Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/gauge_vec_set/gauge_vec_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type GaugeVecSet struct {
// Returns an *unregistered* collector; register it with a Prometheus registry yourself.
// Example:
//
// col := NewGaugeVecSet(ns, sub, "condition", help, []string{"controller","name","namespace"}, []string{"condition"}, []string{"status","reason"})
// col := NewGaugeVecSet(ns, sub, name, help, []string{"namespace"}, []string{"pod"}, []string{"phase"})
// prometheus.MustRegister(col)
func NewGaugeVecSet(
namespace, subsystem, name, help string,
Expand Down Expand Up @@ -281,7 +281,7 @@ func (c *GaugeVecSet) cacheWithKeys(indexKey, groupKey, fullKey string) {
}

// Set assigns the Gauge value for the series identified by (index, group)
// This does not modify sibling series. Use SetExclusiveInGroup or SetActiveInGroup to enforce enum-like exclusivity.
// This does not modify sibling series. Use SetGroup or SetActiveInGroup to enforce exclusivity on the group level.
func (c *GaugeVecSet) Set(
value float64,
indexValues []string,
Expand Down
36 changes: 11 additions & 25 deletions pkg/operator_condition_metrics/operator_condition_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ Implementation
groupLabels = [condition]
extraLabels = [status, reason]
Exclusivity is enforced with SetGroup(), which deletes sibling series.

Notes
- KIND: In controller-runtime, obj.GetObjectKind().GroupVersionKind().Kind can be empty if
GVK wasn't populated. Ensure your scheme is registered and objects are decoded via the client;
otherwise, resolve Kind via the scheme (scheme.ObjectKinds(obj)).
- Cluster-scoped: namespace label is set to the empty string "".
*/

const (
Expand All @@ -108,12 +102,12 @@ type OperatorConditionsGauge struct {
// NewOperatorConditionsGauge creates a new OperatorConditionsGauge for an operator.
// Initialize once (e.g., in your package init or setup)
//
// var OperatorConditionsGauge *OperatorConditionsGauge = nil
// var OperatorConditionsGauge *OperatorConditionsGauge = nil
//
// func init() {
// OperatorConditionsGauge = NewOperatorConditionsGauge("my-operator")
// controllermetrics.Registry.MustRegister(OperatorConditionsGauge)
// }
// func init() {
// OperatorConditionsGauge = NewOperatorConditionsGauge("my-operator")
// controllermetrics.Registry.MustRegister(OperatorConditionsGauge)
// }
func NewOperatorConditionsGauge(metricNamespace string) *OperatorConditionsGauge {
return &OperatorConditionsGauge{
metrics.NewGaugeVecSet(
Expand All @@ -136,27 +130,23 @@ type ObjectLike interface {
// ConditionMetricRecorder records metrics for Kubernetes style `metav1.Condition`
// objects on custom resources, using a Prometheus gauge.
//
// It is intended for use in controller implementations that expose CRD conditions
// (e.g., Ready, Reconciled, Synchronized).
//
// Usage:
//
// Embed in your custom recorder or reconciler
//
// type MyRecorder struct {
// metrics.ConditionMetricRecorder
// gvs.ConditionMetricRecorder
// }
//
// r := MyControllerRecorder{
// ConditionMetricRecorder: metrics.ConditionMetricRecorder{
// ConditionMetricRecorder: gvs.ConditionMetricRecorder{
// Controller: "my-controller",
// OperatorConditionsGauge: OperatorConditionsGauge,
// OperatorConditionsGauge: my_metrics.OperatorConditionsGauge,
// },
// }
//
// r.RecordConditionFor(myObj, condition)
// r.SetStatusCondition(myObj, &myObj.Status.Conditions, condition) // wrapper for meta.SetStatusCondition
// r.RemoveConditionsFor(myObj)
// r.RecordConditionFor(kind, obj, cond.Type, string(cond.Status), cond.Reason)
// r.RemoveConditionsFor(kind, obj)
type ConditionMetricRecorder struct {
// The name of the controller the condition metrics are for
Controller string
Expand All @@ -181,11 +171,7 @@ type ConditionMetricRecorder struct {
//
// Example:
//
// r.RecordConditionFor(obj, metav1.Condition{
// Type: "Ready",
// Status: metav1.ConditionFalse,
// Reason: "KeyAuthorizationError",
// })
// r.RecordConditionFor(kind, obj, "Ready", "True", "AppReady")
func (r *ConditionMetricRecorder) RecordConditionFor(
kind string, object ObjectLike, conditionType, conditionStatus, conditionReason string,
) {
Expand Down