/
prometheus.go
89 lines (74 loc) · 3.28 KB
/
prometheus.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
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)
type CtrlFuncMetrics struct {
// ConfigPushCount is a Prometheus metric with semantics defined by its help string in NewCtrlFuncMetrics().
ConfigPushCount *prometheus.CounterVec
// TranslationCount is a Prometheus metric with semantics defined by its help string in NewCtrlFuncMetrics().
TranslationCount *prometheus.CounterVec
// ConfigPushDuration is a Prometheus metric with semantics defined by its help string in NewCtrlFuncMetrics().
ConfigPushDuration *prometheus.HistogramVec
}
const (
// SuccessTrue indicates that the operation was successful.
SuccessTrue string = "true"
// SuccessTrue indicates that the operation was not successful.
SuccessFalse string = "false"
// SuccessKey defines the key of the metric label indicating success/failure of an operation.
SuccessKey string = "success"
)
const (
// ProtocolDBLess indicates that configuration was sent to Kong using the DB-less protocol (POST /config).
ProtocolDBLess string = "db-less"
// ProtocolDeck indicates that configuration was sent to Kong using the DB mode protocol (deck sync).
ProtocolDeck string = "deck"
// ProtocolKey defines the key of the metric label indicating which protocol KIC used to configure Kong.
ProtocolKey string = "protocol"
)
const (
MetricNameConfigPushCount = "ingress_controller_configuration_push_count"
MetricNameTranslationCount = "ingress_controller_translation_count"
MetricNameConfigPushDuration = "ingress_controller_configuration_push_duration_milliseconds"
)
func NewCtrlFuncMetrics() *CtrlFuncMetrics {
controllerMetrics := &CtrlFuncMetrics{}
controllerMetrics.ConfigPushCount =
prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: MetricNameConfigPushCount,
Help: "Count of successful/failed configuration pushes to Kong. `" +
ProtocolKey + "` describes the configuration protocol (" + ProtocolDBLess + " or " +
ProtocolDeck + ") in use. `" +
SuccessKey + "` describes whether there were unrecoverable errors (`" +
SuccessFalse + "`) or not (`" + SuccessTrue + "`).",
},
[]string{SuccessKey, ProtocolKey},
)
controllerMetrics.TranslationCount =
prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: MetricNameTranslationCount,
Help: "Count of translations from Kubernetes state to Kong state. `" +
SuccessKey + "` describes whether there were unrecoverable errors (`" +
SuccessFalse + "`) or not (`" + SuccessTrue + "`).",
},
[]string{SuccessKey},
)
controllerMetrics.ConfigPushDuration =
prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: MetricNameConfigPushDuration,
Help: "How long it took to push the configuration to Kong, in milliseconds. `" +
ProtocolKey + "` describes the configuration protocol (" + ProtocolDBLess + " or " +
ProtocolDeck + ") in use. `" +
SuccessKey + "` describes whether there were unrecoverable errors (`" +
SuccessFalse + "`) or not (`" + SuccessTrue + "`).",
Buckets: prometheus.ExponentialBuckets(100, 1.33, 30),
},
[]string{SuccessKey, ProtocolKey},
)
metrics.Registry.MustRegister(controllerMetrics.ConfigPushCount, controllerMetrics.TranslationCount, controllerMetrics.ConfigPushDuration)
return controllerMetrics
}