Skip to content

Commit 5946662

Browse files
set up ci and prometheus metrics
1 parent 608d7bb commit 5946662

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
services:
12+
redis:
13+
image: redis:7-alpine
14+
ports:
15+
- 6379:6379
16+
options: >-
17+
--health-cmd "redis-cli ping"
18+
--health-interval 5s
19+
--health-timeout 3s
20+
--health-retries 5
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-go@v5
24+
with:
25+
go-version: "1.24"
26+
- run: go vet ./...
27+
- run: go build ./...
28+
- run: go test -race ./...
29+
env:
30+
RELAY_REDIS_ADDR: 127.0.0.1:6379
31+
32+
lint:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions/setup-go@v5
37+
with:
38+
go-version: "1.24"
39+
- name: gofmt
40+
run: test -z "$(gofmt -l .)"

metrics.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package relay
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/prometheus/client_golang/prometheus"
7+
"github.com/prometheus/client_golang/prometheus/promauto"
8+
"github.com/prometheus/client_golang/prometheus/promhttp"
9+
)
10+
11+
var (
12+
tasksProcessed = promauto.NewCounterVec(prometheus.CounterOpts{
13+
Namespace: "relay",
14+
Name: "tasks_processed_total",
15+
Help: "Number of tasks processed successfully.",
16+
}, []string{"queue", "type"})
17+
18+
tasksFailed = promauto.NewCounterVec(prometheus.CounterOpts{
19+
Namespace: "relay",
20+
Name: "tasks_failed_total",
21+
Help: "Number of task executions that returned an error.",
22+
}, []string{"queue", "type"})
23+
24+
tasksRetried = promauto.NewCounterVec(prometheus.CounterOpts{
25+
Namespace: "relay",
26+
Name: "tasks_retried_total",
27+
Help: "Number of tasks scheduled for retry.",
28+
}, []string{"queue", "type"})
29+
30+
tasksArchived = promauto.NewCounterVec(prometheus.CounterOpts{
31+
Namespace: "relay",
32+
Name: "tasks_archived_total",
33+
Help: "Number of tasks moved to the archive after exhausting retries.",
34+
}, []string{"queue", "type"})
35+
36+
tasksInProgress = promauto.NewGaugeVec(prometheus.GaugeOpts{
37+
Namespace: "relay",
38+
Name: "tasks_in_progress",
39+
Help: "Number of tasks currently being processed.",
40+
}, []string{"queue"})
41+
42+
processingDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
43+
Namespace: "relay",
44+
Name: "task_duration_seconds",
45+
Help: "Time spent processing a task.",
46+
Buckets: prometheus.DefBuckets,
47+
}, []string{"queue", "type"})
48+
)
49+
50+
func MetricsHandler() http.Handler {
51+
return promhttp.Handler()
52+
}

0 commit comments

Comments
 (0)