Skip to content

Commit

Permalink
YACE dimension_name_requirements support (#4705)
Browse files Browse the repository at this point in the history
  • Loading branch information
CVdV-au authored Aug 10, 2023
1 parent 2aa87ea commit 4507bfa
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Main (unreleased)

- Flow: Add a new stage `non_indexed_labels` to attach non-indexed labels from extracted data to log line entry. (@vlad-diachenko)

- Allow specification of `dimension_name_requirements` for Cloudwatch discovery exports. (@cvdv-au)

- `loki.write` now exposes basic WAL support. (@thepalbi)

- `loki.write` WAL now exposes a last segment reclaimed metric. (@thepalbi)
Expand Down
22 changes: 12 additions & 10 deletions component/prometheus/exporter/cloudwatch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ type TagsPerNamespace = cloudwatch_exporter.TagsPerNamespace

// DiscoveryJob configures a discovery job for a given service.
type DiscoveryJob struct {
Auth RegionAndRoles `river:",squash"`
CustomTags Tags `river:"custom_tags,attr,optional"`
SearchTags Tags `river:"search_tags,attr,optional"`
Type string `river:"type,attr"`
Metrics []Metric `river:"metric,block"`
Auth RegionAndRoles `river:",squash"`
CustomTags Tags `river:"custom_tags,attr,optional"`
SearchTags Tags `river:"search_tags,attr,optional"`
Type string `river:"type,attr"`
DimensionNameRequirements []string `river:"dimension_name_requirements,attr,optional"`
Metrics []Metric `river:"metric,block"`
}

// Tags represents a series of tags configured on an AWS resource. Each tag is a
Expand Down Expand Up @@ -190,11 +191,12 @@ func toYACEStaticJob(sj StaticJob) *yaceConf.Static {

func toYACEDiscoveryJob(rj DiscoveryJob) *yaceConf.Job {
job := &yaceConf.Job{
Regions: rj.Auth.Regions,
Roles: toYACERoles(rj.Auth.Roles),
Type: rj.Type,
CustomTags: rj.CustomTags.toYACE(),
SearchTags: rj.SearchTags.toYACE(),
Regions: rj.Auth.Regions,
Roles: toYACERoles(rj.Auth.Roles),
Type: rj.Type,
CustomTags: rj.CustomTags.toYACE(),
SearchTags: rj.SearchTags.toYACE(),
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,
Expand Down
8 changes: 5 additions & 3 deletions component/prometheus/exporter/cloudwatch/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ discovery {
role {
role_arn = "arn:aws:iam::878167871295:role/yace_testing"
}
dimension_name_requirements = ["BucketName"]
metric {
name = "BucketSizeBytes"
statistics = ["Sum"]
Expand Down Expand Up @@ -238,9 +239,10 @@ func TestCloudwatchComponentConfig(t *testing.T) {
Roles: []yaceConf.Role{{
RoleArn: "arn:aws:iam::878167871295:role/yace_testing",
}},
Type: "s3",
SearchTags: []yaceModel.Tag{},
CustomTags: []yaceModel.Tag{},
Type: "s3",
SearchTags: []yaceModel.Tag{},
CustomTags: []yaceModel.Tag{},
DimensionNameRequirements: []string{"BucketName"},
Metrics: []*yaceConf.Metric{
{
Name: "BucketSizeBytes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,13 @@ prometheus.exporter.cloudwatch "discover_instances" {
You can configure the `discovery` block one or multiple times to scrape metrics from different services or with
different `search_tags`.

| Name | Type | Description | Default | Required |
|---------------|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|----------|
| `regions` | `list(string)` | List of AWS regions. | | yes |
| `type` | `string` | Cloudwatch service alias (`"alb"`, `"ec2"`, etc) or namespace name (`"AWS/EC2"`, `"AWS/S3"`, etc). See [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 |
| `search_tags` | `map(string)` | List of key / value pairs to use for tag filtering (all must match). Value can be a regex. | `{}` | no |
| Name | Type | Description | Default | Required |
|--------------------------------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|----------|
| `regions` | `list(string)` | List of AWS regions. | | yes |
| `type` | `string` | Cloudwatch service alias (`"alb"`, `"ec2"`, etc) or namespace name (`"AWS/EC2"`, `"AWS/S3"`, etc). See [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 |
| `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 |

[supported-services]: #supported-services-in-discovery-jobs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ Configuration reference:
# the following format: `custom_tag_{Key}`.
custom_tags: [ <aws_tag> ]

# Optional: 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.
dimension_name_requirements: [ <string> ]

# Required: List of metric definitions to scrape.
metrics: [ <metric> ]
```
Expand Down
24 changes: 13 additions & 11 deletions pkg/integrations/cloudwatch_exporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ type TagsPerNamespace map[string][]string

// DiscoveryJob configures a discovery job for a given service.
type DiscoveryJob struct {
InlineRegionAndRoles `yaml:",inline"`
InlineCustomTags `yaml:",inline"`
SearchTags []Tag `yaml:"search_tags"`
Type string `yaml:"type"`
Metrics []Metric `yaml:"metrics"`
InlineRegionAndRoles `yaml:",inline"`
InlineCustomTags `yaml:",inline"`
SearchTags []Tag `yaml:"search_tags"`
Type string `yaml:"type"`
DimensionNameRequirements []string `yaml:"dimension_name_requirements"`
Metrics []Metric `yaml:"metrics"`
}

// StaticJob will scrape metrics that match all defined dimensions.
Expand Down Expand Up @@ -206,12 +207,13 @@ func toYACEDimensions(dim []Dimension) []yaceConf.Dimension {
func toYACEDiscoveryJob(job *DiscoveryJob) *yaceConf.Job {
roles := toYACERoles(job.Roles)
yaceJob := yaceConf.Job{
Regions: job.Regions,
Roles: roles,
CustomTags: toYACETags(job.CustomTags),
Type: job.Type,
Metrics: toYACEMetrics(job.Metrics),
SearchTags: toYACETags(job.SearchTags),
Regions: job.Regions,
Roles: roles,
CustomTags: toYACETags(job.CustomTags),
Type: job.Type,
Metrics: toYACEMetrics(job.Metrics),
SearchTags: toYACETags(job.SearchTags),
DimensionNameRequirements: job.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.
Expand Down
9 changes: 7 additions & 2 deletions pkg/integrations/cloudwatch_exporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ discovery:
- us-east-2
roles:
- role_arn: arn:aws:iam::878167871295:role/yace_testing
dimension_name_requirements:
- BucketName
metrics:
- name: BucketSizeBytes
period: 5m
Expand Down Expand Up @@ -95,6 +97,8 @@ discovery:
- us-east-2
roles:
- role_arn: arn:aws:iam::878167871295:role/yace_testing
dimension_name_requirements:
- BucketName
metrics:
- name: BucketSizeBytes
period: 5m
Expand Down Expand Up @@ -178,8 +182,9 @@ var expectedConfig = yaceConf.ScrapeConf{
RoleArn: "arn:aws:iam::878167871295:role/yace_testing",
},
},
SearchTags: []yaceModel.Tag{},
CustomTags: []yaceModel.Tag{},
SearchTags: []yaceModel.Tag{},
CustomTags: []yaceModel.Tag{},
DimensionNameRequirements: []string{"BucketName"},
Metrics: []*yaceConf.Metric{
{
Name: "BucketSizeBytes",
Expand Down

0 comments on commit 4507bfa

Please sign in to comment.