-
Notifications
You must be signed in to change notification settings - Fork 16
/
metrics.go
64 lines (53 loc) · 2.33 KB
/
metrics.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
59
60
61
62
63
64
package ci
import "github.com/prometheus/client_golang/prometheus"
// TestExecutionMetricsCollectors returns a list of Prometheus metrics collectors for test execution.
func TestExecutionMetricsCollectors() []prometheus.Collector {
return []prometheus.Collector{
cloneTimeGauge,
validationTimeGauge,
testExecutionTimeGauge,
testsStartedCounter,
testsFailedCounter,
testsSucceededCounter,
}
}
var (
cloneTimeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "quickfeed_clone_repositories_time",
Help: "The time to clone tests and student repository for test execution.",
}, []string{"user", "course"})
validationTimeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "quickfeed_repository_validation_time",
Help: "The time to validate student repository for issues.",
}, []string{"user", "course"})
testExecutionTimeGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "quickfeed_test_execution_time",
Help: "The time to run test execution.",
}, []string{"user", "course"})
testsStartedCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "quickfeed_test_execution_attempts",
Help: "Total number of times test execution was attempted",
}, []string{"user", "course"})
testsFailedCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "quickfeed_test_execution_failed",
Help: "Total number of times test execution failed",
}, []string{"user", "course"})
testsFailedWithOutputCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "quickfeed_test_execution_failed_with_output",
Help: "Total number of times test execution failed with output",
}, []string{"user", "course"})
testsFailedExtractResultsCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "quickfeed_test_execution_failed_to_extract_results",
Help: "Total number of times test execution failed to extract results",
}, []string{"user", "course"})
testsSucceededCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "quickfeed_test_execution_succeeded",
Help: "Total number of times test execution succeeded",
}, []string{"user", "course"})
)
func timer(jobOwner, course string, gauge *prometheus.GaugeVec) func() {
responseTimer := prometheus.NewTimer(prometheus.ObserverFunc(
gauge.WithLabelValues(jobOwner, course).Set),
)
return func() { responseTimer.ObserveDuration() }
}