@@ -32,7 +32,8 @@ while getopts "b:m:h" opt; do
3232 esac
3333done
3434
35- set -x
35+ # Enable verbose logs if you want to debug the script. Else, keep logs clean.
36+ # set -x
3637
3738# Validate binary option
3839case " $BINARY " in
@@ -103,7 +104,7 @@ check_service_health() {
103104}
104105
105106# Function to check if all services are healthy
106- wait_for_services () {
107+ wait_for_services_to_be_healthy () {
107108 echo " Waiting for services to be up and running..."
108109
109110 case " $METRICSTORE " in
@@ -121,6 +122,100 @@ wait_for_services() {
121122 check_service_health " Jaeger" " http://localhost:16686"
122123}
123124
125+ get_expected_operations_of_service () {
126+ # Which span names do we expect from which service?
127+ # See https://github.com/yurishkuro/microsim/blob/main/config/hotrod.go
128+ local service=$1
129+ case " $service " in
130+ " driver" )
131+ echo " /FindNearest"
132+ ;;
133+ " customer" )
134+ echo " /customer"
135+ ;;
136+ " mysql" )
137+ echo " /sql_select"
138+ ;;
139+ " redis" )
140+ echo " /FindDriverIDs /GetDriver"
141+ ;;
142+ " frontend" )
143+ echo " /dispatch"
144+ ;;
145+ " route" )
146+ echo " /GetShortestRoute"
147+ ;;
148+ " ui" )
149+ echo " /"
150+ ;;
151+ * )
152+ echo " "
153+ ;;
154+ esac
155+ }
156+
157+ # Validate that found operations match expected operations for a service
158+ validate_operations_for_service () {
159+ local service=$1
160+ local found_operations=$2
161+
162+ local expected_operations
163+ expected_operations=$( get_expected_operations_of_service " $service " )
164+
165+ # If no expected operations defined for this service, skip validation
166+ if [[ -z " $expected_operations " ]]; then
167+ return 0
168+ fi
169+
170+ # Log expected and found operations
171+ if [[ -n " $found_operations " ]]; then
172+ echo " Expected operations for service '$service ': [$expected_operations ] | Found operations: [$found_operations ]"
173+ else
174+ echo " Expected operations for service '$service ': [$expected_operations ] | Found operations: []"
175+ fi
176+
177+ # If no operations found, that's an error
178+ if [[ -z " $found_operations " ]]; then
179+ echo " ❌ ERROR: No operations found for service '$service ', but expected: [$expected_operations ]"
180+ return 1
181+ fi
182+
183+ # Parse comma-separated operations (format: "op1, op2, op3")
184+ # Convert to space-separated and normalize whitespace
185+ local found_ops_list
186+ found_ops_list=$( echo " $found_operations " | sed ' s/,/ /g' | tr -s ' ' | sed ' s/^ *//;s/ *$//' )
187+
188+ # Check each found operation against expected ones
189+ local found_op
190+ for found_op in $found_ops_list ; do
191+ # Remove any leading/trailing spaces
192+ found_op=$( echo " $found_op " | sed ' s/^ *//;s/ *$//' )
193+
194+ # Skip empty operations
195+ if [[ -z " $found_op " ]]; then
196+ continue
197+ fi
198+
199+ # Check if this operation is in the expected list
200+ local is_expected=false
201+ local expected_op
202+ for expected_op in $expected_operations ; do
203+ if [[ " $found_op " == " $expected_op " ]]; then
204+ is_expected=true
205+ break
206+ fi
207+ done
208+
209+ if [[ " $is_expected " == " false" ]]; then
210+ echo " ❌ ERROR: Unexpected operation '$found_op ' found for service '$service '. Expected operations: [$expected_operations ]"
211+ return 1
212+ fi
213+ done
214+
215+ echo " ✅ Operation validation passed for service '$service '"
216+ return 0
217+ }
218+
124219# Function to validate the service metrics
125220validate_service_metrics () {
126221 local service=$1
@@ -160,6 +255,19 @@ validate_service_metrics() {
160255 if ! assert_labels_set_equals " $response " " operation service_name" ; then
161256 return 1
162257 fi
258+
259+ # Validate operations from this service are what we expect.
260+ echo " Checking operations for service: $service "
261+ local operations
262+ operations=$( extract_operations " $response " )
263+ if [[ -n " $operations " ]]; then
264+ # Validate that found operations match expected ones
265+ if ! validate_operations_for_service " $service " " $operations " " calls" ; then
266+ return 1
267+ fi
268+ else
269+ echo " ❌ ERROR No operations found yet for service '${service} '. We expected to find some."
270+ fi
163271
164272 # ## Validate Errors Rate metrics
165273 local url=" http://localhost:16686/api/metrics/errors?service=${service} &endTs=&lookback=${fiveMinutes} &step=${fifteenSec} &ratePer=${oneMinute} "
@@ -221,6 +329,27 @@ assert_labels_set_equals() {
221329 return 0
222330}
223331
332+ extract_operations () {
333+ local response=$1
334+ # Extract all unique operation names from all metrics in the response
335+ # Each metric has labels array, and when groupByOperation=true, each metric has a label with name=="operation"
336+ local operations
337+ operations=$( echo " $response " | jq -r '
338+ if .metrics and (.metrics | length > 0) then
339+ [.metrics[] | .labels[] | select(.name=="operation") | .value] | unique | sort | .[]
340+ else
341+ empty
342+ end' 2> /dev/null)
343+
344+ if [[ -z " $operations " ]]; then
345+ echo " "
346+ return 0
347+ fi
348+
349+ # Return operations as a comma-separated list
350+ echo " $operations " | tr ' \n' ' ,' | sed ' s/,$//' | sed ' s/,/, /g'
351+ }
352+
224353count_zero_metrics_point () {
225354 echo " $1 " | jq -r ' [.metrics[0].metricPoints[].gaugeValue.doubleValue | select(. == 0)] | length'
226355}
@@ -268,7 +397,7 @@ teardown_services() {
268397main () {
269398 (cd docker-compose/monitor && make build BINARY=" $BINARY " && make $make_target DOCKER_COMPOSE_ARGS=" -d" )
270399
271- wait_for_services
400+ wait_for_services_to_be_healthy
272401 check_spm
273402 success=" true"
274403}
0 commit comments