From 8e806a7c4544f4a198953f6bacfb6588722fb1c5 Mon Sep 17 00:00:00 2001 From: Paulin Todev Date: Thu, 17 Oct 2024 15:28:23 +0100 Subject: [PATCH] Add recently_active_only to prometheus.exporter.cloudwatch's discovery block --- CHANGELOG.md | 3 +++ .../prometheus/prometheus.exporter.cloudwatch.md | 1 + .../component/prometheus/exporter/cloudwatch/config.go | 7 ++++--- .../prometheus/exporter/cloudwatch/config_test.go | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35e69de435..274f032219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,9 @@ Main (unreleased) - Add support for relative paths to `import.file`. This new functionality allows users to use `import.file` blocks in modules imported via `import.git` and other `import.file`. (@wildum) +- `prometheus.exporter.cloudwatch`: The `discovery` block now has a `recently_active_only` configuration attribute + to return only metrics which have been active in the last 3 hours. + ### Bugfixes - Fixed a bug in `import.git` which caused a `"non-fast-forward update"` error message. (@ptodev) diff --git a/docs/sources/reference/components/prometheus/prometheus.exporter.cloudwatch.md b/docs/sources/reference/components/prometheus/prometheus.exporter.cloudwatch.md index dda2e83c18..dc45e8b0a6 100644 --- a/docs/sources/reference/components/prometheus/prometheus.exporter.cloudwatch.md +++ b/docs/sources/reference/components/prometheus/prometheus.exporter.cloudwatch.md @@ -198,6 +198,7 @@ different `search_tags`. | `regions` | `list(string)` | List of AWS regions. | | yes | | `type` | `string` | CloudWatch service alias (`"alb"`, `"ec2"`, etc) or namespace name (`"AWS/EC2"`, `"AWS/S3"`, etc). Refer to [supported-services][] for a complete list. | | yes | | `custom_tags` | `map(string)` | Custom tags to be added as a list of key / value pairs. When exported to Prometheus format, the label name follows the following format: `custom_tag_{key}`. | `{}` | no | +| `recently_active_only` | `bool` | Only return metrics that have been active in the last 3 hours. | `false` | no | | `search_tags` | `map(string)` | List of key / value pairs to use for tag filtering (all must match). Value can be a regex. | `{}` | no | | `dimension_name_requirements` | `list(string)` | List of metric dimensions to query. Before querying metric values, the total list of metrics will be filtered to only those that contain exactly this list of dimensions. An empty or undefined list results in all dimension combinations being included. | `{}` | no | | `nil_to_zero` | `bool` | When `true`, `NaN` metric values are converted to 0. Individual metrics can override this value in the [metric][] block. | `true` | no | diff --git a/internal/component/prometheus/exporter/cloudwatch/config.go b/internal/component/prometheus/exporter/cloudwatch/config.go index 5248aec1fb..96c879f630 100644 --- a/internal/component/prometheus/exporter/cloudwatch/config.go +++ b/internal/component/prometheus/exporter/cloudwatch/config.go @@ -56,13 +56,13 @@ type DecoupledScrapeConfig struct { type TagsPerNamespace = cloudwatch_exporter.TagsPerNamespace // DiscoveryJob configures a discovery job for a given service. -// TODO: Add a recently_active_only attribute. type DiscoveryJob struct { Auth RegionAndRoles `alloy:",squash"` CustomTags Tags `alloy:"custom_tags,attr,optional"` SearchTags Tags `alloy:"search_tags,attr,optional"` Type string `alloy:"type,attr"` DimensionNameRequirements []string `alloy:"dimension_name_requirements,attr,optional"` + RecentlyActiveOnly bool `alloy:"recently_active_only,attr,optional"` Metrics []Metric `alloy:"metric,block"` //TODO: Remove NilToZero, because it is deprecated upstream. NilToZero *bool `alloy:"nil_to_zero,attr,optional"` @@ -317,8 +317,9 @@ func toYACEDiscoveryJob(rj DiscoveryJob) *yaceConf.Job { DimensionNameRequirements: rj.DimensionNameRequirements, // By setting RoundingPeriod to nil, the exporter will align the start and end times for retrieving CloudWatch // metrics, with the smallest period in the retrieved batch. - RoundingPeriod: nil, - Metrics: toYACEMetrics(rj.Metrics, nilToZero), + RoundingPeriod: nil, + RecentlyActiveOnly: rj.RecentlyActiveOnly, + Metrics: toYACEMetrics(rj.Metrics, nilToZero), } return job } diff --git a/internal/component/prometheus/exporter/cloudwatch/config_test.go b/internal/component/prometheus/exporter/cloudwatch/config_test.go index f3f6769a10..7870538e15 100644 --- a/internal/component/prometheus/exporter/cloudwatch/config_test.go +++ b/internal/component/prometheus/exporter/cloudwatch/config_test.go @@ -99,6 +99,7 @@ discovery { role_arn = "arn:aws:iam::878167871295:role/yace_testing" } dimension_name_requirements = ["BucketName"] + recently_active_only = true metric { name = "BucketSizeBytes" statistics = ["Sum"] @@ -370,6 +371,7 @@ func TestCloudwatchComponentConfig(t *testing.T) { }, RoundingPeriod: nil, ExportedTagsOnMetrics: []string{}, + RecentlyActiveOnly: true, DimensionsRegexps: []yaceModel.DimensionsRegexp{ { Regexp: regexp.MustCompile("(?P[^:]+)$"),