Skip to content

Commit e7c3e93

Browse files
committed
processor_content_modifier: add support for OTel metrics
The following patch, extends the processor capabilities to operate on top of metrics, specifically on resource and scope metadata such as attributes, name, version, etc. Signed-off-by: Eduardo Silva <[email protected]>
1 parent 3fd4ec0 commit e7c3e93

File tree

11 files changed

+1092
-549
lines changed

11 files changed

+1092
-549
lines changed

plugins/processor_content_modifier/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
set(src
22
cm_config.c
33
cm_logs.c
4+
cm_metrics.c
45
cm_traces.c
6+
cm_opentelemetry.c
7+
cm_utils.c
58
cm.c
69
)
710

plugins/processor_content_modifier/cm.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ static int cb_process_traces(struct flb_processor_instance *ins,
9898

9999
}
100100

101+
static int cb_process_metrics(struct flb_processor_instance *ins,
102+
struct cmt *in_cmt,
103+
struct cmt **out_cmt,
104+
const char *tag,
105+
int tag_len)
106+
{
107+
int ret;
108+
struct content_modifier_ctx *ctx;
109+
110+
if (!ins->context) {
111+
return FLB_PROCESSOR_FAILURE;
112+
}
113+
ctx = ins->context;
114+
115+
ret = cm_metrics_process(ins, ctx, in_cmt, out_cmt, tag, tag_len);
116+
return ret;
117+
}
118+
101119
static struct flb_config_map config_map[] = {
102120
{
103121
FLB_CONFIG_MAP_STR, "context", NULL,
@@ -144,7 +162,7 @@ struct flb_processor_plugin processor_content_modifier_plugin = {
144162
.description = "Modify the content of Logs, Metrics and Traces",
145163
.cb_init = cb_init,
146164
.cb_process_logs = cb_process_logs,
147-
.cb_process_metrics = NULL,
165+
.cb_process_metrics = cb_process_metrics,
148166
.cb_process_traces = cb_process_traces,
149167
.cb_exit = cb_exit,
150168
.config_map = config_map,

plugins/processor_content_modifier/cm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,10 @@ int cm_traces_process(struct flb_processor_instance *ins,
116116
struct ctrace *traces_context,
117117
const char *tag, int tag_len);
118118

119+
int cm_metrics_process(struct flb_processor_instance *ins,
120+
struct content_modifier_ctx *ctx,
121+
struct cmt *in_cmt,
122+
struct cmt **out_cmt,
123+
const char *tag, int tag_len);
119124

120125
#endif

plugins/processor_content_modifier/cm_config.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,53 @@ static int set_context(struct content_modifier_ctx *ctx)
218218
strcasecmp(ctx->context_str, "attributes") == 0) {
219219
context = CM_CONTEXT_METRIC_LABELS;
220220
}
221+
222+
/*
223+
* OpenTelemetry contexts
224+
* ----------------------
225+
*/
226+
else if (strcasecmp(ctx->context_str, "otel_resource_attributes") == 0) {
227+
context = CM_CONTEXT_OTEL_RESOURCE_ATTR;
228+
}
229+
else if (strcasecmp(ctx->context_str, "otel_scope_attributes") == 0) {
230+
context = CM_CONTEXT_OTEL_SCOPE_ATTR;
231+
}
232+
else if (strcasecmp(ctx->context_str, "otel_scope_name") == 0) {
233+
/*
234+
* scope name is restricted to specific actions, make sure the user
235+
* cannot messed it up
236+
*
237+
* action allowed ?
238+
* -----------------------------
239+
* CM_ACTION_INSERT Yes
240+
* CM_ACTION_UPSERT Yes
241+
* CM_ACTION_DELETE Yes
242+
* CM_ACTION_RENAME No
243+
* CM_ACTION_HASH Yes
244+
* CM_ACTION_EXTRACT No
245+
* CM_ACTION_CONVERT No
246+
*/
247+
248+
if (ctx->action_type == CM_ACTION_RENAME ||
249+
ctx->action_type == CM_ACTION_EXTRACT ||
250+
ctx->action_type == CM_ACTION_CONVERT) {
251+
flb_plg_error(ctx->ins, "action '%s' is not allowed for context '%s'",
252+
ctx->action_str, ctx->context_str);
253+
return -1;
254+
}
255+
256+
/* check that 'name' is the key set */
257+
if (!ctx->key) {
258+
ctx->key = flb_sds_create("name");
259+
}
260+
else if (strcasecmp(ctx->key, "name") != 0) {
261+
flb_plg_error(ctx->ins, "context '%s' requires the name of the key to be 'name', no '%s'",
262+
ctx->context_str, ctx->key);
263+
return -1;
264+
}
265+
266+
context = CM_CONTEXT_OTEL_SCOPE_NAME;
267+
}
221268
else {
222269
flb_plg_error(ctx->ins, "unknown metrics context '%s'", ctx->context_str);
223270
return -1;

0 commit comments

Comments
 (0)