From 4aa8941eb186264e570ee76eda8b23ff8989abc5 Mon Sep 17 00:00:00 2001 From: Will Bollock Date: Sun, 16 Nov 2025 05:28:50 -0500 Subject: [PATCH] fix(discovery): aws discovery test fix (#17527) * fix: aws discovery test fix Fixes a problem introduced after the merge of this https://github.com/prometheus/prometheus/pull/17138 PR didn't take into account another merged PR! ``` discovery/aws/aws.go:218:54: too many arguments in call to NewEC2Discovery have (*EC2SDConfig, *slog.Logger, *ec2Metrics) want (*EC2SDConfig, discovery.DiscovererOptions) discovery/aws/aws.go:222:66: too many arguments in call to NewLightsailDiscovery have (*LightsailSDConfig, *slog.Logger, *lightsailMetrics) want (*LightsailSDConfig, discovery.DiscovererOptions) ``` Signed-off-by: Will Bollock * fix: align ecs style ECS was a new service discovery tool added after this PR was merged: https://github.com/prometheus/prometheus/pull/17138 Aligns the style of passing a single "opts" to it like almost all the other service discovery engines now use Signed-off-by: Will Bollock --------- Signed-off-by: Will Bollock --- discovery/aws/aws.go | 3 ++- discovery/aws/ecs.go | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/discovery/aws/aws.go b/discovery/aws/aws.go index bfb2be183c..1ac97b3c9e 100644 --- a/discovery/aws/aws.go +++ b/discovery/aws/aws.go @@ -218,7 +218,8 @@ func (c *SDConfig) NewDiscoverer(opts discovery.DiscovererOptions) (discovery.Di opts.Metrics = &ec2Metrics{refreshMetrics: awsMetrics.refreshMetrics} return NewEC2Discovery(c.EC2SDConfig, opts) case RoleECS: - return NewECSDiscovery(c.ECSSDConfig, opts.Logger, &ecsMetrics{refreshMetrics: awsMetrics.refreshMetrics}) + opts.Metrics = &ecsMetrics{refreshMetrics: awsMetrics.refreshMetrics} + return NewECSDiscovery(c.ECSSDConfig, opts) case RoleLightsail: opts.Metrics = &lightsailMetrics{refreshMetrics: awsMetrics.refreshMetrics} return NewLightsailDiscovery(c.LightsailSDConfig, opts) diff --git a/discovery/aws/ecs.go b/discovery/aws/ecs.go index 286c002a71..3794ad178d 100644 --- a/discovery/aws/ecs.go +++ b/discovery/aws/ecs.go @@ -118,7 +118,7 @@ func (*ECSSDConfig) Name() string { return "ecs" } // NewDiscoverer returns a Discoverer for the EC2 Config. func (c *ECSSDConfig) NewDiscoverer(opts discovery.DiscovererOptions) (discovery.Discoverer, error) { - return NewECSDiscovery(c, opts.Logger, opts.Metrics) + return NewECSDiscovery(c, opts) } // UnmarshalYAML implements the yaml.Unmarshaler interface for the ECS Config. @@ -165,22 +165,22 @@ type ECSDiscovery struct { } // NewECSDiscovery returns a new ECSDiscovery which periodically refreshes its targets. -func NewECSDiscovery(conf *ECSSDConfig, logger *slog.Logger, metrics discovery.DiscovererMetrics) (*ECSDiscovery, error) { - m, ok := metrics.(*ecsMetrics) +func NewECSDiscovery(conf *ECSSDConfig, opts discovery.DiscovererOptions) (*ECSDiscovery, error) { + m, ok := opts.Metrics.(*ecsMetrics) if !ok { return nil, errors.New("invalid discovery metrics type") } - if logger == nil { - logger = promslog.NewNopLogger() + if opts.Logger == nil { + opts.Logger = promslog.NewNopLogger() } d := &ECSDiscovery{ - logger: logger, + logger: opts.Logger, cfg: conf, } d.Discovery = refresh.NewDiscovery( refresh.Options{ - Logger: logger, + Logger: opts.Logger, Mech: "ecs", Interval: time.Duration(d.cfg.RefreshInterval), RefreshF: d.refresh,