Skip to content

Commit 10277d3

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

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-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

+2
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.
@@ -47,6 +48,7 @@ type AdoptionReconciler struct {
4748

4849
// SetupWithManager adds the operator reconciler to the given controller manager.
4950
func (r *AdoptionReconciler) SetupWithManager(mgr ctrl.Manager) error {
51+
metrics.EmitAdoptionReconcile()
5052
// Trigger operator events from the events of their compoenents.
5153
enqueueSub := handler.EnqueueRequestsFromMapFunc(r.mapToSubscriptions)
5254

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

+52
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,12 @@ const (
2729
APPROVAL_LABEL = "approval"
2830
WARNING_LABEL = "warning"
2931
GVK_LABEL = "gvk"
32+
33+
// Controller names
34+
operatorController = "operator"
35+
adoptionController = "adoption"
36+
operatorConditionController = "operator_condition"
37+
operatorConditionGeneratorController = "operator_condition_generator"
3038
)
3139

3240
type MetricsProvider interface {
@@ -199,13 +207,31 @@ var (
199207
Help: "monotonic count of resources that generated warnings when applied as part of an InstallPlan (for example, due to deprecation)",
200208
},
201209
)
210+
reconcileMetrics = reconcileCounters(operatorController, adoptionController, operatorConditionController, operatorConditionGeneratorController)
202211

203212
// subscriptionSyncCounters keeps a record of the promethues counters emitted by
204213
// Subscription objects. The key of a record is the Subscription name, while the value
205214
// is struct containing label values used in the counter
206215
subscriptionSyncCounters = make(map[string]subscriptionSyncLabelValues)
207216
)
208217

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+
209235
type subscriptionSyncLabelValues struct {
210236
installedCSV string
211237
pkg string
@@ -230,6 +256,12 @@ func RegisterCatalog() {
230256
prometheus.MustRegister(installPlanWarningCount)
231257
}
232258

259+
func RegisterReconcileMetrics() {
260+
for _, v := range reconcileMetrics {
261+
prometheus.MustRegister(v)
262+
}
263+
}
264+
233265
func CounterForSubscription(name, installedCSV, channelName, packageName, planApprovalStrategy string) prometheus.Counter {
234266
return SubscriptionSyncCount.WithLabelValues(name, installedCSV, channelName, packageName, planApprovalStrategy)
235267
}
@@ -334,3 +366,23 @@ func RegisterDependencyResolutionFailure(duration time.Duration) {
334366
func EmitInstallPlanWarning() {
335367
installPlanWarningCount.Inc()
336368
}
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

Comments
 (0)