@@ -20,6 +20,7 @@ import (
20
20
"time"
21
21
22
22
"github.com/prometheus/client_golang/prometheus"
23
+ "github.com/prometheus/client_golang/prometheus/collectors"
23
24
"k8s.io/klog/v2"
24
25
"sigs.k8s.io/controller-runtime/pkg/metrics"
25
26
)
@@ -55,10 +56,11 @@ var (
55
56
},
56
57
)
57
58
59
+ // Deprecated: use the more common ControllerRuntimeReconcileTime instead
58
60
reconcileFederatedResourcesDuration = prometheus .NewHistogram (
59
61
prometheus.HistogramOpts {
60
62
Name : "reconcile_federated_resources_duration_seconds" ,
61
- Help : "Time taken to reconcile federated resources in the target clusters." ,
63
+ Help : "[Deprecated] Time taken to reconcile federated resources in the target clusters." ,
62
64
Buckets : []float64 {0.01 , 0.05 , 0.1 , 0.5 , 1.0 , 2.5 , 5.0 , 7.5 , 10.0 , 12.5 , 15.0 , 17.5 , 20.0 , 22.5 , 25.0 , 27.5 , 30.0 , 50.0 , 75.0 , 100.0 , 1000.0 },
63
65
},
64
66
)
@@ -87,21 +89,50 @@ var (
87
89
}, []string {"action" },
88
90
)
89
91
92
+ // Deprecated: use the more common ControllerRuntimeReconcileTime instead
90
93
controllerRuntimeReconcileDuration = prometheus .NewHistogramVec (
91
94
prometheus.HistogramOpts {
92
95
Name : "controller_runtime_reconcile_duration_seconds" ,
93
- Help : "Time taken by various parts of Kubefed controllers reconciliation loops." ,
96
+ Help : "[Deprecated] Time taken by various parts of Kubefed controllers reconciliation loops." ,
94
97
Buckets : []float64 {0.01 , 0.05 , 0.1 , 0.5 , 1.0 , 2.5 , 5.0 , 7.5 , 10.0 , 12.5 , 15.0 , 17.5 , 20.0 , 22.5 , 25.0 , 27.5 , 30.0 , 50.0 , 75.0 , 100.0 , 1000.0 },
95
98
}, []string {"controller" },
96
99
)
97
100
101
+ // Deprecated: use the more common ControllerRuntimeReconcileTime instead
98
102
controllerRuntimeReconcileDurationSummary = prometheus .NewSummaryVec (
99
103
prometheus.SummaryOpts {
100
104
Name : "controller_runtime_reconcile_quantile_seconds" ,
101
- Help : "Quantiles of time taken by various parts of Kubefed controllers reconciliation loops." ,
105
+ Help : "[Deprecated] Quantiles of time taken by various parts of Kubefed controllers reconciliation loops." ,
102
106
MaxAge : time .Hour ,
103
107
}, []string {"controller" },
104
108
)
109
+
110
+ ControllerRuntimeReconcileTotal = prometheus .NewCounterVec (prometheus.CounterOpts {
111
+ Name : "controller_runtime_reconcile_total" ,
112
+ Help : "Total number of reconciliations per controller" ,
113
+ }, []string {"controller" , "result" })
114
+
115
+ ControllerRuntimeReconcileErrors = prometheus .NewCounterVec (prometheus.CounterOpts {
116
+ Name : "controller_runtime_reconcile_errors_total" ,
117
+ Help : "Total number of reconciliation errors per controller" ,
118
+ }, []string {"controller" })
119
+
120
+ ControllerRuntimeReconcileTime = prometheus .NewHistogramVec (prometheus.HistogramOpts {
121
+ Name : "controller_runtime_reconcile_time_seconds" ,
122
+ Help : "Length of time per reconciliation per controller" ,
123
+ Buckets : []float64 {0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.15 , 0.2 , 0.25 , 0.3 , 0.35 , 0.4 , 0.45 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 , 1.0 ,
124
+ 1.25 , 1.5 , 1.75 , 2.0 , 2.5 , 3.0 , 3.5 , 4.0 , 4.5 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 20 , 25 , 30 , 40 , 50 , 60 },
125
+ }, []string {"controller" })
126
+
127
+ ControllerRuntimeWorkerCount = prometheus .NewGaugeVec (prometheus.GaugeOpts {
128
+ Name : "controller_runtime_max_concurrent_reconciles" ,
129
+ Help : "Maximum number of concurrent reconciles per controller" ,
130
+ }, []string {"controller" })
131
+
132
+ ControllerRuntimeActiveWorkers = prometheus .NewGaugeVec (prometheus.GaugeOpts {
133
+ Name : "controller_runtime_active_workers" ,
134
+ Help : "Number of currently used workers per controller" ,
135
+ }, []string {"controller" })
105
136
)
106
137
107
138
const (
@@ -117,6 +148,10 @@ const (
117
148
// RegisterAll registers all metrics.
118
149
func RegisterAll () {
119
150
metrics .Registry .MustRegister (
151
+ // expose process metrics like CPU, Memory, file descriptor usage etc.
152
+ collectors .NewProcessCollector (collectors.ProcessCollectorOpts {}),
153
+ // expose Go runtime metrics like GC stats, memory stats etc.
154
+ collectors .NewGoCollector (),
120
155
kubefedClusterTotal ,
121
156
joinedClusterTotal ,
122
157
reconcileFederatedResourcesDuration ,
@@ -127,6 +162,11 @@ func RegisterAll() {
127
162
dispatchOperationDuration ,
128
163
controllerRuntimeReconcileDuration ,
129
164
controllerRuntimeReconcileDurationSummary ,
165
+ ControllerRuntimeReconcileTotal ,
166
+ ControllerRuntimeReconcileErrors ,
167
+ ControllerRuntimeReconcileTime ,
168
+ ControllerRuntimeWorkerCount ,
169
+ ControllerRuntimeActiveWorkers ,
130
170
)
131
171
}
132
172
@@ -188,25 +228,38 @@ func UnjoinedClusterDurationFromStart(start time.Time) {
188
228
unjoinedClusterDuration .Observe (duration .Seconds ())
189
229
}
190
230
231
+ // Deprecated: use the more common UpdateControllerRuntimeReconcileTimeFromStart instead
191
232
// ReconcileFederatedResourcesDurationFromStart records the duration of the federation of resources
192
233
func ReconcileFederatedResourcesDurationFromStart (start time.Time ) {
193
234
duration := time .Since (start )
194
235
reconcileFederatedResourcesDuration .Observe (duration .Seconds ())
195
236
}
196
237
238
+ // Deprecated: use the more common UpdateControllerRuntimeReconcileTimeFromStart instead
197
239
// UpdateControllerReconcileDurationFromStart records the duration of the reconcile loop
198
240
// of a controller
199
241
func UpdateControllerReconcileDurationFromStart (controller string , start time.Time ) {
200
242
duration := time .Since (start )
201
243
UpdateControllerReconcileDuration (controller , duration )
202
244
}
203
245
246
+ // Deprecated: use the more common UpdateControllerRuntimeReconcileTime instead
204
247
// UpdateControllerReconcileDuration records the duration of the reconcile function of a controller
205
248
func UpdateControllerReconcileDuration (controller string , duration time.Duration ) {
249
+ controllerRuntimeReconcileDurationSummary .WithLabelValues (controller ).Observe (duration .Seconds ())
250
+ controllerRuntimeReconcileDuration .WithLabelValues (controller ).Observe (duration .Seconds ())
251
+ }
252
+
253
+ // UpdateControllerRuntimeReconcileTimeFromStart records the duration of the reconcile loop of a controller
254
+ func UpdateControllerRuntimeReconcileTimeFromStart (controller string , start time.Time ) {
255
+ duration := time .Since (start )
256
+ UpdateControllerRuntimeReconcileTime (controller , duration )
257
+ }
258
+
259
+ // UpdateControllerRuntimeReconcileTime records the duration of the reconcile function of a controller
260
+ func UpdateControllerRuntimeReconcileTime (controller string , duration time.Duration ) {
206
261
if duration > LogReconcileLongDurationThreshold {
207
262
klog .V (4 ).Infof ("Reconcile loop %s took %v to complete" , controller , duration )
208
263
}
209
-
210
- controllerRuntimeReconcileDurationSummary .WithLabelValues (controller ).Observe (duration .Seconds ())
211
- controllerRuntimeReconcileDuration .WithLabelValues (controller ).Observe (duration .Seconds ())
264
+ ControllerRuntimeReconcileTime .WithLabelValues (controller ).Observe (duration .Seconds ())
212
265
}
0 commit comments