forked from kubermatic/kubermatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
179 lines (148 loc) · 6.69 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
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
175
176
177
178
179
/*
Copyright 2020 The Kubermatic Kubernetes Platform contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/push"
"go.uber.org/zap"
)
const (
metricNamespace = "conformancetest"
)
var (
metricsPusher *push.Pusher
kubermaticLoginDurationMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "kubermatic_login_duration_seconds",
Help: "Time it took to perform the Kubermatic login, in seconds",
}, []string{"prowjob"})
kubermaticReconciliationDurationMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "kubermatic_reconciliation_duration_seconds",
Help: "Time it took for Kubermatic to fully reconcile the test cluster",
}, []string{"prowjob", "scenario"})
seedControlplaneDurationMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "seed_controlplane_duration_seconds",
Help: "Time it took the user-cluser's controlplane pods in the seed cluster to become ready",
}, []string{"prowjob", "scenario"})
clusterControlplaneDurationMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "cluster_controlplane_duration_seconds",
Help: "Time it took for all pods to be ready in a user cluster after all worker nodes have become ready",
}, []string{"prowjob", "scenario"})
nodeCreationDuration = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "node_creation_duration_seconds",
Help: "Time it took for all nodes to spawn after the NodeDeployments were created",
}, []string{"prowjob", "scenario"})
nodeRadinessDuration = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "node_readiness_duration_seconds",
Help: "Time it took for all nodes to become ready they appeared",
}, []string{"prowjob", "scenario"})
scenarioRuntimeMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "scenario_runtime_seconds",
Help: "Total duration of a scenario test run",
}, []string{"prowjob", "scenario"})
ginkgoRuntimeMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "ginkgo_runtime_seconds",
Help: "Number of seconds a Ginkgo run took",
}, []string{"prowjob", "scenario", "run", "attempt"})
ginkgoAttemptsMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "ginkgo_attempts",
Help: "Number of times a job has been run for a given scenario",
}, []string{"prowjob", "scenario", "run"})
pvctestRuntimeMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "pvctest_runtime_seconds",
Help: "Number of seconds a pvctest run took",
}, []string{"prowjob", "scenario", "attempt"})
pvctestAttemptsMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "pvctest_attempts",
Help: "Number of times a job has been run for a given scenario",
}, []string{"prowjob", "scenario"})
lbtestRuntimeMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "lbtest_runtime_seconds",
Help: "Number of seconds a lbtest run took",
}, []string{"prowjob", "scenario", "attempt"})
lbtestAttemptsMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "lbtest_attempts",
Help: "Number of times a job has been run for a given scenario",
}, []string{"prowjob", "scenario"})
)
func initMetrics(endpoint string, prowjob string, instance string) {
if endpoint == "" {
return
}
registry := prometheus.NewRegistry()
registry.MustRegister(kubermaticLoginDurationMetric)
registry.MustRegister(kubermaticReconciliationDurationMetric)
registry.MustRegister(seedControlplaneDurationMetric)
registry.MustRegister(clusterControlplaneDurationMetric)
registry.MustRegister(nodeCreationDuration)
registry.MustRegister(nodeRadinessDuration)
registry.MustRegister(scenarioRuntimeMetric)
registry.MustRegister(ginkgoRuntimeMetric)
registry.MustRegister(ginkgoAttemptsMetric)
registry.MustRegister(pvctestRuntimeMetric)
registry.MustRegister(pvctestAttemptsMetric)
registry.MustRegister(lbtestRuntimeMetric)
registry.MustRegister(lbtestAttemptsMetric)
prowjobLabel := prometheus.Labels{
"prowjob": prowjob,
}
kubermaticLoginDurationMetric = kubermaticLoginDurationMetric.MustCurryWith(prowjobLabel)
kubermaticReconciliationDurationMetric = kubermaticReconciliationDurationMetric.MustCurryWith(prowjobLabel)
seedControlplaneDurationMetric = seedControlplaneDurationMetric.MustCurryWith(prowjobLabel)
clusterControlplaneDurationMetric = clusterControlplaneDurationMetric.MustCurryWith(prowjobLabel)
nodeCreationDuration = nodeCreationDuration.MustCurryWith(prowjobLabel)
nodeRadinessDuration = nodeRadinessDuration.MustCurryWith(prowjobLabel)
scenarioRuntimeMetric = scenarioRuntimeMetric.MustCurryWith(prowjobLabel)
ginkgoRuntimeMetric = ginkgoRuntimeMetric.MustCurryWith(prowjobLabel)
ginkgoAttemptsMetric = ginkgoAttemptsMetric.MustCurryWith(prowjobLabel)
pvctestRuntimeMetric = pvctestRuntimeMetric.MustCurryWith(prowjobLabel)
pvctestAttemptsMetric = pvctestAttemptsMetric.MustCurryWith(prowjobLabel)
lbtestRuntimeMetric = lbtestRuntimeMetric.MustCurryWith(prowjobLabel)
lbtestAttemptsMetric = lbtestAttemptsMetric.MustCurryWith(prowjobLabel)
metricsPusher = push.New(endpoint, "conformancetest")
metricsPusher.Grouping("instance", instance)
metricsPusher.Gatherer(registry)
}
func updateMetrics(log *zap.SugaredLogger) {
if metricsPusher == nil {
return
}
if err := metricsPusher.Push(); err != nil {
log.Warnw("Failed to push metrics", zap.Error(err))
}
}
func measureTime(metric prometheus.Gauge, log *zap.SugaredLogger, callback func() error) error {
start := time.Now()
err := callback()
metric.Set(time.Since(start).Seconds())
updateMetrics(log)
return err
}
func timeMeasurementWrapper(metric prometheus.Gauge, log *zap.SugaredLogger, callback func() error) func() error {
return func() error {
return measureTime(metric, log, callback)
}
}