From 9a4cb4f3a968783cf901be5ef3f0e301abcf9f2a Mon Sep 17 00:00:00 2001 From: Steven Berler Date: Thu, 14 Sep 2023 12:55:39 -0700 Subject: [PATCH] correctly convert static YACE jobs --- CHANGELOG.md | 2 ++ .../internal/build/cloudwatch_exporter.go | 33 ++++++++++++++++++- .../staticconvert/testdata/integrations.river | 23 +++++++++++++ .../staticconvert/testdata/integrations.yaml | 19 +++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea101c4ce73b..43a2ffb3ec7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,8 @@ Main (unreleased) - Fixed a bug where documented default settings in `otelcol.exporter.loadbalancing` were never set. (@rfratto) +- Fixed a bug where converting `YACE` cloudwatch config to river skipped converting static jobs. (@berler) + v0.36.1 (2023-09-06) -------------------- diff --git a/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go b/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go index 610980866e7c..969530a80559 100644 --- a/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go +++ b/converter/internal/staticconvert/internal/build/cloudwatch_exporter.go @@ -29,7 +29,7 @@ func toCloudwatchExporter(config *cloudwatch_exporter.Config) *cloudwatch.Argume Debug: config.Debug, DiscoveryExportedTags: config.Discovery.ExportedTags, Discovery: toDiscoveryJobs(config.Discovery.Jobs), - Static: []cloudwatch.StaticJob{}, + Static: toStaticJobs(config.Static), } } @@ -56,6 +56,29 @@ func toDiscoveryJob(job *cloudwatch_exporter.DiscoveryJob) cloudwatch.DiscoveryJ } } +func toStaticJobs(jobs []cloudwatch_exporter.StaticJob) []cloudwatch.StaticJob { + var out []cloudwatch.StaticJob + for _, job := range jobs { + out = append(out, toStaticJob(&job)) + } + return out +} + +func toStaticJob(job *cloudwatch_exporter.StaticJob) cloudwatch.StaticJob { + return cloudwatch.StaticJob{ + Name: job.Name, + Auth: cloudwatch.RegionAndRoles{ + Regions: job.Regions, + Roles: toRoles(job.Roles), + }, + CustomTags: toTags(job.CustomTags), + Namespace: job.Namespace, + Dimensions: toDimensions(job.Dimensions), + Metrics: toMetrics(job.Metrics), + NilToZero: job.NilToZero, + } +} + func toRoles(roles []cloudwatch_exporter.Role) []cloudwatch.Role { var out []cloudwatch.Role for _, role := range roles { @@ -79,6 +102,14 @@ func toTags(tags []cloudwatch_exporter.Tag) cloudwatch.Tags { return out } +func toDimensions(dimensions []cloudwatch_exporter.Dimension) cloudwatch.Dimensions { + out := make(cloudwatch.Dimensions) + for _, dimension := range dimensions { + out[dimension.Name] = dimension.Value + } + return out +} + func toMetrics(metrics []cloudwatch_exporter.Metric) []cloudwatch.Metric { var out []cloudwatch.Metric for _, metric := range metrics { diff --git a/converter/internal/staticconvert/testdata/integrations.river b/converter/internal/staticconvert/testdata/integrations.river index 8cd4df3921ca..8f2f0b8222fd 100644 --- a/converter/internal/staticconvert/testdata/integrations.river +++ b/converter/internal/staticconvert/testdata/integrations.river @@ -97,6 +97,29 @@ prometheus.exporter.cloudwatch "integrations_cloudwatch_exporter" { nil_to_zero = true } + static "single_ec2_instance" { + regions = ["us-east-2"] + custom_tags = {} + namespace = "AWS/EC2" + dimensions = { + InstanceId = "i-0e43cee369aa44b52", + } + + metric { + name = "CPUUtilization" + statistics = ["Average"] + period = "5m0s" + nil_to_zero = false + } + + metric { + name = "NetworkPacketsIn" + statistics = ["Average"] + period = "5m0s" + } + nil_to_zero = true + } + decoupled_scraping { } } diff --git a/converter/internal/staticconvert/testdata/integrations.yaml b/converter/internal/staticconvert/testdata/integrations.yaml index 300ec2db9980..8b3c54b891a9 100644 --- a/converter/internal/staticconvert/testdata/integrations.yaml +++ b/converter/internal/staticconvert/testdata/integrations.yaml @@ -48,6 +48,25 @@ integrations: period: 5m statistics: - Average + static: + - name: single_ec2_instance + regions: + - us-east-2 + namespace: AWS/EC2 + dimensions: + - name: InstanceId + value: i-0e43cee369aa44b52 + nil_to_zero: true + metrics: + - name: CPUUtilization + period: 5m + statistics: + - Average + nil_to_zero: false + - name: NetworkPacketsIn + period: 5m + statistics: + - Average consul_exporter: enabled: true dnsmasq_exporter: