-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add end-2-end tests for metrics service
Issue: COSI-46
- Loading branch information
1 parent
d46982a
commit 1e81b7e
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/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" | ||
} | ||
|
||
# Start port-forwarding in the background | ||
kubectl port-forward svc/$SERVICE -n $NAMESPACE $LOCAL_PORT:$TARGET_PORT & | ||
PORT_FORWARD_PID=$! | ||
|
||
# Check if the port-forwarding is running | ||
if ps -p $PORT_FORWARD_PID > /dev/null; then | ||
log_and_run echo "Port-forwarding established. Querying metrics..." | ||
|
||
# Use curl to check 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 | ||
|
||
# Kill port-forwarding process | ||
log_and_run kill $PORT_FORWARD_PID | ||
else | ||
log_and_run echo "Port-forwarding failed to establish." | ||
METRICS_WORKING=false | ||
fi | ||
|
||
# Exit with appropriate status for CI | ||
if [ "$METRICS_WORKING" = true ]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters