Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recently_active_only to prometheus.exporter.cloudwatch discovery block #1685

Merged
merged 1 commit into from
Oct 17, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
7 changes: 4 additions & 3 deletions internal/component/prometheus/exporter/cloudwatch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -370,6 +371,7 @@ func TestCloudwatchComponentConfig(t *testing.T) {
},
RoundingPeriod: nil,
ExportedTagsOnMetrics: []string{},
RecentlyActiveOnly: true,
DimensionsRegexps: []yaceModel.DimensionsRegexp{
{
Regexp: regexp.MustCompile("(?P<BucketName>[^:]+)$"),
Expand Down
Loading