From b6902701c60b9f3903af57394f97714db19b04aa Mon Sep 17 00:00:00 2001 From: hugoShaka Date: Wed, 15 Jan 2025 12:21:21 -0500 Subject: [PATCH] Init local registry at runtime instead of config --- lib/service/service.go | 11 ++++++++++- lib/service/servicecfg/config.go | 4 ---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/service/service.go b/lib/service/service.go index ec91870cd18e4..7130dfd0c0182 100644 --- a/lib/service/service.go +++ b/lib/service/service.go @@ -1006,6 +1006,15 @@ func NewTeleport(cfg *servicecfg.Config) (*TeleportProcess, error) { "pid", fmt.Sprintf("%v.%v", os.Getpid(), processID), ) + // Use the custom metrics registry if specified, else create a new one. + // We must create the registry in NewTeleport, as opposed to ApplyConfig(), + // because some tests are running multiple Teleport instances from the same + // config. + metricsRegistry := cfg.MetricsRegistry + if metricsRegistry == nil { + metricsRegistry = prometheus.NewRegistry() + } + // If FIPS mode was requested make sure binary is build against BoringCrypto. if cfg.FIPS { if !modules.GetModules().IsBoringBinary() { @@ -1189,7 +1198,7 @@ func NewTeleport(cfg *servicecfg.Config) (*TeleportProcess, error) { logger: cfg.Logger, cloudLabels: cloudLabels, TracingProvider: tracing.NoopProvider(), - metricsRegistry: cfg.MetricsRegistry, + metricsRegistry: metricsRegistry, } process.registerExpectedServices(cfg) diff --git a/lib/service/servicecfg/config.go b/lib/service/servicecfg/config.go index a7841b4d10db4..98b5905fc05e7 100644 --- a/lib/service/servicecfg/config.go +++ b/lib/service/servicecfg/config.go @@ -523,10 +523,6 @@ func ApplyDefaults(cfg *Config) { cfg.LoggerLevel = new(slog.LevelVar) } - if cfg.MetricsRegistry == nil { - cfg.MetricsRegistry = prometheus.NewRegistry() - } - // Remove insecure and (borderline insecure) cryptographic primitives from // default configuration. These can still be added back in file configuration by // users, but not supported by default by Teleport. See #1856 for more