-
Notifications
You must be signed in to change notification settings - Fork 127
/
job_run_state.go
58 lines (46 loc) · 1.39 KB
/
job_run_state.go
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
package runstate
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/armadaproject/armada/internal/executor/job"
"github.com/armadaproject/armada/internal/executor/metrics"
)
const (
queueLabel = "queue"
phaseLabel = "phase"
)
var runPhaseCountDesc = prometheus.NewDesc(
metrics.ArmadaExecutorMetricsPrefix+"run_phase",
"Runs in different phases by queue",
[]string{queueLabel, phaseLabel}, nil,
)
type JobRunStateStoreMetricsCollector struct {
jobRunStateStore job.RunStateStore
}
func NewJobRunStateStoreMetricsCollector(jobRunStateStore job.RunStateStore) *JobRunStateStoreMetricsCollector {
collector := &JobRunStateStoreMetricsCollector{
jobRunStateStore: jobRunStateStore,
}
return collector
}
func (j *JobRunStateStoreMetricsCollector) Describe(desc chan<- *prometheus.Desc) {
desc <- runPhaseCountDesc
}
type runStateKey struct {
Queue string
Phase job.RunPhase
}
func (j *JobRunStateStoreMetricsCollector) Collect(metrics chan<- prometheus.Metric) {
runs := j.jobRunStateStore.GetAll()
phaseCountByQueue := map[runStateKey]int{}
for _, run := range runs {
key := runStateKey{
Queue: run.Meta.Queue,
Phase: run.Phase,
}
phaseCountByQueue[key]++
}
for metricKey, value := range phaseCountByQueue {
metrics <- prometheus.MustNewConstMetric(runPhaseCountDesc, prometheus.GaugeValue,
float64(value), metricKey.Queue, metricKey.Phase.String())
}
}