11package metrics
22
33import (
4+ "time"
5+
46 "github.com/prometheus/client_golang/prometheus"
57
8+ "github.com/neondatabase/autoscaling/pkg/plugin/reconcile"
69 "github.com/neondatabase/autoscaling/pkg/util"
710)
811
912type Reconcile struct {
10- WaitDurations prometheus.Histogram
11- ProcessDurations * prometheus.HistogramVec
12- Failing * prometheus.GaugeVec
13- Panics * prometheus.CounterVec
13+ waitDurations prometheus.Histogram
14+ processDurations * prometheus.HistogramVec
15+ failing * prometheus.GaugeVec
16+ panics * prometheus.CounterVec
1417}
1518
1619func buildReconcileMetrics (reg prometheus.Registerer ) Reconcile {
1720 return Reconcile {
18- WaitDurations : util .RegisterMetric (reg , prometheus .NewHistogram (
21+ waitDurations : util .RegisterMetric (reg , prometheus .NewHistogram (
1922 prometheus.HistogramOpts {
2023 Name : "autoscaling_plugin_reconcile_queue_wait_durations" ,
2124 Help : "Duration that items in the reconcile queue are waiting to be picked up" ,
@@ -29,7 +32,7 @@ func buildReconcileMetrics(reg prometheus.Registerer) Reconcile {
2932 },
3033 },
3134 )),
32- ProcessDurations : util .RegisterMetric (reg , prometheus .NewHistogramVec (
35+ processDurations : util .RegisterMetric (reg , prometheus .NewHistogramVec (
3336 prometheus.HistogramOpts {
3437 Name : "autoscaling_plugin_reconcile_duration_seconds" ,
3538 Help : "Duration that items take to be reconciled" ,
@@ -44,14 +47,14 @@ func buildReconcileMetrics(reg prometheus.Registerer) Reconcile {
4447 },
4548 []string {"kind" , "outcome" },
4649 )),
47- Failing : util .RegisterMetric (reg , prometheus .NewGaugeVec (
50+ failing : util .RegisterMetric (reg , prometheus .NewGaugeVec (
4851 prometheus.GaugeOpts {
4952 Name : "autoscaling_plugin_reconcile_failing_objects" ,
5053 Help : "Number of objects currently failing to be reconciled" ,
5154 },
5255 []string {"kind" },
5356 )),
54- Panics : util .RegisterMetric (reg , prometheus .NewCounterVec (
57+ panics : util .RegisterMetric (reg , prometheus .NewCounterVec (
5558 prometheus.CounterOpts {
5659 Name : "autoscaling_plugin_reconcile_panics_count" ,
5760 Help : "Number of times reconcile operations have panicked" ,
@@ -60,3 +63,24 @@ func buildReconcileMetrics(reg prometheus.Registerer) Reconcile {
6063 )),
6164 }
6265}
66+
67+ func (r Reconcile ) QueueWaitDurationCallback (duration time.Duration ) {
68+ r .waitDurations .Observe (duration .Seconds ())
69+ }
70+
71+ func (r Reconcile ) ResultCallback (params reconcile.ObjectParams , duration time.Duration , err error ) {
72+ outcome := "success"
73+ if err != nil {
74+ outcome = "failure"
75+ }
76+ r .processDurations .WithLabelValues (params .GVK .Kind , outcome ).Observe (duration .Seconds ())
77+ }
78+
79+ func (r Reconcile ) ErrorStatsCallback (params reconcile.ObjectParams , stats reconcile.ErrorStats ) {
80+ // update count of current failing objects
81+ r .failing .WithLabelValues (params .GVK .Kind ).Set (float64 (stats .TypedCount ))
82+ }
83+
84+ func (r Reconcile ) PanicCallback (params reconcile.ObjectParams ) {
85+ r .panics .WithLabelValues (params .GVK .Kind ).Inc ()
86+ }
0 commit comments