mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
add pipeline before optimization
This commit is contained in:
parent
99eb528f29
commit
b7ae2bef5a
1 changed files with 141 additions and 0 deletions
141
.github/workflows/pipeline.yml
vendored
Normal file
141
.github/workflows/pipeline.yml
vendored
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
name: CI/CD Pipeline with Monitoring
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
PROMETHEUS_URL: http://localhost:9090
|
||||||
|
GRAFANA_URL: http://localhost:3000
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:9.1
|
||||||
|
env:
|
||||||
|
MYSQL_ROOT_PASSWORD: ''
|
||||||
|
MYSQL_ALLOW_EMPTY_PASSWORD: true
|
||||||
|
MYSQL_USER: petclinic
|
||||||
|
MYSQL_PASSWORD: petclinic
|
||||||
|
MYSQL_DATABASE: petclinic
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Start Monitoring Stack
|
||||||
|
run: |
|
||||||
|
docker-compose up -d prometheus grafana powerapi node-exporter
|
||||||
|
sleep 10 # Attendre que les services démarrent
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '17'
|
||||||
|
distribution: 'adopt'
|
||||||
|
|
||||||
|
- name: Record Build Start
|
||||||
|
run: |
|
||||||
|
curl -X POST http://localhost:9091/metrics/job/pipeline/instance/build \
|
||||||
|
--data-binary "pipeline_stage_start{stage=\"build\"} $(date +%s)"
|
||||||
|
|
||||||
|
- name: Maven Build
|
||||||
|
run: |
|
||||||
|
start_time=$(date +%s%N)
|
||||||
|
./mvnw clean package
|
||||||
|
end_time=$(date +%s%N)
|
||||||
|
duration=$(( ($end_time - $start_time)/1000000 ))
|
||||||
|
|
||||||
|
# Envoyer les métriques à Prometheus
|
||||||
|
echo "pipeline_build_duration_ms $duration" | curl -X POST --data-binary @- \
|
||||||
|
http://localhost:9091/metrics/job/pipeline/instance/build
|
||||||
|
|
||||||
|
- name: Run Tests
|
||||||
|
run: |
|
||||||
|
start_time=$(date +%s%N)
|
||||||
|
./mvnw test
|
||||||
|
end_time=$(date +%s%N)
|
||||||
|
duration=$(( ($end_time - $start_time)/1000000 ))
|
||||||
|
|
||||||
|
# Envoyer les métriques à Prometheus
|
||||||
|
echo "pipeline_test_duration_ms $duration" | curl -X POST --data-binary @- \
|
||||||
|
http://localhost:9091/metrics/job/pipeline/instance/test
|
||||||
|
|
||||||
|
- name: Collect Metrics
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
# Récupérer les métriques de PowerAPI
|
||||||
|
curl -o power_metrics.json http://localhost:9091/metrics/job/powerapi
|
||||||
|
|
||||||
|
# Récupérer les métriques système
|
||||||
|
curl -o node_metrics.json http://localhost:9100/metrics
|
||||||
|
|
||||||
|
# Récupérer les métriques de Prometheus
|
||||||
|
curl -o prometheus_metrics.json "$PROMETHEUS_URL/api/v1/query?query=pipeline_build_duration_ms"
|
||||||
|
|
||||||
|
# Générer le rapport des métriques
|
||||||
|
cat << EOF > metrics_report.txt
|
||||||
|
Pipeline Run Report - $(date)
|
||||||
|
===========================
|
||||||
|
|
||||||
|
Build Duration: $(cat prometheus_metrics.json | jq .data.result[0].value[1])ms
|
||||||
|
Power Consumption: $(cat power_metrics.json | jq .total_power_consumption)W
|
||||||
|
CPU Usage: $(cat node_metrics.json | grep cpu_usage_percent | awk '{print $2}')%
|
||||||
|
Memory Usage: $(cat node_metrics.json | grep memory_usage_bytes | awk '{print $2/1024/1024}')MB
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Upload Metrics
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: pipeline-metrics
|
||||||
|
path: |
|
||||||
|
metrics_report.txt
|
||||||
|
power_metrics.json
|
||||||
|
node_metrics.json
|
||||||
|
prometheus_metrics.json
|
||||||
|
|
||||||
|
- name: Create Grafana Dashboard
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
# Créer un dashboard Grafana via l'API
|
||||||
|
curl -X POST -H "Content-Type: application/json" \
|
||||||
|
-d @- \
|
||||||
|
$GRAFANA_URL/api/dashboards/db << EOF
|
||||||
|
{
|
||||||
|
"dashboard": {
|
||||||
|
"title": "Pipeline Performance Dashboard",
|
||||||
|
"panels": [
|
||||||
|
{
|
||||||
|
"title": "Build Duration",
|
||||||
|
"type": "graph",
|
||||||
|
"datasource": "Prometheus",
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"expr": "pipeline_build_duration_ms"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Power Consumption",
|
||||||
|
"type": "graph",
|
||||||
|
"datasource": "Prometheus",
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"expr": "power_consumption_watts"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: docker-compose down
|
Loading…
Reference in a new issue