Skip to content

Commit a5cd24b

Browse files
committed
tests: internal: opentelemetry: add unit test for issue #10648
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 5ba4b5d commit a5cd24b

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

tests/internal/data/opentelemetry/test_cases.json

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@
8686
}
8787
},
8888

89-
"scope_kvlist_error": {
89+
"scope_kvlist_empty_value": {
9090
"input": {
9191
"resourceLogs": [{
9292
"scopeLogs": [{
9393
"scope": {
94-
"attributes": [{"key": "only-key"}]
94+
"attributes": [{"key": "empty-key"}]
9595
},
9696
"logRecords": [{
9797
"timeUnixNano": "1",
@@ -100,8 +100,33 @@
100100
}]
101101
}]
102102
},
103-
"expected_error": {
104-
"code": "FLB_OTEL_LOGS_ERR_SCOPE_KVLIST"
103+
"expected": {
104+
"group_metadata": {"schema":"otlp","resource_id":0,"scope_id":0},
105+
"group_body": {"resource":{}, "scope":{"attributes":{"empty-key":""}}},
106+
"log_metadata": {"otlp":{}},
107+
"log_body": {"log": "test"}
108+
}
109+
},
110+
111+
"scope_kvlist_wrong_value_type": {
112+
"input": {
113+
"resourceLogs": [{
114+
"scopeLogs": [{
115+
"scope": {
116+
"attributes": [{"key": "empty-key"}]
117+
},
118+
"logRecords": [{
119+
"timeUnixNano": "1",
120+
"body": {"stringValue": "test"}
121+
}]
122+
}]
123+
}]
124+
},
125+
"expected": {
126+
"group_metadata": {"schema":"otlp","resource_id":0,"scope_id":0},
127+
"group_body": {"resource":{}, "scope":{"attributes":{"empty-key":""}}},
128+
"log_metadata": {"otlp":{}},
129+
"log_body": {"log": "test"}
105130
}
106131
},
107132

@@ -926,7 +951,7 @@
926951
"scope": {
927952
"name": "invalid-scope",
928953
"attributes": [
929-
{"key": "incomplete-kv-pair"}
954+
{"key": "incomplete-kv-pair", "value": "wrong value"}
930955
]
931956
},
932957
"logRecords": [
@@ -1174,6 +1199,31 @@
11741199
"expected_error": {
11751200
"code": "FLB_OTEL_LOGS_ERR_UNEXPECTED_LOGRECORDS_TYPE"
11761201
}
1177-
}
1202+
},
11781203

1204+
"issue_10648_string_with_null_value": {
1205+
"input": {
1206+
"resourceLogs": [{
1207+
"scopeLogs": [{
1208+
"logRecords": [{
1209+
"timeUnixNano": "1722904465173450100",
1210+
"body": {
1211+
"kvlistValue": {
1212+
"values": [
1213+
{"key": "test_key", "value": {"stringValue": null}},
1214+
{"key": "normal_key", "value": {"stringValue": "normal_value"}}
1215+
]
1216+
}
1217+
}
1218+
}]
1219+
}]
1220+
}]
1221+
},
1222+
"expected": {
1223+
"group_metadata": {"schema":"otlp","resource_id":0,"scope_id":0},
1224+
"group_body": {"resource":{}},
1225+
"log_metadata": {"otlp":{}},
1226+
"log_body": {"test_key": "", "normal_key": "normal_value"}
1227+
}
1228+
}
11791229
}

tests/internal/opentelemetry.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,24 @@ void test_opentelemetry_cases()
628628
/* Fall back to legacy format validation */
629629
meta_json = get_group_metadata(enc.output_buffer, enc.output_length);
630630
TEST_CHECK(strcmp(meta_json, expect_group_meta) == 0);
631+
if (strcmp(meta_json, expect_group_meta) != 0) {
632+
TEST_MSG("group metadata mismatch: expected '%s', got '%s'",
633+
expect_group_meta, meta_json);
634+
}
631635

632636
body_json = get_group_body(enc.output_buffer, enc.output_length);
633637
TEST_CHECK(strcmp(body_json, expect_group_body) == 0);
638+
if (strcmp(body_json, expect_group_body) != 0) {
639+
TEST_MSG("group body mismatch: expected '%s', got '%s'",
640+
expect_group_body, body_json);
641+
}
634642

635643
log_json = get_log_body(enc.output_buffer, enc.output_length);
636644
TEST_CHECK(strcmp(log_json, expect_log_body) == 0);
645+
if (strcmp(log_json, expect_log_body) != 0) {
646+
TEST_MSG("log body mismatch: expected '%s', got '%s'",
647+
expect_log_body, log_json);
648+
}
637649
}
638650
else {
639651
TEST_CHECK_(0, "extended format validation failed: %s", case_name);
@@ -693,6 +705,7 @@ void test_opentelemetry_cases()
693705
exp_code, error_status,
694706
flb_opentelemetry_error_to_string(error_status));
695707
if (error_status != exp_code) {
708+
696709
flb_log_event_encoder_destroy(&enc);
697710
flb_free(input_json);
698711
flb_free(case_name);

0 commit comments

Comments
 (0)