Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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 |
Expand All @@ -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`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ prometheus.exporter.cloudwatch "integrations_cloudwatch_exporter" {
}

decoupled_scraping { }
aws_sdk_version_v2 = true
}

discovery.relabel "integrations_cloudwatch" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ prometheus.exporter.cloudwatch "integrations_cloudwatch_exporter" {
}

decoupled_scraping { }
aws_sdk_version_v2 = true
}

discovery.relabel "integrations_cloudwatch_exporter" {
Expand Down
17 changes: 17 additions & 0 deletions internal/static/integrations/cloudwatch_exporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions internal/static/integrations/cloudwatch_exporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading