Skip to content

Commit 5529baa

Browse files
author
Eric Curtin
committed
atecontroller: log the resolved metrics address, log exporters for all components
1 parent a46d59d commit 5529baa

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎cmd/atecontroller/main.go‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,20 @@ func newControllerRuntimeLogger(h slog.Handler) logr.Logger {
106106
return logr.FromSlogHandler(h)
107107
}
108108

109-
// managerOptions configures the controller-runtime manager. servePull is
110-
// whether OTEL_METRICS_EXPORTER leaves its metrics listener on.
111-
func managerOptions(egressMITMCAPool types.NamespacedName, servePull bool) ctrl.Options {
112-
metricsAddr := metricsOffAddr
109+
// metricsBindAddr is the manager's metrics address. servePull is whether
110+
// OTEL_METRICS_EXPORTER leaves the listener on.
111+
func metricsBindAddr(servePull bool) string {
113112
if servePull {
114-
metricsAddr = metricsPullAddr
113+
return metricsPullAddr
115114
}
115+
return metricsOffAddr
116+
}
117+
118+
// managerOptions configures the controller-runtime manager.
119+
func managerOptions(egressMITMCAPool types.NamespacedName, servePull bool) ctrl.Options {
116120
return ctrl.Options{
117121
Scheme: scheme,
118-
Metrics: metricsserver.Options{BindAddress: metricsAddr},
122+
Metrics: metricsserver.Options{BindAddress: metricsBindAddr(servePull)},
119123
Cache: cache.Options{
120124
ByObject: map[client.Object]cache.ByObject{
121125
&corev1.Secret{}: {
@@ -165,7 +169,7 @@ func main() {
165169
serverboot.Fatal(ctx, "Failed to initialize metrics", err)
166170
}
167171
defer serverboot.ShutdownProvider("MeterProvider", mp.Shutdown)
168-
slog.InfoContext(ctx, "Metrics listener", slog.Bool("enabled", servePull), slog.String("addr", metricsPullAddr))
172+
slog.InfoContext(ctx, "Metrics listener", slog.Bool("enabled", servePull), slog.String("addr", metricsBindAddr(servePull)))
169173

170174
k8sConfig := ctrl.GetConfigOrDie()
171175
k8sClient, err := kubernetes.NewForConfig(k8sConfig)

‎docs/observability.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ Weaver permits only `groups` and `imports` at the top level of a registry file,
321321

322322
### Bridged controller-runtime metrics (atecontroller)
323323

324-
atecontroller bridges controller-runtime's private Prometheus registry, which the manager serves on an unscraped `:8080`, onto its OTLP reader. So `controller_runtime_*`, `workqueue_*`, `certwatcher_*`, `rest_client_*`, `leader_election_*`, `go_*`, and `process_*` reach the collector too, keeping their Prometheus names because they are upstream instruments and renaming them would break existing controller-runtime dashboards.
324+
atecontroller bridges controller-runtime's private Prometheus registry, which the manager serves on `:8080` only while `OTEL_METRICS_EXPORTER` leaves it on (see [Scraping instead of pushing](#scraping-instead-of-pushing)), onto its OTLP reader. So `controller_runtime_*`, `workqueue_*`, `certwatcher_*`, `rest_client_*`, `leader_election_*`, `go_*`, and `process_*` reach the collector too, keeping their Prometheus names because they are upstream instruments and renaming them would break existing controller-runtime dashboards.
325325

326326
These can be used to answer whether the controller is keeping up, e.g. rising `workqueue_depth` or `workqueue_queue_duration_seconds` means reconciles are falling behind, and `controller_runtime_reconcile_errors_total` says which controller.
327327

‎internal/serverboot/serverboot.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ func metricsExporters(ctx context.Context, pullServed bool) Exporters {
220220
known = append(known, exporterPrometheus)
221221
def[exporterPrometheus] = true
222222
}
223-
return resolveExportersEnv(ctx, metricsExporterEnv, known, def)
223+
exporters := resolveExportersEnv(ctx, metricsExporterEnv, known, def)
224+
slog.InfoContext(ctx, "Metrics exporters resolved", slog.String("exporters", exporters.String()))
225+
return exporters
224226
}
225227

226228
// metricsPushEnabled reports whether the OTLP reader is installed: while otlp
@@ -273,7 +275,6 @@ func InitMetricsBridged(ctx context.Context, serviceName string, reg interface {
273275
return nil, false, fmt.Errorf("serviceName is required")
274276
}
275277
exporters := metricsExporters(ctx, true)
276-
slog.InfoContext(ctx, "Metrics exporters resolved", slog.String("exporters", exporters.String()))
277278
servePull = exporters.Has(exporterPrometheus)
278279
switch {
279280
case exporters.Has(ExporterOTLP):

0 commit comments

Comments
 (0)