Skip to content

⚠️ Make all metrics opt-in #1589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
63 changes: 41 additions & 22 deletions pkg/metrics/client_go_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,53 @@ var (
}, []string{"name"})
)

func init() {
registerClientMetrics()
registerReflectorMetrics()
}
// RegisterClientMetrics sets up the client latency metrics from client-go.
// To opt *out* of specific metrics, specify their *Key consts to optOut.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realistically this is lousy UX without a better indication that the varargs are opt out rather than in. It would probably be better to flip it.

func RegisterClientMetrics(optOut ...string) {
toRegister := map[string]bool{
LatencyKey: true,
ResultKey: true,
}
for _, k := range optOut {
toRegister[k] = false
}
registerOpts := clientmetrics.RegisterOpts{}

// registerClientMetrics sets up the client latency metrics from client-go.
func registerClientMetrics() {
// register the metrics with our registry
Registry.MustRegister(requestLatency)
Registry.MustRegister(requestResult)
if toRegister[LatencyKey] {
Registry.MustRegister(requestLatency)
registerOpts.RequestLatency = &latencyAdapter{metric: requestLatency}
}
if toRegister[ResultKey] {
Registry.MustRegister(requestResult)
registerOpts.RequestResult = &resultAdapter{metric: requestResult}
}

// register the metrics with client-go
clientmetrics.Register(clientmetrics.RegisterOpts{
RequestLatency: &latencyAdapter{metric: requestLatency},
RequestResult: &resultAdapter{metric: requestResult},
})
clientmetrics.Register(registerOpts)
}

// registerReflectorMetrics sets up reflector (reconcile) loop metrics.
func registerReflectorMetrics() {
Registry.MustRegister(listsTotal)
Registry.MustRegister(listsDuration)
Registry.MustRegister(itemsPerList)
Registry.MustRegister(watchesTotal)
Registry.MustRegister(shortWatchesTotal)
Registry.MustRegister(watchDuration)
Registry.MustRegister(itemsPerWatch)
Registry.MustRegister(lastResourceVersion)
// RegisterReflectorMetrics sets up reflector (reconcile) loop metrics.
// To opt *out* of specific metrics, specify their *Key consts to optOut.
func RegisterReflectorMetrics(optOut ...string) {
toRegister := map[string]prometheus.Collector{
ListsTotalKey: listsTotal,
ListsDurationKey: listsDuration,
ItemsPerListKey: itemsPerList,
WatchesTotalKey: watchesTotal,
ShortWatchesTotalKey: shortWatchesTotal,
WatchDurationKey: watchDuration,
ItemsPerWatchKey: itemsPerWatch,
LastResourceVersionKey: lastResourceVersion,
}
for _, k := range optOut {
toRegister[k] = nil
}
for _, v := range toRegister {
if v != nil {
Registry.MustRegister(v)
}
}

reflectormetrics.SetReflectorMetricsProvider(reflectorMetricsProvider{})
}
Expand Down