diff --git a/lib/service/service.go b/lib/service/service.go index e288b96ffa792..008ca3175d769 100644 --- a/lib/service/service.go +++ b/lib/service/service.go @@ -903,6 +903,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() { @@ -1083,7 +1092,7 @@ func NewTeleport(cfg *servicecfg.Config) (*TeleportProcess, error) { keyPairs: make(map[keyPairKey]KeyPair), 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 e97dce89475f6..c1d2a1edd117d 100644 --- a/lib/service/servicecfg/config.go +++ b/lib/service/servicecfg/config.go @@ -527,10 +527,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