forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
73 lines (59 loc) · 2.37 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
package injector
import (
"strings"
"github.com/linkerd/linkerd2/pkg/inject"
"github.com/linkerd/linkerd2/pkg/k8s"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const (
labelOwnerKind = "owner_kind"
labelNamespace = "namespace"
labelSkip = "skip"
labelAnnotationAt = "annotation_at"
labelReason = "skip_reason"
)
var (
requestLabels = []string{labelOwnerKind, labelNamespace, labelAnnotationAt}
responseLabels = []string{labelOwnerKind, labelNamespace, labelSkip, labelReason, labelAnnotationAt}
proxyInjectionAdmissionRequests = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "proxy_inject_admission_requests_total",
Help: "A counter for number of admission requests to proxy injector.",
}, append(requestLabels, validLabelNames(inject.ProxyAnnotations)...))
proxyInjectionAdmissionResponses = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "proxy_inject_admission_responses_total",
Help: "A counter for number of admission responses from proxy injector.",
}, append(responseLabels, validLabelNames(inject.ProxyAnnotations)...))
)
func admissionRequestLabels(ownerKind, namespace, annotationAt string, configLabels prometheus.Labels) prometheus.Labels {
configLabels[labelOwnerKind] = ownerKind
configLabels[labelNamespace] = namespace
configLabels[labelAnnotationAt] = annotationAt
return configLabels
}
func admissionResponseLabels(owner, namespace, skip, reason, annotationAt string, configLabels prometheus.Labels) prometheus.Labels {
configLabels[labelOwnerKind] = owner
configLabels[labelNamespace] = namespace
configLabels[labelSkip] = skip
configLabels[labelReason] = reason
configLabels[labelAnnotationAt] = annotationAt
return configLabels
}
func configToPrometheusLabels(conf *inject.ResourceConfig) prometheus.Labels {
labels := conf.GetOverriddenConfiguration()
promLabels := map[string]string{}
for label, value := range labels {
promLabels[validProxyConfigurationLabel(label)] = value
}
return promLabels
}
func validLabelNames(labels []string) []string {
var validLabels []string
for _, label := range labels {
validLabels = append(validLabels, validProxyConfigurationLabel(label))
}
return validLabels
}
func validProxyConfigurationLabel(label string) string {
return strings.ReplaceAll(label[len(k8s.ProxyConfigAnnotationsPrefix)+1:], "-", "_")
}