-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (148 loc) · 5.46 KB
/
go.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: build-metricly
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23.3'
# Install dependencies
- name: Install dependencies
run: go mod tidy
# Run static analysis and linters
- name: Run linters
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run
# Run tests
- name: Run tests
run: go test ./... -v -coverprofile=coverage.out
# Upload test coverage
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out
docker-build-test:
name: Build and test container Image
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build and run container
run: |
pip3 install podman-compose
docker compose up -d --build
sleep 60
docker ps -a
# health_status=$(sudo docker inspect --format '{{.State.Health.Status}}' metricly_metricly)
# if [[ "$health_status" != "healthy" ]]; then
# sudo podman inspect metricly_metricly
# echo "Error: The container is not healthy. Exiting."
# # exit 1 # Fail the script if the container is not healthy
# fi
# Verify metrics are exposed
- name: Verify metrics endpoint
run: |
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/api/v1/metrics)
if [ "$RESPONSE" -ne 200 ]; then
echo "Metrics endpoint not reachable"
exit 1
fi
echo "Metrics endpoint is reachable and returned HTTP $RESPONSE"
# Optional - Inspect metrics content
- name: Fetch and log metrics
run: |
RESPONSE=$(curl -s http://127.0.0.1:8080/api/v1/metrics)
if echo "$RESPONSE" | grep -q "metricly_cpu_total"; then
echo "metricly_cpu_total found!"
else
echo "metricly_cpu_total not found!" && exit 1
fi
if echo "$RESPONSE" | grep -q "metricly_memory_total_bytes"; then
echo "metricly_memory_total_bytes Metrics found!"
else
echo "metricly_memory_total_bytes not found!" && exit 1
fi
if echo "$RESPONSE" | grep -q "metricly_disk_usage_percentage"; then
echo "metricly_disk_usage_percentage Metrics found!"
else
echo "metricly_disk_usage_percentage not found!" && exit 1
fi
if echo "$RESPONSE" | grep -q "metricly_network_rx_bytes"; then
echo "metricly_network_rx_bytes Metrics found!"
else
echo "metricly_network_rx_bytes not found!" && exit 1
fi
# Verify /query api
- name: Test /api/v1/query
run: |
time=$(($(date +%s) - 10))
RESPONSE=$(curl -s "http://127.0.0.1:8080/api/v1/query?metric=metricly_cpu_total&time=$time")
if [[ $(echo "$RESPONSE" | jq '.data.result[0].value|length') -ne 2 ]]; then
echo "Didn't get any data point"
echo $RESPONSE
exit 1
fi
# Verify /query_range api
- name: Test /api/v1/query_range
run: |
start=$(($(date +%s) - 100))
end=$(date +%s)
RESPONSE=$(curl -s "http://127.0.0.1:8080/api/v1/query_range?metric=metricly_cpu_total&start=$start&end=$end&step=15s")
if [[ $(echo "$RESPONSE" | jq '.data.result[0].values|length') -le 1 ]]; then
echo "Didn't multiple data points"
echo $RESPONSE
exit 1
fi
RESPONSE=$(curl -s "http://127.0.0.1:8080/api/v1/query_range?metric=metricly_cpu_total&last=2m&step=15s")
if [[ $(echo "$RESPONSE" | jq '.data.result[0].values|length') -le 1 ]]; then
echo "Didn't multiple data points"
echo $RESPONSE
exit 1
fi
# Verify /aggregate api
- name: Test /api/v1/aggregate
run: |
RESPONSE=$(curl -s "http://127.0.0.1:8080/api/v1/aggregate?metric=metricly_cpu_total&operation=avg&window=1m")
if [[ $(echo "$RESPONSE" | jq '.data.result[0].value|length') -ne 2 ]]; then
echo "Didn't multiple data points"
echo $RESPONSE
exit 1
fi
# Step 6: Stop and remove the container
- name: Clean up container
run: make run_compose_down
docker-build-push:
name: Push Metricly to Quay.io
runs-on: ubuntu-latest
needs: docker-build-test
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Quay.io
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: quay.io/yadneshk/metricly:latest