-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Experimental Metrics (#2435)
This commit introduces a series of metrics that are only recorded when OLM is built with the experimental_metrics build tag. The metrics introduced in this commit includes namespace/name information of the request being reconciled by a series of controllers. These experimental metrics are enabled by default in the e2e-local target defined in the project's Makefile. Signed-off-by: Alexander Greene <greene.al1991@gmail.com>
- Loading branch information
Showing
7 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package metrics | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
const ( | ||
// Controller names | ||
operatorController = "operator" | ||
adoptionCSVController = "adoption_csv" | ||
adoptionSubscriptionController = "adoption_subscription" | ||
operatorConditionController = "operator_condition" | ||
operatorConditionGeneratorController = "operator_condition_generator" | ||
) | ||
|
||
var ( | ||
reconcileMetrics = map[string]*prometheus.CounterVec{} | ||
) | ||
|
||
func EmitOperatorReconcile(namespace, name string) { | ||
emitReconcile(operatorController, namespace, name) | ||
} | ||
|
||
func EmitAdoptionCSVReconcile(namespace, name string) { | ||
emitReconcile(adoptionCSVController, namespace, name) | ||
} | ||
|
||
func EmitAdoptionSubscriptionReconcile(namespace, name string) { | ||
emitReconcile(adoptionSubscriptionController, namespace, name) | ||
} | ||
|
||
func EmitOperatorConditionReconcile(namespace, name string) { | ||
emitReconcile(operatorConditionController, namespace, name) | ||
} | ||
|
||
func EmitOperatorConditionGeneratorReconcile(namespace, name string) { | ||
emitReconcile(operatorConditionGeneratorController, namespace, name) | ||
} | ||
|
||
func emitReconcile(controllerName, namespace, name string) { | ||
if counter, ok := reconcileMetrics[controllerName]; ok { | ||
counter.WithLabelValues(namespace, name).Inc() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//go:build experimental_metrics | ||
// +build experimental_metrics | ||
|
||
package metrics | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func init() { | ||
// Register experimental metrics | ||
reconcileMetrics = reconcileCounters(operatorController, adoptionCSVController, adoptionSubscriptionController, operatorConditionController, operatorConditionGeneratorController) | ||
registerReconcileMetrics() | ||
} | ||
|
||
func reconcileCounters(reconcilerNames ...string) map[string]*prometheus.CounterVec { | ||
result := map[string]*prometheus.CounterVec{} | ||
for _, s := range reconcilerNames { | ||
result[s] = createReconcileCounterVec(s) | ||
} | ||
return result | ||
} | ||
|
||
func createReconcileCounterVec(name string) *prometheus.CounterVec { | ||
return prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "controller_reconcile_" + name, | ||
Help: fmt.Sprintf("Count of reconcile events by the %s controller", strings.Replace(name, "_", " ", -1)), | ||
}, | ||
[]string{NamespaceLabel, NameLabel}, | ||
) | ||
} | ||
|
||
func registerReconcileMetrics() { | ||
for _, v := range reconcileMetrics { | ||
prometheus.MustRegister(v) | ||
} | ||
} |