1
1
package metrics
2
2
3
3
import (
4
+ "fmt"
5
+ "strings"
4
6
"time"
5
7
6
8
"github.com/prometheus/client_golang/prometheus"
@@ -27,6 +29,12 @@ const (
27
29
APPROVAL_LABEL = "approval"
28
30
WARNING_LABEL = "warning"
29
31
GVK_LABEL = "gvk"
32
+
33
+ // Controller names
34
+ operatorController = "operator"
35
+ adoptionController = "adoption"
36
+ operatorConditionController = "operator_condition"
37
+ operatorConditionGeneratorController = "operator_condition_generator"
30
38
)
31
39
32
40
type MetricsProvider interface {
@@ -199,13 +207,31 @@ var (
199
207
Help : "monotonic count of resources that generated warnings when applied as part of an InstallPlan (for example, due to deprecation)" ,
200
208
},
201
209
)
210
+ reconcileMetrics = reconcileCounters (operatorController , adoptionController , operatorConditionController , operatorConditionGeneratorController )
202
211
203
212
// subscriptionSyncCounters keeps a record of the promethues counters emitted by
204
213
// Subscription objects. The key of a record is the Subscription name, while the value
205
214
// is struct containing label values used in the counter
206
215
subscriptionSyncCounters = make (map [string ]subscriptionSyncLabelValues )
207
216
)
208
217
218
+ func reconcileCounters (reconcilerNames ... string ) map [string ]prometheus.Counter {
219
+ result := map [string ]prometheus.Counter {}
220
+ for _ , s := range reconcilerNames {
221
+ result [s ] = reconcileCounter (s )
222
+ }
223
+ return result
224
+ }
225
+
226
+ func reconcileCounter (name string ) prometheus.Counter {
227
+ return prometheus .NewCounter (
228
+ prometheus.CounterOpts {
229
+ Name : "controller_reconcile_" + name ,
230
+ Help : fmt .Sprintf ("Count of reconcile events by the %s controller" , strings .Replace (name , "_" , " " , - 1 )),
231
+ },
232
+ )
233
+ }
234
+
209
235
type subscriptionSyncLabelValues struct {
210
236
installedCSV string
211
237
pkg string
@@ -230,6 +256,12 @@ func RegisterCatalog() {
230
256
prometheus .MustRegister (installPlanWarningCount )
231
257
}
232
258
259
+ func RegisterReconcileMetrics () {
260
+ for _ , v := range reconcileMetrics {
261
+ prometheus .MustRegister (v )
262
+ }
263
+ }
264
+
233
265
func CounterForSubscription (name , installedCSV , channelName , packageName , planApprovalStrategy string ) prometheus.Counter {
234
266
return SubscriptionSyncCount .WithLabelValues (name , installedCSV , channelName , packageName , planApprovalStrategy )
235
267
}
@@ -334,3 +366,23 @@ func RegisterDependencyResolutionFailure(duration time.Duration) {
334
366
func EmitInstallPlanWarning () {
335
367
installPlanWarningCount .Inc ()
336
368
}
369
+
370
+ func EmitOperatorReconcile () {
371
+ emitReconcile (operatorConditionController )
372
+ }
373
+ func EmitAdoptionReconcile () {
374
+ emitReconcile (adoptionController )
375
+ }
376
+ func EmitOperatorConditionReconcile () {
377
+ emitReconcile (operatorConditionController )
378
+ }
379
+
380
+ func EmitOperatorConditionGeneratorReconcile () {
381
+ emitReconcile (operatorConditionGeneratorController )
382
+ }
383
+
384
+ func emitReconcile (name string ) {
385
+ if counter , ok := reconcileMetrics [name ]; ok {
386
+ counter .Inc ()
387
+ }
388
+ }
0 commit comments