diff --git a/docs/sources/reference/components/prometheus/prometheus.exporter.cloudwatch.md b/docs/sources/reference/components/prometheus/prometheus.exporter.cloudwatch.md index da4180b4704..0105b6ba8e0 100644 --- a/docs/sources/reference/components/prometheus/prometheus.exporter.cloudwatch.md +++ b/docs/sources/reference/components/prometheus/prometheus.exporter.cloudwatch.md @@ -88,7 +88,6 @@ To use all of the integration features, use the following AWS IAM Policy: ```alloy prometheus.exporter.cloudwatch "queues" { sts_region = "us-east-2" - aws_sdk_version_v2 = false discovery { type = "AWS/SQS" regions = ["us-east-2"] @@ -116,9 +115,9 @@ prometheus.exporter.cloudwatch "queues" { You can use the following arguments with `prometheus.exporter.cloudwatch`: | Name | Type | Description | Default | Required | -| ------------------------- | ------------------- | ------------------------------------------------------------------------------ | ------- | -------- | +| ------------------------- | ------------------- |--------------------------------------------------------------------------------|---------| -------- | | `sts_region` | `string` | AWS region to use when calling [STS][] for retrieving account information. | | yes | -| `aws_sdk_version_v2` | `bool` | Use AWS SDK version 2. | `false` | no | +| `aws_sdk_version_v2` | `bool` | (Deprecated) When `false`, uses AWS SDK for Go v1 instead of v2. | `true` | no | | `fips_disabled` | `bool` | Disable use of FIPS endpoints. Set 'true' when running outside of USA regions. | `true` | no | | `debug` | `bool` | Enable debug logging on CloudWatch exporter internals. | `false` | no | | `discovery_exported_tags` | `map(list(string))` | List of tags (value) per service (key) to export in all metrics. | `{}` | no | @@ -129,6 +128,11 @@ This affects all discovery jobs. [STS]: https://docs.aws.amazon.com/STS/latest/APIReference/welcome.html +{{< admonition type="caution" >}} +Starting with {{< param "PRODUCT_NAME" >}} v1.15, the `aws_sdk_version_v2` argument is deprecated as AWS SDK for Go v1 is end-of-life since July 31, 2025. +Remove this argument from your configuration to use AWS SDK for Go v2, which is the default. +{{< /admonition >}} + ## Blocks You can use the following blocks with `prometheus.exporter.cloudwatch`: diff --git a/internal/component/prometheus/exporter/cloudwatch/cloudwatch.go b/internal/component/prometheus/exporter/cloudwatch/cloudwatch.go index 51f199457df..9eaa47c75dc 100644 --- a/internal/component/prometheus/exporter/cloudwatch/cloudwatch.go +++ b/internal/component/prometheus/exporter/cloudwatch/cloudwatch.go @@ -6,6 +6,7 @@ import ( "github.com/grafana/alloy/internal/component" "github.com/grafana/alloy/internal/component/prometheus/exporter" "github.com/grafana/alloy/internal/featuregate" + "github.com/grafana/alloy/internal/runtime/logging/level" "github.com/grafana/alloy/internal/static/integrations" "github.com/grafana/alloy/internal/static/integrations/cloudwatch_exporter" ) @@ -30,6 +31,13 @@ func createExporter(opts component.Options, args component.Arguments) (integrati // yaceSess expects a default value of True fipsEnabled := !a.FIPSDisabled + if !a.UseAWSSDKVersion2 { + level.Warn(opts.Logger).Log( + "msg", + "the `aws_sdk_version_v2` argument is deprecated and will be removed in future releases - AWS SDK for Go v1 is end-of-life, remove this argument to use AWS SDK for Go v2", + ) + } + if a.DecoupledScrape.Enabled { exp, err := cloudwatch_exporter.NewDecoupledCloudwatchExporter(opts.ID, opts.Logger, exporterConfig, a.DecoupledScrape.ScrapeInterval, fipsEnabled, a.LabelsSnakeCase, a.Debug, a.UseAWSSDKVersion2) return exp, getHash(a), err diff --git a/internal/component/prometheus/exporter/cloudwatch/config.go b/internal/component/prometheus/exporter/cloudwatch/config.go index c02eccccbdc..664289f8a63 100644 --- a/internal/component/prometheus/exporter/cloudwatch/config.go +++ b/internal/component/prometheus/exporter/cloudwatch/config.go @@ -27,7 +27,7 @@ var defaults = Arguments{ ScrapeInterval: 5 * time.Minute, }, LabelsSnakeCase: false, - UseAWSSDKVersion2: false, + UseAWSSDKVersion2: true, } // Arguments are the Alloy based options to configure the embedded CloudWatch exporter. diff --git a/internal/component/prometheus/exporter/cloudwatch/config_test.go b/internal/component/prometheus/exporter/cloudwatch/config_test.go index 669ad745c8d..0526d3f66f1 100644 --- a/internal/component/prometheus/exporter/cloudwatch/config_test.go +++ b/internal/component/prometheus/exporter/cloudwatch/config_test.go @@ -1184,6 +1184,27 @@ var expectedCustomNamespaceDelayConfig = yaceModel.JobsConfig{ }, } +func TestUseAWSSDKVersion(t *testing.T) { + t.Run("defaults to true", func(t *testing.T) { + args := Arguments{} + err := syntax.Unmarshal([]byte(`sts_region = "us-east-1"`), &args) + require.NoError(t, err) + require.NotEmpty(t, args.STSRegion) + require.True(t, args.UseAWSSDKVersion2) + }) + + t.Run("can be explicitly set to false", func(t *testing.T) { + args := Arguments{} + err := syntax.Unmarshal([]byte(` +sts_region = "us-east-1" +aws_sdk_version_v2 = false +`), &args) + require.NoError(t, err) + require.NotEmpty(t, args.STSRegion) + require.False(t, args.UseAWSSDKVersion2) + }) +} + func TestCloudwatchComponentConfig(t *testing.T) { type testcase struct { raw string diff --git a/internal/component/prometheus/exporter/tests/instance_key_test.go b/internal/component/prometheus/exporter/tests/instance_key_test.go index 8ae4bbdc3e3..0c26d585fc8 100644 --- a/internal/component/prometheus/exporter/tests/instance_key_test.go +++ b/internal/component/prometheus/exporter/tests/instance_key_test.go @@ -124,8 +124,9 @@ func TestInstanceKey(t *testing.T) { testName: "cloudwatch", componentName: "prometheus.exporter.cloudwatch", args: cloudwatch.Arguments{ - STSRegion: "us-west-2", - FIPSDisabled: true, + STSRegion: "us-west-2", + FIPSDisabled: true, + UseAWSSDKVersion2: true, Discovery: []cloudwatch.DiscoveryJob{ { Type: "AWS/EC2", diff --git a/internal/converter/internal/staticconvert/testdata-v2/integrations_v2.alloy b/internal/converter/internal/staticconvert/testdata-v2/integrations_v2.alloy index 04425220876..4d86d3553a9 100644 --- a/internal/converter/internal/staticconvert/testdata-v2/integrations_v2.alloy +++ b/internal/converter/internal/staticconvert/testdata-v2/integrations_v2.alloy @@ -186,7 +186,6 @@ prometheus.exporter.cloudwatch "integrations_cloudwatch_exporter" { } decoupled_scraping { } - aws_sdk_version_v2 = true } discovery.relabel "integrations_cloudwatch" { diff --git a/internal/converter/internal/staticconvert/testdata/integrations.alloy b/internal/converter/internal/staticconvert/testdata/integrations.alloy index 5b81350c0d5..c96c4aaabd2 100644 --- a/internal/converter/internal/staticconvert/testdata/integrations.alloy +++ b/internal/converter/internal/staticconvert/testdata/integrations.alloy @@ -225,7 +225,6 @@ prometheus.exporter.cloudwatch "integrations_cloudwatch_exporter" { } decoupled_scraping { } - aws_sdk_version_v2 = true } discovery.relabel "integrations_cloudwatch_exporter" { diff --git a/internal/static/integrations/cloudwatch_exporter/config.go b/internal/static/integrations/cloudwatch_exporter/config.go index e4c8f8443be..213c14d5818 100644 --- a/internal/static/integrations/cloudwatch_exporter/config.go +++ b/internal/static/integrations/cloudwatch_exporter/config.go @@ -39,6 +39,11 @@ func init() { integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeMultiplex, metricsutils.NewNamedShim("cloudwatch")) } +// DefaultConfig holds the default settings for the cloudwatch_exporter integration. +var DefaultConfig = Config{ + UseAWSSDKVersion2: true, +} + // Config is the configuration for the CloudWatch metrics integration type Config struct { STSRegion string `yaml:"sts_region"` @@ -50,6 +55,13 @@ type Config struct { UseAWSSDKVersion2 bool `yaml:"aws_sdk_version_v2"` } +// UnmarshalYAML implements yaml.Unmarshaler for Config. +func (c *Config) UnmarshalYAML(unmarshal func(any) error) error { + *c = DefaultConfig + type plain Config + return unmarshal((*plain)(c)) +} + // DecoupledScrapeConfig is the configuration for decoupled scraping feature. type DecoupledScrapeConfig struct { Enabled bool `yaml:"enabled"` @@ -138,6 +150,11 @@ func (c *Config) NewIntegration(l log.Logger) (integrations.Integration, error) if err != nil { return nil, fmt.Errorf("invalid cloudwatch exporter configuration: %w", err) } + + if !c.UseAWSSDKVersion2 { + level.Warn(l).Log("msg", "the `aws_sdk_version_v2` argument is deprecated and will be removed in future releases - AWS SDK for Go v1 is end-of-life, remove this argument to use AWS SDK for Go v2") + } + if c.DecoupledScrape.Enabled { scrapeInterval := defaultDecoupledScrapingInterval if v := c.DecoupledScrape.ScrapeInterval; v != nil { diff --git a/internal/static/integrations/cloudwatch_exporter/config_test.go b/internal/static/integrations/cloudwatch_exporter/config_test.go index 5321a0f127f..7994436aa34 100644 --- a/internal/static/integrations/cloudwatch_exporter/config_test.go +++ b/internal/static/integrations/cloudwatch_exporter/config_test.go @@ -475,6 +475,24 @@ func TestTranslateConfigToYACEConfig(t *testing.T) { require.EqualValues(t, falsePtr, fipsEnabled2) } +func TestConfigDefaults(t *testing.T) { + t.Run("UseAWSSDKVersion2 defaults to true", func(t *testing.T) { + var c Config + err := yaml.Unmarshal([]byte(`sts_region: us-east-1`), &c) + require.NoError(t, err) + require.NotEmpty(t, c.STSRegion) + require.True(t, c.UseAWSSDKVersion2) + }) + + t.Run("UseAWSSDKVersion2 can be explicitly set to false", func(t *testing.T) { + var c Config + err := yaml.Unmarshal([]byte("sts_region: us-east-1\naws_sdk_version_v2: false"), &c) + require.NoError(t, err) + require.NotEmpty(t, c.STSRegion) + require.False(t, c.UseAWSSDKVersion2) + }) +} + func TestTranslateNilToZeroConfigToYACEConfig(t *testing.T) { c := Config{} err := yaml.Unmarshal([]byte(configString3), &c)