Skip to content

Commit 70e1503

Browse files
committed
removes klusters and ids from metrics
1 parent 71ad347 commit 70e1503

File tree

5 files changed

+184
-24
lines changed

5 files changed

+184
-24
lines changed

pkg/controller/base/instrumenting.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,36 @@ import (
99

1010
type InstrumentingReconciler struct {
1111
Reconciler
12-
ReconciliationCount *prometheus.CounterVec
13-
ReconciliationLatency *prometheus.SummaryVec
12+
13+
Latency *prometheus.SummaryVec
14+
Total *prometheus.CounterVec
15+
Successful *prometheus.CounterVec
16+
Failed *prometheus.CounterVec
1417
}
1518

1619
func (ir *InstrumentingReconciler) Reconcile(kluster *v1.Kluster) (requeue bool, err error) {
1720
defer func(begin time.Time) {
18-
ir.ReconciliationCount.With(
19-
prometheus.Labels{
20-
"kluster": kluster.Spec.Name,
21-
"project": kluster.Account(),
22-
}).Add(1)
23-
ir.ReconciliationLatency.With(
21+
ir.Latency.With(
2422
prometheus.Labels{
25-
"kluster": kluster.Spec.Name,
26-
"project": kluster.Account(),
23+
"method": "Reconcile",
2724
}).Observe(time.Since(begin).Seconds())
25+
26+
ir.Total.With(
27+
prometheus.Labels{
28+
"method": "Reconcile",
29+
}).Add(1)
30+
31+
if err != nil {
32+
ir.Failed.With(
33+
prometheus.Labels{
34+
"method": "Reconcile",
35+
}).Add(1)
36+
} else {
37+
ir.Successful.With(
38+
prometheus.Labels{
39+
"method": "Reconcile",
40+
}).Add(1)
41+
}
2842
}(time.Now())
2943
return ir.Reconciler.Reconcile(kluster)
3044
}

pkg/controller/launch/controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ func NewController(factories config.Factories, clients config.Clients, recorder
5555
reconciler = &base.EventingReconciler{reconciler}
5656
reconciler = &base.InstrumentingReconciler{
5757
reconciler,
58-
metrics.KlusterReconcilicationCount,
59-
metrics.KlusterReconciliationLatency,
58+
metrics.LaunchOperationsLatency,
59+
metrics.LaunchOperationsTotal,
60+
metrics.LaunchSuccessfulOperationsTotal,
61+
metrics.LaunchFailedOperationsTotal,
6062
}
6163

6264
return base.NewController(factories, clients, reconciler, logger)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package launch
2+
3+
import (
4+
"time"
5+
6+
"github.com/prometheus/client_golang/prometheus"
7+
)
8+
9+
type InstrumentingPoolManager struct {
10+
PoolManager PoolManager
11+
12+
Latency *prometheus.SummaryVec
13+
Total *prometheus.CounterVec
14+
Successful *prometheus.CounterVec
15+
Failed *prometheus.CounterVec
16+
}
17+
18+
func (pm *InstrumentingPoolManager) GetStatus() (status *PoolStatus, err error) {
19+
defer func(begin time.Time) {
20+
pm.Latency.With(
21+
prometheus.Labels{
22+
"method": "GetStatus",
23+
}).Observe(time.Since(begin).Seconds())
24+
25+
pm.Total.With(
26+
prometheus.Labels{
27+
"method": "GetStatus",
28+
}).Add(1)
29+
30+
if err != nil {
31+
pm.Failed.With(
32+
prometheus.Labels{
33+
"method": "GetStatus",
34+
}).Add(1)
35+
} else {
36+
pm.Successful.With(
37+
prometheus.Labels{
38+
"method": "GetStatus",
39+
}).Add(1)
40+
}
41+
}(time.Now())
42+
return pm.PoolManager.GetStatus()
43+
}
44+
45+
func (pm *InstrumentingPoolManager) SetStatus(status *PoolStatus) (err error) {
46+
defer func(begin time.Time) {
47+
pm.Latency.With(
48+
prometheus.Labels{
49+
"method": "SetStatus",
50+
}).Observe(time.Since(begin).Seconds())
51+
52+
pm.Total.With(
53+
prometheus.Labels{
54+
"method": "SetStatus",
55+
}).Add(1)
56+
57+
if err != nil {
58+
pm.Failed.With(
59+
prometheus.Labels{
60+
"method": "SetStatus",
61+
}).Add(1)
62+
} else {
63+
pm.Successful.With(
64+
prometheus.Labels{
65+
"method": "SetStatus",
66+
}).Add(1)
67+
}
68+
}(time.Now())
69+
return pm.PoolManager.SetStatus(status)
70+
}
71+
72+
func (pm *InstrumentingPoolManager) CreateNode() (id string, err error) {
73+
defer func(begin time.Time) {
74+
pm.Latency.With(
75+
prometheus.Labels{
76+
"method": "CreateNode",
77+
}).Observe(time.Since(begin).Seconds())
78+
79+
pm.Total.With(
80+
prometheus.Labels{
81+
"method": "CreateNode",
82+
}).Add(1)
83+
84+
if err != nil {
85+
pm.Failed.With(
86+
prometheus.Labels{
87+
"method": "CreateNode",
88+
}).Add(1)
89+
} else {
90+
pm.Successful.With(
91+
prometheus.Labels{
92+
"method": "CreateNode",
93+
}).Add(1)
94+
}
95+
}(time.Now())
96+
97+
return pm.PoolManager.CreateNode()
98+
}
99+
100+
func (pm *InstrumentingPoolManager) DeleteNode(id string) (err error) {
101+
defer func(begin time.Time) {
102+
pm.Latency.With(
103+
prometheus.Labels{
104+
"method": "DeleteNode",
105+
}).Observe(time.Since(begin).Seconds())
106+
107+
pm.Total.With(
108+
prometheus.Labels{
109+
"method": "DeleteNode",
110+
}).Add(1)
111+
112+
if err != nil {
113+
pm.Failed.With(
114+
prometheus.Labels{
115+
"method": "DeleteNode",
116+
}).Add(1)
117+
} else {
118+
pm.Successful.With(
119+
prometheus.Labels{
120+
"method": "DeleteNode",
121+
}).Add(1)
122+
}
123+
}(time.Now())
124+
125+
return pm.PoolManager.DeleteNode(id)
126+
}

pkg/controller/metrics/launch.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@ package metrics
22

33
import "github.com/prometheus/client_golang/prometheus"
44

5-
var KlusterReconcilicationCount = prometheus.NewCounterVec(
5+
var LaunchOperationsLatency = prometheus.NewSummaryVec(
6+
prometheus.SummaryOpts{
7+
Namespace: "kubernikus",
8+
Subsystem: "launch",
9+
Name: "operation_latency_microseconds",
10+
Help: "Total duration of reconciliation in microseconds.",
11+
},
12+
[]string{"method"})
13+
14+
var LaunchOperationsTotal = prometheus.NewCounterVec(
615
prometheus.CounterOpts{
716
Namespace: "kubernikus",
817
Subsystem: "launch",
9-
Name: "reconciliation_count",
10-
Help: "Number of reconcilitations."},
11-
[]string{"kluster", "project"})
18+
Name: "operation_total",
19+
Help: "Number of operations."},
20+
[]string{"method"})
1221

13-
var KlusterReconciliationLatency = prometheus.NewSummaryVec(
14-
prometheus.SummaryOpts{
22+
var LaunchSuccessfulOperationsTotal = prometheus.NewCounterVec(
23+
prometheus.CounterOpts{
1524
Namespace: "kubernikus",
1625
Subsystem: "launch",
17-
Name: "reconciliation_latency_microseconds",
18-
Help: "Total duration of reconciliation in microseconds.",
19-
},
20-
[]string{"kluster", "project"})
26+
Name: "successful_operation_total",
27+
Help: "Number of successful operations."},
28+
[]string{"method"})
29+
30+
var LaunchFailedOperationsTotal = prometheus.NewCounterVec(
31+
prometheus.CounterOpts{
32+
Namespace: "kubernikus",
33+
Subsystem: "launch",
34+
Name: "failed_operation_total",
35+
Help: "Number of failed operations."},
36+
[]string{"method"})

pkg/controller/metrics/metrics.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ func init() {
147147
klusterStatusPhase,
148148
nodePoolSize,
149149
nodePoolStatus,
150-
KlusterReconcilicationCount,
151-
KlusterReconciliationLatency,
150+
LaunchOperationsLatency,
151+
LaunchOperationsTotal,
152+
LaunchSuccessfulOperationsTotal,
153+
LaunchFailedOperationsTotal,
152154
)
153155
}
154156

0 commit comments

Comments
 (0)