mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
fix github action pipeline
This commit is contained in:
parent
b851a9b525
commit
782096c294
1 changed files with 275 additions and 50 deletions
325
.github/workflows/pipeline.yml
vendored
325
.github/workflows/pipeline.yml
vendored
|
@ -2,7 +2,7 @@ name: CI/CD Pipeline with Monitoring
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ pipeline-optimization ]
|
branches: [ pipeline-optimization ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ pipeline-optimization ]
|
branches: [ pipeline-optimization ]
|
||||||
|
|
||||||
|
@ -15,83 +15,101 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
services:
|
services:
|
||||||
mysql:
|
mysql:
|
||||||
image: mysql:9.1
|
image: mysql:8.0 # Updated to stable version
|
||||||
env:
|
env:
|
||||||
MYSQL_ROOT_PASSWORD: ''
|
MYSQL_ROOT_PASSWORD: root # Avoid empty passwords
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: true
|
|
||||||
MYSQL_USER: petclinic
|
MYSQL_USER: petclinic
|
||||||
MYSQL_PASSWORD: petclinic
|
MYSQL_PASSWORD: petclinic
|
||||||
MYSQL_DATABASE: petclinic
|
MYSQL_DATABASE: petclinic
|
||||||
ports:
|
ports:
|
||||||
- 3306:3306
|
- 3306:3306
|
||||||
|
options: >-
|
||||||
|
--health-cmd="mysqladmin ping"
|
||||||
|
--health-interval=10s
|
||||||
|
--health-timeout=5s
|
||||||
|
--health-retries=3
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Compose
|
||||||
|
run: |
|
||||||
|
docker-compose version
|
||||||
|
docker-compose pull prometheus grafana powerapi node-exporter
|
||||||
|
|
||||||
- name: Start Monitoring Stack
|
- name: Start Monitoring Stack
|
||||||
run: |
|
run: |
|
||||||
docker-compose up -d prometheus grafana powerapi node-exporter
|
docker-compose up -d prometheus grafana powerapi node-exporter
|
||||||
sleep 10 # Attendre que les services démarrent
|
# Use healthcheck instead of sleep
|
||||||
|
timeout 60s bash -c 'until curl -s -f http://localhost:9090/-/healthy; do sleep 2; done'
|
||||||
- name: Checkout code
|
timeout 60s bash -c 'until curl -s -f http://localhost:3000/api/health; do sleep 2; done'
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
distribution: 'adopt'
|
distribution: 'temurin' # More stable than adopt
|
||||||
|
cache: 'maven' # Enable Maven caching
|
||||||
|
|
||||||
- name: Record Build Start
|
- name: Record Build Start
|
||||||
run: |
|
run: |
|
||||||
curl -X POST http://localhost:9091/metrics/job/pipeline/instance/build \
|
curl -X POST http://localhost:9091/metrics/job/pipeline/instance/build \
|
||||||
--data-binary "pipeline_stage_start{stage=\"build\"} $(date +%s)"
|
--data-binary "pipeline_stage_start{stage=\"build\"} $(date +%s)" \
|
||||||
|
--retry 3 --retry-delay 2 # Add retry logic
|
||||||
|
|
||||||
- name: Maven Build
|
- name: Maven Build
|
||||||
run: |
|
run: |
|
||||||
start_time=$(date +%s%N)
|
start_time=$(date +%s%N)
|
||||||
./mvnw clean package
|
./mvnw -B clean package # Add -B for non-interactive mode
|
||||||
end_time=$(date +%s%N)
|
end_time=$(date +%s%N)
|
||||||
duration=$(( ($end_time - $start_time)/1000000 ))
|
duration=$(( ($end_time - $start_time)/1000000 ))
|
||||||
|
|
||||||
# Envoyer les métriques à Prometheus
|
|
||||||
echo "pipeline_build_duration_ms $duration" | curl -X POST --data-binary @- \
|
echo "pipeline_build_duration_ms $duration" | curl -X POST --data-binary @- \
|
||||||
http://localhost:9091/metrics/job/pipeline/instance/build
|
http://localhost:9091/metrics/job/pipeline/instance/build \
|
||||||
|
--retry 3 --retry-delay 2
|
||||||
|
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: |
|
run: |
|
||||||
start_time=$(date +%s%N)
|
start_time=$(date +%s%N)
|
||||||
./mvnw test
|
./mvnw -B test
|
||||||
end_time=$(date +%s%N)
|
end_time=$(date +%s%N)
|
||||||
duration=$(( ($end_time - $start_time)/1000000 ))
|
duration=$(( ($end_time - $start_time)/1000000 ))
|
||||||
|
|
||||||
# Envoyer les métriques à Prometheus
|
|
||||||
echo "pipeline_test_duration_ms $duration" | curl -X POST --data-binary @- \
|
echo "pipeline_test_duration_ms $duration" | curl -X POST --data-binary @- \
|
||||||
http://localhost:9091/metrics/job/pipeline/instance/test
|
http://localhost:9091/metrics/job/pipeline/instance/test \
|
||||||
|
--retry 3 --retry-delay 2
|
||||||
|
|
||||||
- name: Collect Metrics
|
- name: Collect Metrics
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
# Récupérer les métriques de PowerAPI
|
# Add error handling for metric collection
|
||||||
curl -o power_metrics.json http://localhost:9091/metrics/job/powerapi
|
collect_metric() {
|
||||||
|
local url=$1
|
||||||
|
local output=$2
|
||||||
|
curl -f -S --retry 3 --retry-delay 2 -o "$output" "$url" || echo "Failed to collect metric from $url"
|
||||||
|
}
|
||||||
|
|
||||||
# Récupérer les métriques système
|
collect_metric "http://localhost:9091/metrics/job/powerapi" "power_metrics.json"
|
||||||
curl -o node_metrics.json http://localhost:9100/metrics
|
collect_metric "http://localhost:9100/metrics" "node_metrics.json"
|
||||||
|
collect_metric "$PROMETHEUS_URL/api/v1/query?query=pipeline_build_duration_ms" "prometheus_metrics.json"
|
||||||
|
|
||||||
# Récupérer les métriques de Prometheus
|
# Generate report only if metrics are available
|
||||||
curl -o prometheus_metrics.json "$PROMETHEUS_URL/api/v1/query?query=pipeline_build_duration_ms"
|
if [[ -f prometheus_metrics.json && -f power_metrics.json && -f node_metrics.json ]]; then
|
||||||
|
cat << EOF > metrics_report.txt
|
||||||
# Générer le rapport des métriques
|
|
||||||
cat << EOF > metrics_report.txt
|
|
||||||
Pipeline Run Report - $(date)
|
Pipeline Run Report - $(date)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
Build Duration: $(cat prometheus_metrics.json | jq .data.result[0].value[1])ms
|
Build Duration: $(jq -r '.data.result[0].value[1] // "N/A"' prometheus_metrics.json)ms
|
||||||
Power Consumption: $(cat power_metrics.json | jq .total_power_consumption)W
|
Power Consumption: $(jq -r '.total_power_consumption // "N/A"' power_metrics.json)W
|
||||||
CPU Usage: $(cat node_metrics.json | grep cpu_usage_percent | awk '{print $2}')%
|
CPU Usage: $(grep -oP 'cpu_usage_percent \K[\d.]+' node_metrics.json || echo "N/A")%
|
||||||
Memory Usage: $(cat node_metrics.json | grep memory_usage_bytes | awk '{print $2/1024/1024}')MB
|
Memory Usage: $(awk '/memory_usage_bytes/{printf "%.2f", $2/1024/1024}' node_metrics.json || echo "N/A")MB
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Upload Metrics
|
- name: Upload Metrics
|
||||||
uses: actions/upload-artifact@v3
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4 # Updated from v3
|
||||||
with:
|
with:
|
||||||
name: pipeline-metrics
|
name: pipeline-metrics
|
||||||
path: |
|
path: |
|
||||||
|
@ -99,43 +117,250 @@ jobs:
|
||||||
power_metrics.json
|
power_metrics.json
|
||||||
node_metrics.json
|
node_metrics.json
|
||||||
prometheus_metrics.json
|
prometheus_metrics.json
|
||||||
|
retention-days: 30
|
||||||
|
compression-level: 'maximum'
|
||||||
|
|
||||||
|
# Verify project structure
|
||||||
|
- name: List monitoring directory
|
||||||
|
run: |
|
||||||
|
ls -la monitoring/grafana/dashboards/
|
||||||
|
echo "Content of pipeline.json:"
|
||||||
|
cat monitoring/grafana/dashboards/pipeline.json
|
||||||
|
|
||||||
- name: Create Grafana Dashboard
|
- name: Create Grafana Dashboard
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
# Créer un dashboard Grafana via l'API
|
# Using the full path relative to workspace
|
||||||
curl -X POST -H "Content-Type: application/json" \
|
DASHBOARD_PATH="$GITHUB_WORKSPACE/monitoring/grafana/dashboards/pipeline.json"
|
||||||
-d @- \
|
if [ ! -f "$DASHBOARD_PATH" ]; then
|
||||||
$GRAFANA_URL/api/dashboards/db << EOF
|
echo "Error: Dashboard file not found at $DASHBOARD_PATH"
|
||||||
{
|
exit 1
|
||||||
"dashboard": {
|
fi
|
||||||
"title": "Pipeline Performance Dashboard",
|
|
||||||
|
# Create dashboard using the JSON file
|
||||||
|
curl -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
--retry 3 \
|
||||||
|
--retry-delay 2 \
|
||||||
|
-f \
|
||||||
|
-d "{\"dashboard\": $(cat $DASHBOARD_PATH), \"overwrite\": true}" \
|
||||||
|
$GRAFANA_URL/api/dashboards/db || echo "Failed to create dashboard"
|
||||||
|
"annotations": {
|
||||||
|
"list": []
|
||||||
|
},
|
||||||
|
"editable": true,
|
||||||
|
"fiscalYearStartMonth": 0,
|
||||||
|
"graphTooltip": 0,
|
||||||
|
"links": [],
|
||||||
|
"liveNow": false,
|
||||||
"panels": [
|
"panels": [
|
||||||
{
|
{
|
||||||
"title": "Build Duration",
|
"datasource": {
|
||||||
"type": "graph",
|
"type": "prometheus",
|
||||||
"datasource": "Prometheus",
|
"uid": "prometheus"
|
||||||
|
},
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"color": {
|
||||||
|
"mode": "palette-classic"
|
||||||
|
},
|
||||||
|
"custom": {
|
||||||
|
"axisCenteredZero": false,
|
||||||
|
"axisColorMode": "text",
|
||||||
|
"axisLabel": "",
|
||||||
|
"axisPlacement": "auto",
|
||||||
|
"barAlignment": 0,
|
||||||
|
"drawStyle": "line",
|
||||||
|
"fillOpacity": 20,
|
||||||
|
"gradientMode": "none",
|
||||||
|
"hideFrom": {
|
||||||
|
"legend": false,
|
||||||
|
"tooltip": false,
|
||||||
|
"viz": false
|
||||||
|
},
|
||||||
|
"lineInterpolation": "smooth",
|
||||||
|
"lineWidth": 2,
|
||||||
|
"pointSize": 5,
|
||||||
|
"scaleDistribution": {
|
||||||
|
"type": "linear"
|
||||||
|
},
|
||||||
|
"showPoints": "never",
|
||||||
|
"spanNulls": true,
|
||||||
|
"stacking": {
|
||||||
|
"group": "A",
|
||||||
|
"mode": "none"
|
||||||
|
},
|
||||||
|
"thresholdsStyle": {
|
||||||
|
"mode": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mappings": [],
|
||||||
|
"thresholds": {
|
||||||
|
"mode": "absolute",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"color": "green",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "red",
|
||||||
|
"value": 80
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"unit": "ms"
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"h": 8,
|
||||||
|
"w": 12,
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"id": 1,
|
||||||
|
"options": {
|
||||||
|
"legend": {
|
||||||
|
"calcs": ["mean", "max", "min"],
|
||||||
|
"displayMode": "table",
|
||||||
|
"placement": "bottom",
|
||||||
|
"showLegend": true
|
||||||
|
},
|
||||||
|
"tooltip": {
|
||||||
|
"mode": "single",
|
||||||
|
"sort": "none"
|
||||||
|
}
|
||||||
|
},
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
"expr": "pipeline_build_duration_ms"
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "prometheus"
|
||||||
|
},
|
||||||
|
"editorMode": "code",
|
||||||
|
"expr": "pipeline_build_duration_ms",
|
||||||
|
"legendFormat": "Build Duration",
|
||||||
|
"range": true,
|
||||||
|
"refId": "A"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"title": "Pipeline Build Duration",
|
||||||
|
"type": "timeseries"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Power Consumption",
|
"datasource": {
|
||||||
"type": "graph",
|
"type": "prometheus",
|
||||||
"datasource": "Prometheus",
|
"uid": "prometheus"
|
||||||
|
},
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"color": {
|
||||||
|
"mode": "palette-classic"
|
||||||
|
},
|
||||||
|
"custom": {
|
||||||
|
"axisCenteredZero": false,
|
||||||
|
"axisColorMode": "text",
|
||||||
|
"axisLabel": "",
|
||||||
|
"axisPlacement": "auto",
|
||||||
|
"barAlignment": 0,
|
||||||
|
"drawStyle": "line",
|
||||||
|
"fillOpacity": 20,
|
||||||
|
"gradientMode": "none",
|
||||||
|
"hideFrom": {
|
||||||
|
"legend": false,
|
||||||
|
"tooltip": false,
|
||||||
|
"viz": false
|
||||||
|
},
|
||||||
|
"lineInterpolation": "smooth",
|
||||||
|
"lineWidth": 2,
|
||||||
|
"pointSize": 5,
|
||||||
|
"scaleDistribution": {
|
||||||
|
"type": "linear"
|
||||||
|
},
|
||||||
|
"showPoints": "never",
|
||||||
|
"spanNulls": true,
|
||||||
|
"stacking": {
|
||||||
|
"group": "A",
|
||||||
|
"mode": "none"
|
||||||
|
},
|
||||||
|
"thresholdsStyle": {
|
||||||
|
"mode": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mappings": [],
|
||||||
|
"thresholds": {
|
||||||
|
"mode": "absolute",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"color": "green",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "red",
|
||||||
|
"value": 80
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"unit": "watts"
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"h": 8,
|
||||||
|
"w": 12,
|
||||||
|
"x": 12,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"id": 2,
|
||||||
|
"options": {
|
||||||
|
"legend": {
|
||||||
|
"calcs": ["mean", "max"],
|
||||||
|
"displayMode": "table",
|
||||||
|
"placement": "bottom",
|
||||||
|
"showLegend": true
|
||||||
|
},
|
||||||
|
"tooltip": {
|
||||||
|
"mode": "single",
|
||||||
|
"sort": "none"
|
||||||
|
}
|
||||||
|
},
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
"expr": "power_consumption_watts"
|
"datasource": {
|
||||||
|
"type": "prometheus",
|
||||||
|
"uid": "prometheus"
|
||||||
|
},
|
||||||
|
"editorMode": "code",
|
||||||
|
"expr": "power_consumption_watts",
|
||||||
|
"legendFormat": "Power Consumption",
|
||||||
|
"range": true,
|
||||||
|
"refId": "A"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"title": "Power Consumption",
|
||||||
|
"type": "timeseries"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
}
|
"refresh": "5s",
|
||||||
|
"schemaVersion": 38,
|
||||||
|
"style": "dark",
|
||||||
|
"tags": ["pipeline", "performance"],
|
||||||
|
"templating": {
|
||||||
|
"list": []
|
||||||
|
},
|
||||||
|
"time": {
|
||||||
|
"from": "now-1h",
|
||||||
|
"to": "now"
|
||||||
|
},
|
||||||
|
"title": "Pipeline Performance",
|
||||||
|
"weekStart": ""
|
||||||
|
},
|
||||||
|
"overwrite": true
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: docker-compose down
|
run: |
|
||||||
|
docker-compose down --volumes --remove-orphans
|
||||||
|
docker system prune -f
|
||||||
|
|
Loading…
Reference in a new issue