Skip to content

Commit

Permalink
Add end-2-end tests for metrics service
Browse files Browse the repository at this point in the history
Issue: COSI-46
  • Loading branch information
anurag4DSB committed Dec 19, 2024
1 parent d46982a commit e477885
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/scripts/e2e_tests_metrics_service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
set -e

LOG_FILE=".github/e2e_tests/artifacts/logs/e2e_tests/metrics_service.log"
mkdir -p "$(dirname "$LOG_FILE")"

NAMESPACE="scality-object-storage"
SERVICE="scality-cosi-metrics"
LOCAL_PORT=8080
TARGET_PORT=8080

# Error handling function
error_handler() {
echo "An error occurred during bucket creation tests. Check the log file for details." | tee -a "$LOG_FILE"
echo "Failed command: $BASH_COMMAND" | tee -a "$LOG_FILE"
exit 1
}

# Trap errors and call the error handler
trap 'error_handler' ERR

# Log command execution to the log file for debugging
log_and_run() {
"$@" 2>&1 | tee -a "$LOG_FILE"
}

kubectl port-forward svc/$SERVICE -n $NAMESPACE $LOCAL_PORT:$TARGET_PORT &
PORT_FORWARD_PID=$!

if ps -p $PORT_FORWARD_PID > /dev/null; then
log_and_run echo "Port-forwarding established. Querying metrics..."

log_and_run curl -f http://localhost:$LOCAL_PORT/metrics > metrics_output.txt

if [ $? -eq 0 ]; then
log_and_run echo "Metrics fetched successfully. Metrics output:"
log_and_run cat metrics_output.txt
METRICS_WORKING=true
else
log_and_run echo "Failed to fetch metrics from http://localhost:$LOCAL_PORT/metrics"
METRICS_WORKING=false
fi

log_and_run kill $PORT_FORWARD_PID
else
log_and_run echo "Port-forwarding failed to establish."
METRICS_WORKING=false
fi

if [ "$METRICS_WORKING" = true ]; then
log_and_run echo "Metrics service is working as expected."
exit 0
else
log_and_run echo "Metrics service is not working as expected."
exit 1
fi

4 changes: 4 additions & 0 deletions .github/workflows/ci-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ jobs:
run: |
.github/scripts/e2e_tests_brownfield_use_case.sh
- name: E2E tests for brownfield use case using kustomize
run: |
.github/scripts/e2e_tests_metrics_service.sh
- name: "Delay completion"
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
uses: scality/actions/[email protected]
Expand Down

0 comments on commit e477885

Please sign in to comment.