Skip to content

Commit eac4737

Browse files
committed
WIP: add reconcile metrics
Signed-off-by: Alexander Greene <[email protected]>
1 parent 58c8485 commit eac4737

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

cmd/olm/manager.go

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
1717
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators"
1818
"github.com/operator-framework/operator-lifecycle-manager/pkg/feature"
19+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
1920
)
2021

2122
var (
@@ -28,6 +29,9 @@ func init() {
2829
panic(err)
2930
}
3031
copiedLabelDoesNotExist = labels.NewSelector().Add(*requirement)
32+
33+
// Register metrics
34+
metrics.RegisterReconcileMetrics()
3135
}
3236

3337
func Manager(ctx context.Context, debug bool) (ctrl.Manager, error) {

pkg/controller/operators/adoption_controller.go

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
3131
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/decorators"
3232
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
33+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
3334
)
3435

3536
// AdoptionReconciler automagically associates Operator components with their respective operator resource.
@@ -114,6 +115,7 @@ func (r *AdoptionReconciler) ReconcileSubscription(ctx context.Context, req ctrl
114115
// Set up a convenient log object so we don't have to type request over and over again
115116
log := r.log.WithValues("request", req)
116117
log.V(1).Info("reconciling subscription")
118+
metrics.EmitAdoptionSubscriptionReconcile()
117119

118120
// Fetch the Subscription from the cache
119121
in := &operatorsv1alpha1.Subscription{}
@@ -177,6 +179,8 @@ func (r *AdoptionReconciler) ReconcileClusterServiceVersion(ctx context.Context,
177179
log := r.log.WithValues("request", req)
178180
log.V(1).Info("reconciling csv")
179181

182+
metrics.EmitAdoptionCSVReconcile()
183+
180184
// Fetch the CSV from the cache
181185
in := &operatorsv1alpha1.ClusterServiceVersion{}
182186
if err := r.Get(ctx, req.NamespacedName, in); err != nil {

pkg/controller/operators/operator_controller.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
2929
operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
3030
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/decorators"
31+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
3132
)
3233

3334
var (
@@ -115,6 +116,7 @@ func NewOperatorReconciler(cli client.Client, log logr.Logger, scheme *runtime.S
115116
var _ reconcile.Reconciler = &OperatorReconciler{}
116117

117118
func (r *OperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
119+
metrics.EmitOperatorReconcile()
118120
// Set up a convenient log object so we don't have to type request over and over again
119121
log := r.log.WithValues("request", req)
120122
log.V(1).Info("reconciling operator")

pkg/controller/operators/operatorcondition_controller.go

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
2323
operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
2424
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
25+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
2526
)
2627

2728
const (
@@ -91,6 +92,7 @@ func NewOperatorConditionReconciler(cli client.Client, log logr.Logger, scheme *
9192
var _ reconcile.Reconciler = &OperatorConditionReconciler{}
9293

9394
func (r *OperatorConditionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
95+
metrics.EmitOperatorConditionReconcile()
9496
// Set up a convenient log object so we don't have to type request over and over again
9597
log := r.log.WithValues("request", req)
9698
log.V(2).Info("reconciling operatorcondition")

pkg/controller/operators/operatorconditiongenerator_controller.go

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
2121
operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
2222
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
23+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
2324
)
2425

2526
// OperatorConditionGeneratorReconciler reconciles a ClusterServiceVersion object and creates an OperatorCondition.
@@ -88,6 +89,7 @@ func NewOperatorConditionGeneratorReconciler(cli client.Client, log logr.Logger,
8889
var _ reconcile.Reconciler = &OperatorConditionGeneratorReconciler{}
8990

9091
func (r *OperatorConditionGeneratorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
92+
metrics.EmitOperatorConditionGeneratorReconcile()
9193
// Set up a convenient log object so we don't have to type request over and over again
9294
log := r.log.WithValues("request", req)
9395

pkg/metrics/metrics.go

+59
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package metrics
22

33
import (
4+
"fmt"
5+
"strings"
46
"time"
57

68
"github.com/prometheus/client_golang/prometheus"
@@ -27,6 +29,13 @@ const (
2729
APPROVAL_LABEL = "approval"
2830
WARNING_LABEL = "warning"
2931
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"
3039
)
3140

3241
type MetricsProvider interface {
@@ -199,13 +208,31 @@ var (
199208
Help: "monotonic count of resources that generated warnings when applied as part of an InstallPlan (for example, due to deprecation)",
200209
},
201210
)
211+
reconcileMetrics = reconcileCounters(operatorController, adoptionCSVController, adoptionSubscriptionController, operatorConditionController, operatorConditionGeneratorController)
202212

203213
// subscriptionSyncCounters keeps a record of the promethues counters emitted by
204214
// Subscription objects. The key of a record is the Subscription name, while the value
205215
// is struct containing label values used in the counter
206216
subscriptionSyncCounters = make(map[string]subscriptionSyncLabelValues)
207217
)
208218

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+
209236
type subscriptionSyncLabelValues struct {
210237
installedCSV string
211238
pkg string
@@ -230,6 +257,12 @@ func RegisterCatalog() {
230257
prometheus.MustRegister(installPlanWarningCount)
231258
}
232259

260+
func RegisterReconcileMetrics() {
261+
for _, v := range reconcileMetrics {
262+
prometheus.MustRegister(v)
263+
}
264+
}
265+
233266
func CounterForSubscription(name, installedCSV, channelName, packageName, planApprovalStrategy string) prometheus.Counter {
234267
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName, packageName, planApprovalStrategy)
235268
}
@@ -334,3 +367,29 @@ func RegisterDependencyResolutionFailure(duration time.Duration) {
334367
func EmitInstallPlanWarning() {
335368
installPlanWarningCount.Inc()
336369
}
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

Comments
 (0)