Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processor_content_modifier: add support for Metrics processing #9531

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/processor_content_modifier/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
set(src
cm_config.c
cm_logs.c
cm_metrics.c
cm_traces.c
cm_opentelemetry.c
cm_utils.c
cm.c
)

Expand Down
20 changes: 19 additions & 1 deletion plugins/processor_content_modifier/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ static int cb_process_traces(struct flb_processor_instance *ins,

}

static int cb_process_metrics(struct flb_processor_instance *ins,
struct cmt *in_cmt,
struct cmt **out_cmt,
const char *tag,
int tag_len)
{
int ret;
struct content_modifier_ctx *ctx;

if (!ins->context) {
return FLB_PROCESSOR_FAILURE;
}
ctx = ins->context;

ret = cm_metrics_process(ins, ctx, in_cmt, out_cmt, tag, tag_len);
return ret;
}

static struct flb_config_map config_map[] = {
{
FLB_CONFIG_MAP_STR, "context", NULL,
Expand Down Expand Up @@ -144,7 +162,7 @@ struct flb_processor_plugin processor_content_modifier_plugin = {
.description = "Modify the content of Logs, Metrics and Traces",
.cb_init = cb_init,
.cb_process_logs = cb_process_logs,
.cb_process_metrics = NULL,
.cb_process_metrics = cb_process_metrics,
.cb_process_traces = cb_process_traces,
.cb_exit = cb_exit,
.config_map = config_map,
Expand Down
5 changes: 5 additions & 0 deletions plugins/processor_content_modifier/cm.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,10 @@ int cm_traces_process(struct flb_processor_instance *ins,
struct ctrace *traces_context,
const char *tag, int tag_len);

int cm_metrics_process(struct flb_processor_instance *ins,
struct content_modifier_ctx *ctx,
struct cmt *in_cmt,
struct cmt **out_cmt,
const char *tag, int tag_len);

#endif
47 changes: 47 additions & 0 deletions plugins/processor_content_modifier/cm_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,53 @@ static int set_context(struct content_modifier_ctx *ctx)
strcasecmp(ctx->context_str, "attributes") == 0) {
context = CM_CONTEXT_METRIC_LABELS;
}

/*
* OpenTelemetry contexts
* ----------------------
*/
else if (strcasecmp(ctx->context_str, "otel_resource_attributes") == 0) {
context = CM_CONTEXT_OTEL_RESOURCE_ATTR;
}
else if (strcasecmp(ctx->context_str, "otel_scope_attributes") == 0) {
context = CM_CONTEXT_OTEL_SCOPE_ATTR;
}
else if (strcasecmp(ctx->context_str, "otel_scope_name") == 0) {
/*
* scope name is restricted to specific actions, make sure the user
* cannot messed it up
*
* action allowed ?
* -----------------------------
* CM_ACTION_INSERT Yes
* CM_ACTION_UPSERT Yes
* CM_ACTION_DELETE Yes
* CM_ACTION_RENAME No
* CM_ACTION_HASH Yes
* CM_ACTION_EXTRACT No
* CM_ACTION_CONVERT No
*/

if (ctx->action_type == CM_ACTION_RENAME ||
ctx->action_type == CM_ACTION_EXTRACT ||
ctx->action_type == CM_ACTION_CONVERT) {
flb_plg_error(ctx->ins, "action '%s' is not allowed for context '%s'",
ctx->action_str, ctx->context_str);
return -1;
}

/* check that 'name' is the key set */
if (!ctx->key) {
ctx->key = flb_sds_create("name");
}
else if (strcasecmp(ctx->key, "name") != 0) {
flb_plg_error(ctx->ins, "context '%s' requires the name of the key to be 'name', no '%s'",
ctx->context_str, ctx->key);
return -1;
}

context = CM_CONTEXT_OTEL_SCOPE_NAME;
}
else {
flb_plg_error(ctx->ins, "unknown metrics context '%s'", ctx->context_str);
return -1;
Expand Down
Loading
Loading