|
21 | 21 | #include <fluent-bit/flb_time.h> |
22 | 22 | #include <msgpack.h> |
23 | 23 | #include "flb_tests_runtime.h" |
| 24 | +#include "../../plugins/processor_content_modifier/cm.h" |
24 | 25 |
|
25 | 26 | struct processor_test { |
26 | 27 | flb_ctx_t *flb; /* Fluent Bit library context */ |
@@ -183,6 +184,76 @@ static void processor_test_destroy(struct processor_test *ctx) |
183 | 184 | flb_free(ctx); |
184 | 185 | } |
185 | 186 |
|
| 187 | +static void assert_otel_scope_context_key(char *context_name, char *expected_key) |
| 188 | +{ |
| 189 | + int ret; |
| 190 | + struct processor_test *ctx; |
| 191 | + struct flb_lib_out_cb cb_data = {0}; |
| 192 | + struct cfl_variant action = { |
| 193 | + .type = CFL_VARIANT_STRING, |
| 194 | + .data.as_string = "upsert", |
| 195 | + }; |
| 196 | + struct cfl_variant context = { |
| 197 | + .type = CFL_VARIANT_STRING, |
| 198 | + .data.as_string = context_name, |
| 199 | + }; |
| 200 | + struct cfl_variant value = { |
| 201 | + .type = CFL_VARIANT_STRING, |
| 202 | + .data.as_string = "new value", |
| 203 | + }; |
| 204 | + struct flb_processor_instance *ins; |
| 205 | + struct content_modifier_ctx *cm_ctx; |
| 206 | + |
| 207 | + ctx = processor_test_create(FLB_PROCESSOR_LOGS, &cb_data); |
| 208 | + if (!TEST_CHECK(ctx != NULL)) { |
| 209 | + TEST_MSG("failed to create ctx"); |
| 210 | + return; |
| 211 | + } |
| 212 | + |
| 213 | + ret = flb_processor_unit_set_property(ctx->pu, "action", &action); |
| 214 | + TEST_CHECK(ret == 0); |
| 215 | + ret = flb_processor_unit_set_property(ctx->pu, "context", &context); |
| 216 | + TEST_CHECK(ret == 0); |
| 217 | + ret = flb_processor_unit_set_property(ctx->pu, "value", &value); |
| 218 | + TEST_CHECK(ret == 0); |
| 219 | + |
| 220 | + ret = flb_start(ctx->flb); |
| 221 | + if (!TEST_CHECK(ret == 0)) { |
| 222 | + TEST_MSG("flb_start failed"); |
| 223 | + processor_test_destroy(ctx); |
| 224 | + return; |
| 225 | + } |
| 226 | + |
| 227 | + ins = (struct flb_processor_instance *) ctx->pu->ctx; |
| 228 | + if (!TEST_CHECK(ins != NULL)) { |
| 229 | + TEST_MSG("processor instance is NULL"); |
| 230 | + processor_test_destroy(ctx); |
| 231 | + return; |
| 232 | + } |
| 233 | + |
| 234 | + cm_ctx = (struct content_modifier_ctx *) ins->context; |
| 235 | + if (!TEST_CHECK(cm_ctx != NULL)) { |
| 236 | + TEST_MSG("content modifier context is NULL"); |
| 237 | + processor_test_destroy(ctx); |
| 238 | + return; |
| 239 | + } |
| 240 | + |
| 241 | + TEST_CHECK(cm_ctx->key_is_autogenerated == FLB_TRUE); |
| 242 | + TEST_CHECK(strcmp(cm_ctx->key, expected_key) == 0); |
| 243 | + |
| 244 | + processor_test_destroy(ctx); |
| 245 | +} |
| 246 | + |
| 247 | +static void flb_logs_otel_scope_name_autogenerates_key() |
| 248 | +{ |
| 249 | + assert_otel_scope_context_key("otel_scope_name", "name"); |
| 250 | +} |
| 251 | + |
| 252 | +static void flb_logs_otel_scope_version_autogenerates_key() |
| 253 | +{ |
| 254 | + assert_otel_scope_context_key("otel_scope_version", "version"); |
| 255 | +} |
| 256 | + |
186 | 257 | static void flb_logs_action_insert() |
187 | 258 | { |
188 | 259 | struct processor_test *ctx; |
@@ -1431,6 +1502,8 @@ TEST_LIST = { |
1431 | 1502 | {"logs.action.upsert" , flb_logs_action_upsert }, |
1432 | 1503 | {"logs.action.hash" , flb_logs_action_hash }, |
1433 | 1504 | {"logs.action.extract" , flb_logs_action_extract }, |
| 1505 | + {"logs.otel_scope_name.autogenerated_key" , flb_logs_otel_scope_name_autogenerates_key }, |
| 1506 | + {"logs.otel_scope_version.autogenerated_key" , flb_logs_otel_scope_version_autogenerates_key }, |
1434 | 1507 | {"logs.action.convert_from_string_to_int" , flb_logs_action_convert_from_string_to_int }, |
1435 | 1508 | {"logs.action.convert_from_int_to_string" , flb_logs_action_convert_from_int_to_string }, |
1436 | 1509 | {"logs.action.convert_from_string_to_double" , flb_logs_action_convert_from_string_to_double }, |
|
0 commit comments