Skip to content

Commit a9948ee

Browse files
edsipercosmo0920
authored andcommitted
tests: runtime: processor_content_modifier: OTEL scope autogenerated keys
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent 2fdd547 commit a9948ee

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

tests/runtime/processor_content_modifier.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <fluent-bit/flb_time.h>
2222
#include <msgpack.h>
2323
#include "flb_tests_runtime.h"
24+
#include "../../plugins/processor_content_modifier/cm.h"
2425

2526
struct processor_test {
2627
flb_ctx_t *flb; /* Fluent Bit library context */
@@ -183,6 +184,76 @@ static void processor_test_destroy(struct processor_test *ctx)
183184
flb_free(ctx);
184185
}
185186

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+
186257
static void flb_logs_action_insert()
187258
{
188259
struct processor_test *ctx;
@@ -1431,6 +1502,8 @@ TEST_LIST = {
14311502
{"logs.action.upsert" , flb_logs_action_upsert },
14321503
{"logs.action.hash" , flb_logs_action_hash },
14331504
{"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 },
14341507
{"logs.action.convert_from_string_to_int" , flb_logs_action_convert_from_string_to_int },
14351508
{"logs.action.convert_from_int_to_string" , flb_logs_action_convert_from_int_to_string },
14361509
{"logs.action.convert_from_string_to_double" , flb_logs_action_convert_from_string_to_double },

0 commit comments

Comments
 (0)