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

Add SPM integration tests #5640

Merged
merged 23 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
34 changes: 34 additions & 0 deletions .github/workflows/ci-build-spm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test SPM

yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
on:
push:
branches: [main]

pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }}
cancel-in-progress: true

# See https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions
permissions:
contents: read

jobs:
SPM:
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 1.22.x

- name: Run SPM Test
run: ./scripts/build-SPM.sh
83 changes: 83 additions & 0 deletions scripts/build-SPM.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

set -e -uxf -o pipefail

# Function to check if a service is healthy
check_service_health() {
local service_name=$1
local url=$2
local retry_count=10
local wait_seconds=5

echo "Checking health of service: $service_name at $url"

for i in $(seq 1 $retry_count); do
if curl -s -L --head --request GET "$url" | grep "200 OK" > /dev/null; then
echo "$service_name is healthy"
return 0
else
echo "Waiting for $service_name to be healthy... ($i/$retry_count)"
sleep $wait_seconds
fi
done

echo "Error: $service_name did not become healthy in time"
return 1
}

# Function to check if all services are healthy
wait_for_services() {
echo "Waiting for services to be up and running..."
check_service_health "Jaeger" "http://localhost:16686"
check_service_health "Prometheus" "http://localhost:9090/graph"
check_service_health "Grafana" "http://localhost:3000"
}
check_jaeger(){
echo "Checking Jaeger"
services_list=("driver" "customer" "mysql" "redis" "frontend" "route" "ui" )
sleep 60
for service in "${services_list[@]}"; do
echo "Processing service: $service"
response=$(curl -s "http://localhost:16686/api/metrics/calls?service=$service&endTs=$(date +%s)000&lookback=1000&step=100&ratePer=60000")
echo "$response"
service_name=$(echo "$response" | jq -r '.metrics[0].labels[] | select(.name=="service_name") | .value')
if [ "$service_name" != "$service" ]; then
echo "Service name does not match 'driver'"
exit 1
fi

all_non_zero=true
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
metric_points=$(echo "$response" | jq -r '.metrics[0].metricPoints[] | .gaugeValue.doubleValue')
for value in $metric_points; do
if (( $(echo "$value == 0" | bc -l) )); then
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
all_non_zero=false
break
fi
done

if [ "$all_non_zero" = true ]; then
echo "All gauge values are non-zero"
else
echo "Some gauge values are zero"
exit 1
fi
done

}

# Function to tear down Docker Compose services
teardown_services() {
docker compose -f docker-compose/monitor/docker-compose.yml down
}

# Main function
main() {
docker compose -f docker-compose/monitor/docker-compose.yml up -d
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
wait_for_services
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
check_jaeger
echo "All services are running correctly"
teardown_services
}
trap teardown_services EXIT INT
# Run the main function
main
Loading