Skip to content

Commit 5f2487b

Browse files
committed
chore: update GitHub Actions for Docker and monitoring setup
1 parent 90c05f0 commit 5f2487b

File tree

20 files changed

+360
-74
lines changed

20 files changed

+360
-74
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
version: 2
22
updates:
33
- package-ecosystem: "gradle"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
12+
13+
- package-ecosystem: "docker"
414
directory: "/"
515
schedule:
616
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
build:
10+
11+
ci:
1112
runs-on: ubuntu-latest
1213

13-
# ─── Variável de ambiente necessária para o JwtService inicializar ───
14-
env:
15-
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
16-
1714
steps:
1815
- name: Checkout repository
1916
uses: actions/checkout@v4
@@ -27,31 +24,42 @@ jobs:
2724
java-version: '25'
2825
cache: gradle
2926

27+
- name: Grant execute permission for Gradle
28+
run: chmod +x gradlew
29+
3030
- name: Cache SonarCloud packages
3131
uses: actions/cache@v4
3232
with:
3333
path: ~/.sonar/cache
3434
key: ${{ runner.os }}-sonar
3535
restore-keys: ${{ runner.os }}-sonar
3636

37-
- name: Grant execute permission for Gradle
38-
run: chmod +x gradlew
37+
- name: Build + Test + Coverage
38+
run: ./gradlew clean build
3939

40-
- name: Build, Test, Coverage and Sonar
40+
- name: SonarCloud Scan
4141
env:
4242
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
43-
run: |
44-
./gradlew clean build \
45-
jacocoTestReport \
46-
jacocoTestCoverageVerification \
47-
sonar --info
43+
run: ./gradlew sonar --info
4844

4945
- name: Upload coverage to Codecov
5046
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2 - pinned SHA
5147
with:
5248
token: ${{ secrets.CODECOV_TOKEN }}
5349
files: build/reports/jacoco/test/jacocoTestReport.xml
5450

51+
docker:
52+
runs-on: ubuntu-latest
53+
54+
needs: ci
55+
56+
if: github.ref == 'refs/heads/main'
57+
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
5562
# ─── Build Docker ───
56-
- name: Build Docker image
57-
run: docker build -t library-api .
63+
- name: Validate Docker Build
64+
run: docker build -t library-api:${{ github.sha }} . \
65+
-t library-api:latest .

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ build/
44
!gradle/wrapper/gradle-wrapper.jar
55
!**/src/main/**/build/
66
!**/src/test/**/build/
7+
/monitoring/grafana/data/
78

89
### STS ###
910
.apt_generated

docker-compose.dev.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,3 @@ volumes:
8181
redis_data:
8282
pgadmin_data:
8383
prometheus_data:
84-
grafana_data:

docker-compose.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ services:
4040
ports:
4141
- "9090:9090"
4242
volumes:
43-
- ./prometheus.yml:/etc/prometheus/prometheus.yml
43+
- ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
4444
- prometheus_data:/prometheus
4545
restart: unless-stopped
4646
networks:
@@ -51,7 +51,14 @@ services:
5151
ports:
5252
- "3000:3000"
5353
volumes:
54-
- grafana_data:/var/lib/grafana
54+
# provisioning config
55+
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning
56+
57+
# banco interno (persistência real)
58+
- ./monitoring/grafana/data:/var/lib/grafana
59+
environment:
60+
- GF_ALERTING_ENABLED=true
61+
- GF_UNIFIED_ALERTING_ENABLED=true
5562
depends_on:
5663
- prometheus
5764
restart: unless-stopped
@@ -74,6 +81,14 @@ services:
7481
- backend
7582

7683
library-api:
84+
deploy:
85+
resources:
86+
limits:
87+
cpus: '1'
88+
memory: 1G
89+
reservations:
90+
cpus: '0.5'
91+
memory: 512M
7792
build: .
7893
image: library-api
7994
environment:
@@ -82,6 +97,8 @@ services:
8297
DB_USERNAME: ${DB_USERNAME}
8398
DB_PASSWORD: ${DB_PASSWORD}
8499
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
100+
REDIS_HOST: ${REDIS_HOST}
101+
REDIS_PORT: ${REDIS_PORT}
85102
ports:
86103
- "8080:8080"
87104
depends_on:
@@ -91,7 +108,13 @@ services:
91108
condition: service_healthy
92109
networks:
93110
- backend
94-
restart: unless-stopped
111+
restart: unless-stopped
112+
healthcheck:
113+
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
114+
interval: 30s
115+
timeout: 10s
116+
retries: 3
117+
start_period: 40s
95118

96119
networks:
97120
backend:
@@ -101,4 +124,3 @@ volumes:
101124
redis_data:
102125
pgadmin_data:
103126
prometheus_data:
104-
grafana_data:

monitoring/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Monitoring Stack
2+
3+
## Services
4+
- Prometheus: http://localhost:9090
5+
- Grafana: http://localhost:3000 (admin/admin)
6+
7+
## Dashboards
8+
- Library API Overview: Auto-imported
9+
10+
## Custom Metrics
11+
- `books_created_total`: Counter de livros criados
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: 1
2+
3+
providers:
4+
- name: 'library'
5+
orgId: 1
6+
folder: ''
7+
type: file
8+
disableDeletion: false
9+
editable: true
10+
options:
11+
path: /etc/grafana/provisioning/dashboards
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"annotations": { "list": [] },
3+
"editable": true,
4+
"panels": [
5+
{
6+
"type": "stat",
7+
"title": "Total Books",
8+
"datasource": "Prometheus",
9+
"targets": [
10+
{ "expr": "library_books_total", "refId": "A" }
11+
],
12+
"gridPos": { "h": 5, "w": 6, "x": 0, "y": 0 }
13+
},
14+
{
15+
"type": "timeseries",
16+
"title": "Requests per Second",
17+
"datasource": "Prometheus",
18+
"targets": [
19+
{
20+
"expr": "rate(http_server_requests_seconds_count{uri!=\"/actuator/prometheus\"}[1m])",
21+
"legendFormat": "RPS",
22+
"refId": "A"
23+
}
24+
],
25+
"gridPos": { "h": 8, "w": 12, "x": 6, "y": 0 }
26+
},
27+
{
28+
"type": "timeseries",
29+
"title": "Requests by Endpoint",
30+
"datasource": "Prometheus",
31+
"targets": [
32+
{
33+
"expr": "rate(http_server_requests_seconds_count{uri!=\"/actuator/prometheus\"}[1m])",
34+
"legendFormat": "{{uri}}",
35+
"refId": "A"
36+
}
37+
],
38+
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 5 }
39+
},
40+
{
41+
"type": "timeseries",
42+
"title": "5xx Errors per Second",
43+
"datasource": "Prometheus",
44+
"targets": [
45+
{
46+
"expr": "rate(http_server_requests_seconds_count{status=~\"5..\"}[1m])",
47+
"legendFormat": "5xx",
48+
"refId": "A"
49+
}
50+
],
51+
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 5 }
52+
},
53+
{
54+
"type": "timeseries",
55+
"title": "Average Response Time (ms)",
56+
"datasource": "Prometheus",
57+
"targets": [
58+
{
59+
"expr": "rate(http_server_requests_seconds_sum[1m]) / rate(http_server_requests_seconds_count[1m]) * 1000",
60+
"legendFormat": "Avg Response",
61+
"refId": "A"
62+
}
63+
],
64+
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 13 }
65+
},
66+
{
67+
"type": "stat",
68+
"title": "Error Rate (%)",
69+
"datasource": "Prometheus",
70+
"targets": [
71+
{
72+
"expr": "(rate(http_server_requests_seconds_count{status=~\"5..\"}[1m]) / rate(http_server_requests_seconds_count[1m])) * 100",
73+
"refId": "A"
74+
}
75+
],
76+
"gridPos": { "h": 5, "w": 6, "x": 12, "y": 13 }
77+
}
78+
],
79+
"refresh": "5s",
80+
"schemaVersion": 38,
81+
"style": "dark",
82+
"tags": ["library", "observability"],
83+
"time": { "from": "now-15m", "to": "now" },
84+
"title": "Library API - Production Dashboard",
85+
"version": 1
86+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: 1
2+
3+
datasources:
4+
- name: Prometheus
5+
type: prometheus
6+
access: proxy
7+
url: http://prometheus:9090
8+
isDefault: true

monitoring/prometheus/alerts.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
groups:
2+
- name: library-api
3+
interval: 30s
4+
rules:
5+
- alert: HighErrorRate
6+
expr: rate(http_server_requests_seconds_count{status=~"5.."}[5m]) > 0.05
7+
for: 5m
8+
labels:
9+
severity: warning
10+
annotations:
11+
summary: "High error rate detected"
12+
13+
- alert: HighMemoryUsage
14+
expr: jvm_memory_used_bytes / jvm_memory_max_bytes > 0.9
15+
for: 5m
16+
labels:
17+
severity: critical

0 commit comments

Comments
 (0)