...
1
16
17 package monitor
18
19 import (
20 "time"
21
22 v2 "k8s.io/api/autoscaling/v2"
23 )
24
25 type ActionLabel string
26 type ErrorLabel string
27
28 const (
29 ActionLabelScaleUp ActionLabel = "scale_up"
30 ActionLabelScaleDown ActionLabel = "scale_down"
31 ActionLabelNone ActionLabel = "none"
32
33
34 ErrorLabelSpec ErrorLabel = "spec"
35
36 ErrorLabelInternal ErrorLabel = "internal"
37 ErrorLabelNone ErrorLabel = "none"
38 )
39
40
41 type Monitor interface {
42 ObserveReconciliationResult(action ActionLabel, err ErrorLabel, duration time.Duration)
43 ObserveMetricComputationResult(action ActionLabel, err ErrorLabel, duration time.Duration, metricType v2.MetricSourceType)
44 }
45
46 type monitor struct{}
47
48 func New() Monitor {
49 return &monitor{}
50 }
51
52
53 func (r *monitor) ObserveReconciliationResult(action ActionLabel, err ErrorLabel, duration time.Duration) {
54 reconciliationsTotal.WithLabelValues(string(action), string(err)).Inc()
55 reconciliationsDuration.WithLabelValues(string(action), string(err)).Observe(duration.Seconds())
56 }
57
58
59 func (r *monitor) ObserveMetricComputationResult(action ActionLabel, err ErrorLabel, duration time.Duration, metricType v2.MetricSourceType) {
60 metricComputationTotal.WithLabelValues(string(action), string(err), string(metricType)).Inc()
61 metricComputationDuration.WithLabelValues(string(action), string(err), string(metricType)).Observe(duration.Seconds())
62 }
63
View as plain text