Skip to content

Commit

Permalink
Update cloudwatch exporter code
Browse files Browse the repository at this point in the history
  • Loading branch information
andriikushch committed Apr 29, 2024
1 parent 55a8c0a commit 92e4d66
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func createExporter(opts component.Options, args component.Arguments, defaultIns
fipsEnabled := !a.FIPSDisabled

if a.DecoupledScrape.Enabled {
exp, err := cloudwatch_exporter.NewDecoupledCloudwatchExporter(opts.ID, opts.Logger, exporterConfig, a.DecoupledScrape.ScrapeInterval, fipsEnabled, a.Debug, "2")
exp, err := cloudwatch_exporter.NewDecoupledCloudwatchExporter(opts.ID, opts.Logger, exporterConfig, a.DecoupledScrape.ScrapeInterval, fipsEnabled, a.Debug, a.AWSSDKVersion)
return exp, getHash(a), err
}

exp, err := cloudwatch_exporter.NewCloudwatchExporter(opts.ID, opts.Logger, exporterConfig, fipsEnabled, a.Debug, "2")
exp, err := cloudwatch_exporter.NewCloudwatchExporter(opts.ID, opts.Logger, exporterConfig, fipsEnabled, a.Debug, a.AWSSDKVersion)
return exp, getHash(a), err
}
2 changes: 2 additions & 0 deletions internal/component/prometheus/exporter/cloudwatch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var defaults = Arguments{
Enabled: false,
ScrapeInterval: 5 * time.Minute,
},
AWSSDKVersion: "v1",
}

// Arguments are the river based options to configure the embedded CloudWatch exporter.
Expand All @@ -38,6 +39,7 @@ type Arguments struct {
Discovery []DiscoveryJob `river:"discovery,block,optional"`
Static []StaticJob `river:"static,block,optional"`
DecoupledScrape DecoupledScrapeConfig `river:"decoupled_scraping,block,optional"`
AWSSDKVersion string `river:"aws_sdk_version"`
}

// DecoupledScrapeConfig is the configuration for decoupled scraping feature.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func NewCloudwatchExporter(name string, logger log.Logger, conf yaceModel.JobsCo
var err error

switch clientVersion {
case "1":
case AWSSDKVersionV1:
factory = yaceClientsV1.NewFactory(loggerWrapper, conf, fipsEnabled)
case "2":
case AWSSDKVersionV2:
factory, err = yaceClientsV2.NewFactory(loggerWrapper, conf, fipsEnabled)
default:
err = fmt.Errorf("invalid client version %s", clientVersion)
err = fmt.Errorf("invalid client version %s, valid versions are v1 and v2", clientVersion)
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func NewDecoupledCloudwatchExporter(name string, logger log.Logger, conf yaceMod
var err error

switch clientVersion {
case "1":
case AWSSDKVersionV1:
factory = yaceClientsV1.NewFactory(loggerWrapper, conf, fipsEnabled)
case "2":
case AWSSDKVersionV2:
factory, err = yaceClientsV2.NewFactory(loggerWrapper, conf, fipsEnabled)
default:
err = fmt.Errorf("invalid client version %s", clientVersion)
err = fmt.Errorf("invalid client version %s, valid versions are v1 and v2", clientVersion)
}

if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions static/integrations/cloudwatch_exporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const (
tagConcurrency = 5
labelsSnakeCase = false
defaultDecoupledScrapingInterval = time.Minute * 5

AWSSDKVersionV1 = "v1"
AWSSDKVersionV2 = "v2"
)

// Since we are gathering metrics from CloudWatch and writing them in prometheus during each scrape, the timestamp
Expand All @@ -44,6 +47,7 @@ type Config struct {
Static []StaticJob `yaml:"static"`
Debug bool `yaml:"debug"`
DecoupledScrape DecoupledScrapeConfig `yaml:"decoupled_scraping"`
AWSSDKVersion string `yaml:"aws_sdk_version"`
}

// DecoupledScrapeConfig is the configuration for decoupled scraping feature.
Expand Down

0 comments on commit 92e4d66

Please sign in to comment.