Skip to content

Commit

Permalink
Add http/protobuf smoke tests (#263)
Browse files Browse the repository at this point in the history
* add smoke test http service to docker-compose

* scaffold http smoke test

* working traces test

* fix placeholder smoke test

* change SERVICE_NAME to OTEL_SERVICE_NAME

* put test service name into a variable

* convert indentation to tab
  • Loading branch information
pkanal authored Sep 21, 2022
1 parent b0caa19 commit 10770b1
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,9 @@ $RECYCLE.BIN/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### temporary smoke-test files
smoke-tests/collector/data.json
smoke-tests/collector/data-results/*.json
smoke-tests/report.xml
smoke-tests/report.html
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ smoke:
@echo ""
@echo "+++ Placeholder for Smoking all the tests."
@echo ""
cd smoke-tests && docker-compose up -d --build && docker-compose down --volumes
cd smoke-tests && docker-compose up -d --build collector app-sdk-http && docker-compose down --volumes

unsmoke:
@echo ""
Expand Down
24 changes: 19 additions & 5 deletions smoke-tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ x-env-base: &env_base
HONEYCOMB_DATASET: bogus_dataset
HONEYCOMB_METRICS_DATASET: bogus_dataset
OTEL_METRIC_EXPORT_INTERVAL: 1000
SERVICE_NAME: "my-web-app"
OTEL_SERVICE_NAME: "aspnetcore-example"

x-app-base: &app_base
build:
context: ../
dockerfile: ./examples/aspnetcore/Dockerfile
image: honeycomb/aspnetcore
depends_on:
- collector

services:
collector:
Expand All @@ -17,11 +25,17 @@ services:
- "./collector:/var/lib"

app-aspnetcore:
build:
context: ../
dockerfile: ./examples/aspnetcore/Dockerfile
image: honeycomb/aspnetcore
<<: *app_base
environment:
<<: *env_base
ports:
- "127.0.0.1:5001:5001"

app-sdk-http:
<<: *app_base
environment:
<<: *env_base
HONEYCOMB_API_ENDPOINT: http://collector:4318/v1/traces
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
ports:
- "127.0.0.1:5001:5001"
33 changes: 33 additions & 0 deletions smoke-tests/smoke-sdk-http.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bats

load test_helpers/utilities

CONTAINER_NAME="app-sdk-http"
OTEL_SERVICE_NAME="aspnetcore-example"

setup_file() {
echo "# 🚧" >&3
docker-compose up --detach collector ${CONTAINER_NAME}
wait_for_ready_app ${CONTAINER_NAME}
curl --silent "http://localhost:5001/weatherforecast"
wait_for_traces
}

teardown_file() {
cp collector/data.json collector/data-results/data-${CONTAINER_NAME}.json
docker-compose stop ${CONTAINER_NAME}
docker-compose restart collector
wait_for_flush
}

# TESTS

@test "Manual instrumentation produces span with name of span" {
result=$(span_names_for ${OTEL_SERVICE_NAME})
assert_equal "$result" '"sleep"'
}

@test "Manual instrumentation adds custom attribute" {
result=$(span_attributes_for ${OTEL_SERVICE_NAME} | jq "select(.key == \"delay_ms\").value.intValue")
assert_equal "$result" '"100"'
}
128 changes: 128 additions & 0 deletions smoke-tests/test_helpers/utilities.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# UTILITY FUNCS

spans_from_library_named() {
spans_received | jq ".scopeSpans[] | select(.scope.name == \"$1\").spans[]"
}

metrics_from_library_named() {
metrics_received | jq ".scopeMetrics[] | select(.scope.name == \"$1\").metrics[]"
}

spans_received() {
jq ".resourceSpans[]?" ./collector/data.json
}

metrics_received() {
jq ".resourceMetrics[]?" ./collector/data.json
}

# test span name
span_names_for() {
spans_from_library_named $1 | jq '.name'
}

# test span attributes
span_attributes_for() {
# $1 - library name

spans_from_library_named $1 | \
jq ".attributes[]"
}

# test metric name
metric_names_for() {
metrics_from_library_named $1 | jq '.name'
}

# Arguments
# $1 - retry limit (default 5); Nth retry sleeps for N seconds
wait_for_metrics() {
echo -n "# ⏳ Waiting for collector to receive metrics" >&3
NEXT_WAIT_TIME=0
MAX_RETRIES=${1:-5}
until [ $NEXT_WAIT_TIME -eq $MAX_RETRIES ] || [ "$(metrics_received)" != "" ]
do
echo -n " ... $(( NEXT_WAIT_TIME++ ))s" >&3
sleep $NEXT_WAIT_TIME
done
echo "" >&3
[ $NEXT_WAIT_TIME -lt $MAX_RETRIES ]
}

# Arguments
# $1 - retry limit (default 5); Nth retry sleeps for N seconds
wait_for_data() {
echo -n "# ⏳ Waiting for collector to receive data" >&3
NEXT_WAIT_TIME=0
MAX_RETRIES=${1:-5}
until [ $NEXT_WAIT_TIME -eq $MAX_RETRIES ] || [ "$(wc -l ./collector/data.json | awk '{ print $1 }')" -ne 0 ]
do
echo -n " ... $(( NEXT_WAIT_TIME++ ))s" >&3
sleep $NEXT_WAIT_TIME
done
echo "" >&3
[ $NEXT_WAIT_TIME -lt $MAX_RETRIES ]
}

# Arguments
# $1 - retry limit (default 5); Nth retry sleeps for N seconds
wait_for_traces() {
echo -n "# ⏳ Waiting for collector to receive traces" >&3
NEXT_WAIT_TIME=0
MAX_RETRIES=${1:-5}
until [ $NEXT_WAIT_TIME -eq $MAX_RETRIES ] || [ "$(spans_received)" != "" ]
do
echo -n " ... $(( NEXT_WAIT_TIME++ ))s" >&3
sleep $NEXT_WAIT_TIME
done
echo "" >&3
[ $NEXT_WAIT_TIME -lt $MAX_RETRIES ]
}

wait_for_flush() {
echo -n "# ⏳ Waiting for collector data flush" >&3
NEXT_WAIT_TIME=0
until [ $NEXT_WAIT_TIME -eq 5 ] || [ "$(wc -l ./collector/data.json | awk '{ print $1 }')" -eq 0 ]
do
echo -n " ... $(( NEXT_WAIT_TIME++ ))s" >&3
sleep $NEXT_WAIT_TIME
done
echo "" >&3
[ $NEXT_WAIT_TIME -lt 5 ]
}

# Wait loop for one of our example Dotnet apps to be started and ready to receive traffic.
#
# Arguments:
# $1 - the name of the container/service in which the app is running
wait_for_ready_app() {
CONTAINER=${1:?container name is a required parameter}
MAX_RETRIES=10
echo -n "# 🍿 Setting up ${CONTAINER}" >&3
NEXT_WAIT_TIME=0
until [ $NEXT_WAIT_TIME -eq $MAX_RETRIES ] || [[ $(docker-compose logs ${CONTAINER} | grep "Now listening on:") ]]
do
echo -n " ... $(( NEXT_WAIT_TIME++ ))s" >&3
sleep $NEXT_WAIT_TIME
done
echo "" >&3
[ $NEXT_WAIT_TIME -lt $MAX_RETRIES ]
}

# Fail and display details if the expected and actual values do not
# equal. Details include both values.
#
# Lifted and then drastically simplified from bats-assert * bats-support
assert_equal() {
if [[ $1 != "$2" ]]; then
{
echo
echo "-- 💥 values are not equal 💥 --"
echo "expected : $2"
echo "actual : $1"
echo "--"
echo
} >&2 # output error to STDERR
return 1
fi
}

0 comments on commit 10770b1

Please sign in to comment.