From 11aaa7544f2d90ce4fe006ada1065ae5d645ba33 Mon Sep 17 00:00:00 2001 From: Clovis Delarue Date: Tue, 20 Aug 2024 08:47:52 +0200 Subject: [PATCH] fix: Add missing logger in servicequotas fetcher This commit is updating the exporter and servicequotas packages to properly pass the logger. In the `serviceQuotaFetcher` struct we have defined a logger field but it was never initialized. Which means any call to s.logger was panicking in the `serviceQuotaFetcher` methods. Properly passing the logger and storing it in the structure will allow us to properly use `s.logger` inside the `serviceQuotaFetcher` methods. This change has been made following this [issue][1] [1]: https://github.com/qonto/prometheus-rds-exporter/issues/205 Signed-off-by: Clovis Delarue --- internal/app/exporter/exporter.go | 2 +- internal/app/servicequotas/servicequotas.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/app/exporter/exporter.go b/internal/app/exporter/exporter.go index d823cd5..8fee6b2 100644 --- a/internal/app/exporter/exporter.go +++ b/internal/app/exporter/exporter.go @@ -477,7 +477,7 @@ func (c *rdsCollector) getQuotasMetrics(client servicequotas.ServiceQuotasClient c.logger.Debug("fetch quotas") - fetcher := servicequotas.NewFetcher(ctx, client) + fetcher := servicequotas.NewFetcher(ctx, client, c.logger) metrics, err := fetcher.GetRDSQuotas() if err != nil { diff --git a/internal/app/servicequotas/servicequotas.go b/internal/app/servicequotas/servicequotas.go index f61b6ec..0d97ac1 100644 --- a/internal/app/servicequotas/servicequotas.go +++ b/internal/app/servicequotas/servicequotas.go @@ -5,13 +5,13 @@ import ( "context" "errors" "fmt" + "log/slog" aws_servicequotas "github.com/aws/aws-sdk-go-v2/service/servicequotas" "github.com/qonto/prometheus-rds-exporter/internal/app/trace" converter "github.com/qonto/prometheus-rds-exporter/internal/app/unit" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" - "golang.org/x/exp/slog" ) var ( @@ -44,10 +44,11 @@ type ServiceQuotasClient interface { GetServiceQuota(ctx context.Context, input *aws_servicequotas.GetServiceQuotaInput, optFns ...func(*aws_servicequotas.Options)) (*aws_servicequotas.GetServiceQuotaOutput, error) } -func NewFetcher(ctx context.Context, client ServiceQuotasClient) *serviceQuotaFetcher { +func NewFetcher(ctx context.Context, client ServiceQuotasClient, logger slog.Logger) *serviceQuotaFetcher { return &serviceQuotaFetcher{ ctx: ctx, client: client, + logger: &logger, } }