...
1 package metrics
2
3 import (
4 "github.com/prometheus/client_golang/prometheus"
5
6 "edge-infra.dev/pkg/k8s/runtime/controller/metrics"
7
8 l5dv1alpha1 "edge-infra.dev/pkg/edge/linkerd/k8s/apis/linkerd/v1alpha1"
9 )
10
11 var LinkerdReadinessMetric prometheus.GaugeVec = *prometheus.NewGaugeVec(
12 prometheus.GaugeOpts{
13 Name: metrics.Name("linkerd", "reconcile_readiness"),
14 Help: "Metric for linkerd controller readiness",
15 },
16 []string{"type", "status", "reason", "version"})
17
18 var TrustAnchorExpiry prometheus.GaugeVec = *prometheus.NewGaugeVec(
19 prometheus.GaugeOpts{
20 Name: metrics.Name("linkerd", "trust_anchor_expiry"),
21 Help: "Metric for linkerd trust anchor expiration date as UNIX timestamp",
22 },
23 []string{},
24 )
25
26 var WorkloadInjectionReadinessMetric prometheus.GaugeVec = *prometheus.NewGaugeVec(
27 prometheus.GaugeOpts{
28 Name: metrics.Name("workloadinjection", "reconcile_readiness"),
29 Help: "Metric for linkerd workload injection controller readiness",
30 },
31 []string{"type", "reason", "status"})
32
33 func RecordLinkerdReadiness(l5d *l5dv1alpha1.Linkerd) {
34 LinkerdReadinessMetric.Reset()
35 for _, condition := range l5d.Status.Conditions {
36 labels := prometheus.Labels{
37 "type": condition.Type,
38 "status": string(condition.Status),
39 "reason": condition.Reason,
40 "version": l5d.Status.Version,
41 }
42 if condition.Status == "False" || condition.Status == "Unknown" {
43 LinkerdReadinessMetric.With(labels).Set(0)
44 } else if condition.Status == "True" {
45 LinkerdReadinessMetric.With(labels).Set(1)
46 }
47 }
48 }
49
50 func RecordTrustAnchorExpiryTime(expiry float64) {
51 labels := prometheus.Labels{}
52 TrustAnchorExpiry.With(labels).Set(float64(expiry))
53 }
54
55 func RecordWorkloadInjectionReadiness(workloadInjection *l5dv1alpha1.LinkerdWorkloadInjection) {
56 WorkloadInjectionReadinessMetric.Reset()
57 for _, condition := range workloadInjection.Status.Conditions {
58 labels := prometheus.Labels{
59 "type": condition.Type,
60 "status": string(condition.Status),
61 "reason": condition.Reason,
62 }
63 if condition.Status == "False" || condition.Status == "Unknown" {
64 WorkloadInjectionReadinessMetric.With(labels).Set(0)
65 } else if condition.Status == "True" {
66 WorkloadInjectionReadinessMetric.With(labels).Set(1)
67 }
68 }
69 }
70
View as plain text