From bdd917911f645ed006bbe435b638301d43cf59ac Mon Sep 17 00:00:00 2001 From: Lucas Tembras Date: Fri, 11 Jul 2025 18:32:48 +0000 Subject: [PATCH 1/3] out_datadog: added support for site configuration field Signed-off-by: Lucas Tembras --- plugins/out_datadog/datadog.c | 5 ++- plugins/out_datadog/datadog.h | 1 + plugins/out_datadog/datadog_conf.c | 60 +++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/plugins/out_datadog/datadog.c b/plugins/out_datadog/datadog.c index e5c6621f880..e4c12b2f293 100644 --- a/plugins/out_datadog/datadog.c +++ b/plugins/out_datadog/datadog.c @@ -581,7 +581,10 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct flb_out_datadog, json_date_key), "Date key name for output." }, - + { + FLB_CONFIG_MAP_STR, "site", NULL, 0, FLB_FALSE, offsetof(struct flb_out_datadog, site), + "DataDog site for telemetry data (e.g., 'datadoghq.eu', 'datadoghq.com', 'us3.datadoghq.com'). The plugin will construct the full hostname by prepending 'http-intake.logs.' to this value." + }, /* EOF */ {0} }; diff --git a/plugins/out_datadog/datadog.h b/plugins/out_datadog/datadog.h index 60e7a676c72..02376ac8029 100644 --- a/plugins/out_datadog/datadog.h +++ b/plugins/out_datadog/datadog.h @@ -61,6 +61,7 @@ struct flb_out_datadog { flb_sds_t tag_key; struct mk_list *headers; bool remap; + flb_sds_t site; /* final result */ flb_sds_t json_date_key; diff --git a/plugins/out_datadog/datadog_conf.c b/plugins/out_datadog/datadog_conf.c index a0ef7369df7..2efb60e08a5 100644 --- a/plugins/out_datadog/datadog_conf.c +++ b/plugins/out_datadog/datadog_conf.c @@ -40,6 +40,7 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins, char *host = NULL; char *port = NULL; char *uri = NULL; + char *site = NULL; /* Start resource creation */ ctx = flb_calloc(1, sizeof(struct flb_out_datadog)); @@ -98,6 +99,15 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins, return NULL; } + /* Parse site parameter early so it's available for host construction */ + tmp = flb_output_get_property("site", ins); + if (tmp){ + ctx->site = flb_sds_create(tmp); + flb_plg_debug(ctx->ins, "site parameter set to: %s", ctx->site); + } else { + flb_plg_debug(ctx->ins, "no site parameter found"); + } + /* Tag Key */ if (ctx->include_tag_key == FLB_TRUE) { ctx->nb_additional_entries++; @@ -126,7 +136,7 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins, tmp = flb_output_get_property("provider", 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("/api/v2/logs"); if (!ctx->uri) { flb_plg_error(ctx->ins, "error on uri generation"); @@ -138,18 +148,47 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins, /* Get network configuration */ if (!ins->host.name) { - tmp_sds = flb_sds_create(FLB_DATADOG_DEFAULT_HOST); + /* No explicit Host parameter, check for site */ + if (ctx->site) { + flb_plg_debug(ctx->ins, "using site for host construction: %s", ctx->site); + /* Construct hostname from site */ + tmp_sds = flb_sds_create("http-intake.logs."); + if (!tmp_sds) { + flb_errno(); + flb_datadog_conf_destroy(ctx); + return NULL; + } + flb_plg_debug(ctx->ins, "created base hostname: %s", tmp_sds); + flb_plg_debug(ctx->ins, "about to concatenate site: %s (length: %zu)", ctx->site, flb_sds_len(ctx->site)); + tmp_sds = flb_sds_cat(tmp_sds, (const char *)ctx->site, flb_sds_len(ctx->site)); + flb_plg_debug(ctx->ins, "after concatenation: %s", tmp_sds); + ctx->host = tmp_sds; + flb_plg_debug(ctx->ins, "host constructed from site: %s", ctx->host); + } else { + flb_plg_debug(ctx->ins, "no site specified, using default host"); + /* No site specified, use default */ + tmp_sds = flb_sds_create(FLB_DATADOG_DEFAULT_HOST); + if (!tmp_sds) { + flb_errno(); + flb_datadog_conf_destroy(ctx); + return NULL; + } + ctx->host = tmp_sds; + flb_plg_debug(ctx->ins, "host: %s", ctx->host); + } } else { + flb_plg_debug(ctx->ins, "explicit Host parameter takes precedence: %s", ins->host.name); + /* Explicit Host parameter takes precedence */ tmp_sds = flb_sds_create(ins->host.name); + if (!tmp_sds) { + flb_errno(); + flb_datadog_conf_destroy(ctx); + return NULL; + } + ctx->host = tmp_sds; + flb_plg_debug(ctx->ins, "host: %s", ctx->host); } - if (!tmp_sds) { - flb_errno(); - flb_datadog_conf_destroy(ctx); - return NULL; - } - ctx->host = tmp_sds; - flb_plg_debug(ctx->ins, "host: %s", ctx->host); if (ins->host.port != 0) { ctx->port = ins->host.port; @@ -222,6 +261,9 @@ int flb_datadog_conf_destroy(struct flb_out_datadog *ctx) if (ctx->upstream) { flb_upstream_destroy(ctx->upstream); } + if (ctx->site){ + flb_sds_destroy(ctx->site); + } flb_free(ctx); return 0; From 64226fedb86807a4405c2b32bddefd6c7dbd40ab Mon Sep 17 00:00:00 2001 From: Lucas Tembras Date: Mon, 4 Aug 2025 14:47:25 +0000 Subject: [PATCH 2/3] fix: implemented minor coderabbitai suggestions Signed-off-by: Lucas Tembras --- plugins/out_datadog/datadog_conf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/out_datadog/datadog_conf.c b/plugins/out_datadog/datadog_conf.c index 2efb60e08a5..43a1b7e8e18 100644 --- a/plugins/out_datadog/datadog_conf.c +++ b/plugins/out_datadog/datadog_conf.c @@ -103,6 +103,11 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins, tmp = flb_output_get_property("site", ins); if (tmp){ ctx->site = flb_sds_create(tmp); + if (!ctx->site) { + flb_plg_error(ctx->ins, "failed to allocate memory for site parameter"); + flb_datadog_conf_destroy(ctx); + return NULL; + } flb_plg_debug(ctx->ins, "site parameter set to: %s", ctx->site); } else { flb_plg_debug(ctx->ins, "no site parameter found"); @@ -158,10 +163,7 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins, flb_datadog_conf_destroy(ctx); return NULL; } - flb_plg_debug(ctx->ins, "created base hostname: %s", tmp_sds); - flb_plg_debug(ctx->ins, "about to concatenate site: %s (length: %zu)", ctx->site, flb_sds_len(ctx->site)); tmp_sds = flb_sds_cat(tmp_sds, (const char *)ctx->site, flb_sds_len(ctx->site)); - flb_plg_debug(ctx->ins, "after concatenation: %s", tmp_sds); ctx->host = tmp_sds; flb_plg_debug(ctx->ins, "host constructed from site: %s", ctx->host); } else { From f4e945290fc587a43e5657be437e84a2e8006688 Mon Sep 17 00:00:00 2001 From: Lucas Tembras Date: Wed, 20 Aug 2025 14:15:02 +0000 Subject: [PATCH 3/3] refactor: set site to FLB_TRUE and implemented styling suggestions Signed-off-by: Lucas Tembras --- plugins/out_datadog/datadog.c | 6 ++++-- plugins/out_datadog/datadog_conf.c | 22 +++++++--------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/plugins/out_datadog/datadog.c b/plugins/out_datadog/datadog.c index e4c12b2f293..9b9600613b9 100644 --- a/plugins/out_datadog/datadog.c +++ b/plugins/out_datadog/datadog.c @@ -582,8 +582,10 @@ static struct flb_config_map config_map[] = { "Date key name for output." }, { - FLB_CONFIG_MAP_STR, "site", NULL, 0, FLB_FALSE, offsetof(struct flb_out_datadog, site), - "DataDog site for telemetry data (e.g., 'datadoghq.eu', 'datadoghq.com', 'us3.datadoghq.com'). The plugin will construct the full hostname by prepending 'http-intake.logs.' to this value." + FLB_CONFIG_MAP_STR, "site", NULL, 0, FLB_TRUE, offsetof(struct flb_out_datadog, site), + "DataDog site for telemetry data (e.g., 'datadoghq.eu', 'datadoghq.com', 'us3.datadoghq.com'). " + "The plugin will construct the full hostname by prepending 'http-intake.logs.' to this value. " + "This parameter is required." }, /* EOF */ {0} diff --git a/plugins/out_datadog/datadog_conf.c b/plugins/out_datadog/datadog_conf.c index 43a1b7e8e18..636d4d93e2c 100644 --- a/plugins/out_datadog/datadog_conf.c +++ b/plugins/out_datadog/datadog_conf.c @@ -99,17 +99,11 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins, return NULL; } - /* Parse site parameter early so it's available for host construction */ - tmp = flb_output_get_property("site", ins); - if (tmp){ - ctx->site = flb_sds_create(tmp); - if (!ctx->site) { - flb_plg_error(ctx->ins, "failed to allocate memory for site parameter"); - flb_datadog_conf_destroy(ctx); - return NULL; - } + /* Site parameter is now handled by config map */ + if (ctx->site) { flb_plg_debug(ctx->ins, "site parameter set to: %s", ctx->site); - } else { + } + else { flb_plg_debug(ctx->ins, "no site parameter found"); } @@ -166,7 +160,8 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins, tmp_sds = flb_sds_cat(tmp_sds, (const char *)ctx->site, flb_sds_len(ctx->site)); ctx->host = tmp_sds; flb_plg_debug(ctx->ins, "host constructed from site: %s", ctx->host); - } else { + } + else { flb_plg_debug(ctx->ins, "no site specified, using default host"); /* No site specified, use default */ tmp_sds = flb_sds_create(FLB_DATADOG_DEFAULT_HOST); @@ -263,10 +258,7 @@ int flb_datadog_conf_destroy(struct flb_out_datadog *ctx) if (ctx->upstream) { flb_upstream_destroy(ctx->upstream); } - if (ctx->site){ - flb_sds_destroy(ctx->site); - } flb_free(ctx); return 0; -} +} \ No newline at end of file