Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add test for OpenTelemetry input plugin tagfromuri #8964

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tests: Add in_opentelemetry tests that replicate #8734
Signed-off-by: Stewart Webb <stewart.james.webb@gmail.com>
  • Loading branch information
nuclearpidgeon committed Jul 1, 2024
commit 75f1c9c6d39ddb17c134a39b16e2f2476dfdc67a
3 changes: 3 additions & 0 deletions tests/runtime_shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions tests/runtime_shell/in_opentelemetry_tagfromuri_log_expect.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions tests/runtime_shell/in_opentelemetry_tagfromuri_trace_expect.sh
Original file line number Diff line number Diff line change
@@ -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
Loading