From 8f165e084bdfda70bb1e281c7672f0bea9075b50 Mon Sep 17 00:00:00 2001 From: Stewart Webb Date: Sun, 19 May 2024 21:22:45 +1000 Subject: [PATCH] Add tests that replicate issue in fluent/fluent-bit#8734 Signed-off-by: Stewart Webb --- tests/runtime_shell/CMakeLists.txt | 3 ++ .../in_opentelemetry_tagfromuri_expect.conf | 38 +++++++++++++++++++ .../in_opentelemetry_tagfromuri_log_expect.sh | 30 +++++++++++++++ ..._opentelemetry_tagfromuri_metric_expect.sh | 30 +++++++++++++++ ...n_opentelemetry_tagfromuri_trace_expect.sh | 30 +++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 tests/runtime_shell/conf/in_opentelemetry_tagfromuri_expect.conf create mode 100755 tests/runtime_shell/in_opentelemetry_tagfromuri_log_expect.sh create mode 100755 tests/runtime_shell/in_opentelemetry_tagfromuri_metric_expect.sh create mode 100755 tests/runtime_shell/in_opentelemetry_tagfromuri_trace_expect.sh diff --git a/tests/runtime_shell/CMakeLists.txt b/tests/runtime_shell/CMakeLists.txt index 15eebb5f316..fd123ec7d3b 100644 --- a/tests/runtime_shell/CMakeLists.txt +++ b/tests/runtime_shell/CMakeLists.txt @@ -12,6 +12,9 @@ set(UNIT_TESTS_SH in_syslog_udp_plaintext_expect.sh in_syslog_uds_dgram_plaintext_expect.sh in_syslog_uds_stream_plaintext_expect.sh + in_opentelemetry_tagfromuri_log_expect.sh + in_opentelemetry_tagfromuri_metric_expect.sh + in_opentelemetry_tagfromuri_trace_expect.sh ) # Prepare list of unit tests diff --git a/tests/runtime_shell/conf/in_opentelemetry_tagfromuri_expect.conf b/tests/runtime_shell/conf/in_opentelemetry_tagfromuri_expect.conf new file mode 100644 index 00000000000..df1524765d1 --- /dev/null +++ b/tests/runtime_shell/conf/in_opentelemetry_tagfromuri_expect.conf @@ -0,0 +1,38 @@ +[SERVICE] + Flush 1 + Grace 1 + Log_Level error + +[INPUT] + name dummy + samples 1 + +[OUTPUT] + name file + match dummy.* + file ${SIGNAL_FILE_PATH} + mkdir on + +[INPUT] + name opentelemetry + tag_from_uri True + tag target_input + listen ${LISTENER_HOST} + port ${LISTENER_PORT} + +[FILTER] + Name expect + Match target_input + Log_Level debug + +# Use explicit matches on what tag_from_uri should be setting for each +# of the three OpenTelemetry signal types +[OUTPUT] + Name exit + Match v1_logs +[OUTPUT] + Name exit + Match v1_metrics +[OUTPUT] + Name exit + Match v1_traces diff --git a/tests/runtime_shell/in_opentelemetry_tagfromuri_log_expect.sh b/tests/runtime_shell/in_opentelemetry_tagfromuri_log_expect.sh new file mode 100755 index 00000000000..89d2d6c1ca2 --- /dev/null +++ b/tests/runtime_shell/in_opentelemetry_tagfromuri_log_expect.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +. ${FLB_RUNTIME_SHELL_PATH}/common.sh + +input_generator() { + result=$(wait_for_fluent_bit ${SIGNAL_FILE_PATH}) + + if test "$result" -eq "0" + then + # sample data from https://github.com/open-telemetry/opentelemetry-proto/blob/main/examples/logs.json + curl \ + --header "Content-Type: application/json" \ + --request POST \ + --data '{"resourceLogs":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"my.service"}}]},"scopeLogs":[{"scope":{"name":"my.library","version":"1.0.0","attributes":[{"key":"my.scope.attribute","value":{"stringValue":"somescopeattribute"}}]},"logRecords":[{"timeUnixNano":"1544712660300000000","observedTimeUnixNano":"1544712660300000000","severityNumber":10,"severityText":"Information","traceId":"5B8EFFF798038103D269B633813FC60C","spanId":"EEE19B7EC3C1B174","body":{"stringValue":"Examplelogrecord"},"attributes":[{"key":"string.attribute","value":{"stringValue":"somestring"}},{"key":"boolean.attribute","value":{"boolValue":true}},{"key":"int.attribute","value":{"intValue":"10"}},{"key":"double.attribute","value":{"doubleValue":637.704}},{"key":"array.attribute","value":{"arrayValue":{"values":[{"stringValue":"many"},{"stringValue":"values"}]}}},{"key":"map.attribute","value":{"kvlistValue":{"values":[{"key":"some.map.key","value":{"stringValue":"somevalue"}}]}}}]}]}]}]}' \ + http://${LISTENER_HOST}:${LISTENER_PORT}/v1/logs + fi +} + +test_in_opentelemetry_tagfromuri_log_expect() { + export SIGNAL_FILE_PATH="/tmp/fb_signal_$$" + export LISTENER_HOST=127.0.0.1 + export LISTENER_PORT=4318 + + input_generator & + + $FLB_BIN -c $FLB_RUNTIME_SHELL_CONF/in_opentelemetry_tagfromuri_expect.conf +} + +# The following command launch the unit test +. $FLB_RUNTIME_SHELL_PATH/runtime_shell.env diff --git a/tests/runtime_shell/in_opentelemetry_tagfromuri_metric_expect.sh b/tests/runtime_shell/in_opentelemetry_tagfromuri_metric_expect.sh new file mode 100755 index 00000000000..8bb847aaec2 --- /dev/null +++ b/tests/runtime_shell/in_opentelemetry_tagfromuri_metric_expect.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +. ${FLB_RUNTIME_SHELL_PATH}/common.sh + +input_generator() { + result=$(wait_for_fluent_bit ${SIGNAL_FILE_PATH}) + + if test "$result" -eq "0" + then + # sample data from https://github.com/open-telemetry/opentelemetry-proto/blob/main/examples/metrics.json + curl \ + --header "Content-Type: application/json" \ + --request POST \ + --data '{"resourceMetrics":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"my.service"}}]},"scopeMetrics":[{"scope":{"name":"my.library","version":"1.0.0","attributes":[{"key":"my.scope.attribute","value":{"stringValue":"somescopeattribute"}}]},"metrics":[{"name":"my.counter","unit":"1","description":"IamaCounter","sum":{"aggregationTemporality":1,"isMonotonic":true,"dataPoints":[{"asDouble":5,"startTimeUnixNano":"1544712660300000000","timeUnixNano":"1544712660300000000","attributes":[{"key":"my.counter.attr","value":{"stringValue":"somevalue"}}]}]}},{"name":"my.gauge","unit":"1","description":"IamaGauge","gauge":{"dataPoints":[{"asDouble":10,"timeUnixNano":"1544712660300000000","attributes":[{"key":"my.gauge.attr","value":{"stringValue":"somevalue"}}]}]}},{"name":"my.histogram","unit":"1","description":"IamaHistogram","histogram":{"aggregationTemporality":1,"dataPoints":[{"startTimeUnixNano":"1544712660300000000","timeUnixNano":"1544712660300000000","count":2,"sum":2,"bucketCounts":[1,1],"explicitBounds":[1],"min":0,"max":2,"attributes":[{"key":"my.histogram.attr","value":{"stringValue":"somevalue"}}]}]}}]}]}]}' \ + http://${LISTENER_HOST}:${LISTENER_PORT}/v1/metrics + fi +} + +test_in_opentelemetry_tagfromuri_metric_expect() { + export SIGNAL_FILE_PATH="/tmp/fb_signal_$$" + export LISTENER_HOST=127.0.0.1 + export LISTENER_PORT=4318 + + input_generator & + + $FLB_BIN -c $FLB_RUNTIME_SHELL_CONF/in_opentelemetry_tagfromuri_expect.conf +} + +# The following command launch the unit test +. $FLB_RUNTIME_SHELL_PATH/runtime_shell.env diff --git a/tests/runtime_shell/in_opentelemetry_tagfromuri_trace_expect.sh b/tests/runtime_shell/in_opentelemetry_tagfromuri_trace_expect.sh new file mode 100755 index 00000000000..ad9cd3bdf52 --- /dev/null +++ b/tests/runtime_shell/in_opentelemetry_tagfromuri_trace_expect.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +. ${FLB_RUNTIME_SHELL_PATH}/common.sh + +input_generator() { + result=$(wait_for_fluent_bit ${SIGNAL_FILE_PATH}) + + if test "$result" -eq "0" + then + # sample data from https://github.com/open-telemetry/opentelemetry-proto/blob/main/examples/trace.json + curl \ + --header "Content-Type: application/json" \ + --request POST \ + --data '{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"my.service"}}]},"scopeSpans":[{"scope":{"name":"my.library","version":"1.0.0","attributes":[{"key":"my.scope.attribute","value":{"stringValue":"somescopeattribute"}}]},"spans":[{"traceId":"5B8EFFF798038103D269B633813FC60C","spanId":"EEE19B7EC3C1B174","parentSpanId":"EEE19B7EC3C1B173","name":"I'\''maserverspan","startTimeUnixNano":"1544712660000000000","endTimeUnixNano":"1544712661000000000","kind":2,"attributes":[{"key":"my.span.attr","value":{"stringValue":"somevalue"}}]}]}]}]}' \ + http://${LISTENER_HOST}:${LISTENER_PORT}/v1/traces + fi +} + +test_in_opentelemetry_tagfromuri_trace_expect() { + export SIGNAL_FILE_PATH="/tmp/fb_signal_$$" + export LISTENER_HOST=127.0.0.1 + export LISTENER_PORT=4318 + + input_generator & + + $FLB_BIN -c $FLB_RUNTIME_SHELL_CONF/in_opentelemetry_tagfromuri_expect.conf +} + +# The following command launch the unit test +. $FLB_RUNTIME_SHELL_PATH/runtime_shell.env