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