Skip to content

Commit

Permalink
datadog: support v2 endpoint
Browse files Browse the repository at this point in the history
This commit migrates the datadog plugin to use the now available v2
endpoints. The changes should be transparent to the user.

Signed-off-by: truthbk <[email protected]>
  • Loading branch information
truthbk committed Mar 11, 2022
1 parent fc51f21 commit 803a806
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions plugins/out_datadog/datadog.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <fluent-bit/flb_time.h>
#include <fluent-bit/flb_gzip.h>
#include <fluent-bit/flb_config_map.h>
#include <fluent-bit/flb_version.h>

#include <msgpack.h>

Expand Down Expand Up @@ -354,7 +355,11 @@ static void cb_datadog_flush(struct flb_event_chunk *event_chunk,
FLB_OUTPUT_RETURN(FLB_ERROR);
}

/* Add the required headers to the URI */
flb_http_add_header(client, "User-Agent", 10, "Fluent-Bit", 10);
flb_http_add_header(client, FLB_DATADOG_API_HDR, sizeof(FLB_DATADOG_API_HDR) - 1, ctx->api_key, flb_sds_len(ctx->api_key));
flb_http_add_header(client, FLB_DATADOG_ORIGIN_HDR, sizeof(FLB_DATADOG_ORIGIN_HDR) - 1, "Fluent-Bit", 10);
flb_http_add_header(client, FLB_DATADOG_ORIGIN_VERSION_HDR, sizeof(FLB_DATADOG_ORIGIN_VERSION_HDR) - 1, FLB_VERSION_STR, sizeof(FLB_VERSION_STR) - 1);
flb_http_add_header(client,
FLB_DATADOG_CONTENT_TYPE, sizeof(FLB_DATADOG_CONTENT_TYPE) - 1,
FLB_DATADOG_MIME_JSON, sizeof(FLB_DATADOG_MIME_JSON) - 1);
Expand Down
4 changes: 4 additions & 0 deletions plugins/out_datadog/datadog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#define FLB_DATADOG_REMAP_PROVIDER "ecs"
#define FLB_DATADOG_TAG_SEPERATOR ","

#define FLB_DATADOG_API_HDR "DD-API-KEY"
#define FLB_DATADOG_ORIGIN_HDR "DD-EVP-ORIGIN"
#define FLB_DATADOG_ORIGIN_VERSION_HDR "DD-EVP-ORIGIN-VERSION"

#define FLB_DATADOG_CONTENT_TYPE "Content-Type"
#define FLB_DATADOG_MIME_JSON "application/json"

Expand Down
3 changes: 2 additions & 1 deletion plugins/out_datadog/datadog_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
ctx->remap = tmp && (strlen(tmp) == strlen(FLB_DATADOG_REMAP_PROVIDER)) && \
(strncmp(tmp, FLB_DATADOG_REMAP_PROVIDER, strlen(tmp)) == 0);

ctx->uri = flb_sds_create("/v1/input/");
ctx->uri = flb_sds_create("/api/v2/logs");
if (!ctx->uri) {
flb_plg_error(ctx->ins, "error on uri generation");
flb_datadog_conf_destroy(ctx);
return NULL;
}

/* Add the api_key to the URI */
ctx->uri = flb_sds_cat(ctx->uri, ctx->api_key, flb_sds_len(ctx->api_key));
flb_plg_debug(ctx->ins, "uri: %s", ctx->uri);
Expand Down
2 changes: 1 addition & 1 deletion plugins/out_datadog/datadog_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define FLB_OUT_DATADOG_CONF_H

#include <fluent-bit/flb_output.h>
#include <fluent-bit/flb_config.h>
#include <fluent-bit/flb_config.h>

#include "datadog.h"

Expand Down

0 comments on commit 803a806

Please sign in to comment.