diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c08d003e5c..48a14027f8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ Main (unreleased) - Fix direction of arrows for pyroscope components in UI graph. (@dehaansa) +- Fix `prometheus.exporter.cloudwatch` to not always emit debug logs but respect debug property. (@kalleep) + v1.11.0 ----------------- diff --git a/internal/static/integrations/cloudwatch_exporter/cloudwatch_exporter.go b/internal/static/integrations/cloudwatch_exporter/cloudwatch_exporter.go index a877865acc6..902161bb8de 100644 --- a/internal/static/integrations/cloudwatch_exporter/cloudwatch_exporter.go +++ b/internal/static/integrations/cloudwatch_exporter/cloudwatch_exporter.go @@ -40,10 +40,12 @@ func NewCloudwatchExporter(name string, logger log.Logger, conf yaceModel.JobsCo var factory cachingFactory var err error + l := slog.New(newSlogHandler(logging.NewSlogGoKitHandler(logger), debug)) + if useAWSSDKVersionV2 { - factory, err = yaceClientsV2.NewFactory(slog.New(logging.NewSlogGoKitHandler(logger)), conf, fipsEnabled) + factory, err = yaceClientsV2.NewFactory(l, conf, fipsEnabled) } else { - factory = yaceClientsV1.NewFactory(slog.New(logging.NewSlogGoKitHandler(logger)), conf, fipsEnabled) + factory = yaceClientsV1.NewFactory(l, conf, fipsEnabled) } if err != nil { @@ -52,7 +54,7 @@ func NewCloudwatchExporter(name string, logger log.Logger, conf yaceModel.JobsCo return &exporter{ name: name, - logger: slog.New(logging.NewSlogGoKitHandler(logger)), + logger: l, cachingClientFactory: factory, scrapeConf: conf, }, nil diff --git a/internal/static/integrations/cloudwatch_exporter/logger.go b/internal/static/integrations/cloudwatch_exporter/logger.go new file mode 100644 index 00000000000..85ea3b44c47 --- /dev/null +++ b/internal/static/integrations/cloudwatch_exporter/logger.go @@ -0,0 +1,30 @@ +package cloudwatch_exporter + +import ( + "context" + "log/slog" + + "github.com/grafana/alloy/internal/runtime/logging" +) + +// slogHandler is wrapping our internal logging adapter with support for cloudwatch debug field. +// cloudwatch exporter will inspect check for debug logging level and pass that to aws sdk that perform +// it's own logging without going through the logger we pass. +type slogHandler struct { + debug bool + *logging.SlogGoKitHandler +} + +func newSlogHandler(logger *logging.SlogGoKitHandler, debug bool) *slogHandler { + return &slogHandler{ + debug: debug, + SlogGoKitHandler: logger, + } +} + +func (s *slogHandler) Enabled(ctx context.Context, level slog.Level) bool { + if level == slog.LevelDebug { + return s.debug + } + return s.SlogGoKitHandler.Enabled(ctx, level) +}