Skip to content

Commit 2fb92a2

Browse files
committed
Address comments
1 parent 41d0002 commit 2fb92a2

8 files changed

+51
-47
lines changed

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ build-coverage: clean $(CMDS)
8585

8686
build-linux: build_cmd=build
8787
build-linux: arch_flags=GOOS=linux GOARCH=386
88-
build-linux: BUILD_TAGS="json1 experimental_metrics"
8988
build-linux: clean $(CMDS)
9089

9190
build-wait: clean bin/wait

pkg/controller/operators/adoption_controller.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (r *AdoptionReconciler) ReconcileSubscription(ctx context.Context, req ctrl
115115
// Set up a convenient log object so we don't have to type request over and over again
116116
log := r.log.WithValues("request", req)
117117
log.V(1).Info("reconciling subscription")
118-
metrics.EmitAdoptionSubscriptionReconcile()
118+
metrics.EmitAdoptionSubscriptionReconcile(req.Namespace, req.Name)
119119

120120
// Fetch the Subscription from the cache
121121
in := &operatorsv1alpha1.Subscription{}
@@ -178,8 +178,7 @@ func (r *AdoptionReconciler) ReconcileClusterServiceVersion(ctx context.Context,
178178
// Set up a convenient log object so we don't have to type request over and over again
179179
log := r.log.WithValues("request", req)
180180
log.V(1).Info("reconciling csv")
181-
182-
metrics.EmitAdoptionCSVReconcile()
181+
metrics.EmitAdoptionCSVReconcile(req.Namespace, req.Name)
183182

184183
// Fetch the CSV from the cache
185184
in := &operatorsv1alpha1.ClusterServiceVersion{}

pkg/controller/operators/operator_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ func NewOperatorReconciler(cli client.Client, log logr.Logger, scheme *runtime.S
116116
var _ reconcile.Reconciler = &OperatorReconciler{}
117117

118118
func (r *OperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
119-
metrics.EmitOperatorReconcile()
120119
// Set up a convenient log object so we don't have to type request over and over again
121120
log := r.log.WithValues("request", req)
122121
log.V(1).Info("reconciling operator")
122+
metrics.EmitOperatorReconcile(req.Namespace, req.Name)
123123

124124
// Get the Operator
125125
create := false

pkg/controller/operators/operatorcondition_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ func NewOperatorConditionReconciler(cli client.Client, log logr.Logger, scheme *
9292
var _ reconcile.Reconciler = &OperatorConditionReconciler{}
9393

9494
func (r *OperatorConditionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
95-
metrics.EmitOperatorConditionReconcile()
9695
// Set up a convenient log object so we don't have to type request over and over again
9796
log := r.log.WithValues("request", req)
9897
log.V(2).Info("reconciling operatorcondition")
98+
metrics.EmitOperatorConditionReconcile(req.Namespace, req.Name)
9999

100100
operatorCondition := &operatorsv2.OperatorCondition{}
101101
err := r.Client.Get(context.TODO(), req.NamespacedName, operatorCondition)

pkg/controller/operators/operatorconditiongenerator_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ func NewOperatorConditionGeneratorReconciler(cli client.Client, log logr.Logger,
8989
var _ reconcile.Reconciler = &OperatorConditionGeneratorReconciler{}
9090

9191
func (r *OperatorConditionGeneratorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
92-
metrics.EmitOperatorConditionGeneratorReconcile()
9392
// Set up a convenient log object so we don't have to type request over and over again
9493
log := r.log.WithValues("request", req)
94+
metrics.EmitOperatorConditionGeneratorReconcile(req.Namespace, req.Name)
9595

9696
in := &operatorsv1alpha1.ClusterServiceVersion{}
9797
err := r.Client.Get(context.TODO(), req.NamespacedName, in)
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package metrics
2+
3+
import "github.com/prometheus/client_golang/prometheus"
4+
5+
const (
6+
// Controller names
7+
operatorController = "operator"
8+
adoptionCSVController = "adoption_csv"
9+
adoptionSubscriptionController = "adoption_subscription"
10+
operatorConditionController = "operator_condition"
11+
operatorConditionGeneratorController = "operator_condition_generator"
12+
)
13+
14+
var (
15+
reconcileMetrics = map[string]prometheus.CounterVec{}
16+
)
17+
18+
func EmitOperatorReconcile(namespace, name string) {
19+
emitReconcile(operatorConditionController, namespace, name)
20+
}
21+
22+
func EmitAdoptionCSVReconcile(namespace, name string) {
23+
emitReconcile(adoptionCSVController, namespace, name)
24+
}
25+
26+
func EmitAdoptionSubscriptionReconcile(namespace, name string) {
27+
emitReconcile(adoptionSubscriptionController, namespace, name)
28+
}
29+
30+
func EmitOperatorConditionReconcile(namespace, name string) {
31+
emitReconcile(operatorConditionController, namespace, name)
32+
}
33+
34+
func EmitOperatorConditionGeneratorReconcile(namespace, name string) {
35+
emitReconcile(operatorConditionGeneratorController, namespace, name)
36+
}
37+
38+
func emitReconcile(controllerName, namespace, name string) {
39+
if counter, ok := reconcileMetrics[name]; ok {
40+
counter.WithLabelValues(namespace, name).Inc()
41+
}
42+
}

pkg/metrics/experimental.go pkg/metrics/experimental_register.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ func init() {
1313
// Register experimental metrics
1414
reconcileMetrics = reconcileCounters(operatorController, adoptionCSVController, adoptionSubscriptionController, operatorConditionController, operatorConditionGeneratorController)
1515
registerReconcileMetrics()
16-
fmt.Printf("metrics")
1716
}
1817

19-
func reconcileCounters(reconcilerNames ...string) map[string]prometheus.Counter {
18+
func reconcileCounters(reconcilerNames ...string) map[string]prometheus.CounterVec {
2019
result := map[string]prometheus.Counter{}
2120
for _, s := range reconcilerNames {
2221
result[s] = reconcileCounter(s)
2322
}
2423
return result
2524
}
2625

27-
func reconcileCounter(name string) prometheus.Counter {
28-
return prometheus.NewCounter(
26+
func reconcileCounter(name string) prometheus.CounterVec {
27+
return prometheus.NewCounterVec(
2928
prometheus.CounterOpts{
3029
Name: "controller_reconcile_" + name,
3130
Help: fmt.Sprintf("Count of reconcile events by the %s controller", strings.Replace(name, "_", " ", -1)),
3231
},
32+
[]string{NAMESPACE_LABEL, NAME_LABEL},
3333
)
3434
}
3535

pkg/metrics/metrics.go

-36
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ const (
2727
APPROVAL_LABEL = "approval"
2828
WARNING_LABEL = "warning"
2929
GVK_LABEL = "gvk"
30-
31-
// Controller names
32-
operatorController = "operator"
33-
adoptionCSVController = "adoption_csv"
34-
adoptionSubscriptionController = "adoption_subscription"
35-
operatorConditionController = "operator_condition"
36-
operatorConditionGeneratorController = "operator_condition_generator"
3730
)
3831

3932
type MetricsProvider interface {
@@ -211,9 +204,6 @@ var (
211204
// Subscription objects. The key of a record is the Subscription name, while the value
212205
// is struct containing label values used in the counter
213206
subscriptionSyncCounters = make(map[string]subscriptionSyncLabelValues)
214-
215-
// Experimental Metrics
216-
reconcileMetrics = map[string]prometheus.Counter{}
217207
)
218208

219209
type subscriptionSyncLabelValues struct {
@@ -344,29 +334,3 @@ func RegisterDependencyResolutionFailure(duration time.Duration) {
344334
func EmitInstallPlanWarning() {
345335
installPlanWarningCount.Inc()
346336
}
347-
348-
func EmitOperatorReconcile() {
349-
emitReconcile(operatorConditionController)
350-
}
351-
352-
func EmitAdoptionCSVReconcile() {
353-
emitReconcile(adoptionCSVController)
354-
}
355-
356-
func EmitAdoptionSubscriptionReconcile() {
357-
emitReconcile(adoptionSubscriptionController)
358-
}
359-
360-
func EmitOperatorConditionReconcile() {
361-
emitReconcile(operatorConditionController)
362-
}
363-
364-
func EmitOperatorConditionGeneratorReconcile() {
365-
emitReconcile(operatorConditionGeneratorController)
366-
}
367-
368-
func emitReconcile(name string) {
369-
if counter, ok := reconcileMetrics[name]; ok {
370-
counter.Inc()
371-
}
372-
}

0 commit comments

Comments
 (0)