From 9d40bb7137497b1b6881922be15027ac6fe8afe1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 6 May 2022 12:43:29 +0300 Subject: [PATCH] lib/promscrape/discovery/ec2: add ability to filter Availability Zones in `ec2_sd_config` via `az_filters` section --- docs/CHANGELOG.md | 2 ++ lib/promscrape/discovery/ec2/api.go | 14 ++++++++------ lib/promscrape/discovery/ec2/az.go | 2 +- lib/promscrape/discovery/ec2/ec2.go | 5 +++-- lib/promscrape/discovery/ec2/instance.go | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index adfa9daaa..016889962 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,6 +15,8 @@ The following tip changes can be tested by building VictoriaMetrics components f ## tip +* FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): add ability to specify filters for Availability Zones in [ec2_sd_config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ec2_sd_config) via `az_filters` section. This section can contain AZ-specific set of filters in the same way as the existing `filters` section, which is used for filtering EC2 instances. The list of supported AZ-specific filters is available [here](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAvailabilityZones.html). + * BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl.html): properly import InfluxDB measurements if they contain `db` tag. Previously this could result in incomplete import of measurmenet tags. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/2536). Thanks to @mback2k for the bugfix. * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): do not reset the selected relative time range when entering new query. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2402#issuecomment-1115817302). * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): properly show the graph when clicking on `Prometheus` link in Grafana graph editor. Previously the graph wasn't shown until clicking on the `Graph` tab. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2402#issuecomment-1115830648). diff --git a/lib/promscrape/discovery/ec2/api.go b/lib/promscrape/discovery/ec2/api.go index 014cea086..dc3640c97 100644 --- a/lib/promscrape/discovery/ec2/api.go +++ b/lib/promscrape/discovery/ec2/api.go @@ -8,9 +8,10 @@ import ( ) type apiConfig struct { - awsConfig *awsapi.Config - filters []awsapi.Filter - port int + awsConfig *awsapi.Config + instanceFilters []awsapi.Filter + azFilters []awsapi.Filter + port int // A map from AZ name to AZ id. azMap map[string]string @@ -37,9 +38,10 @@ func newAPIConfig(sdc *SDConfig) (*apiConfig, error) { return nil, err } cfg := &apiConfig{ - awsConfig: awsCfg, - filters: sdc.Filters, - port: port, + awsConfig: awsCfg, + instanceFilters: sdc.InstanceFilters, + azFilters: sdc.AZFilters, + port: port, } return cfg, nil } diff --git a/lib/promscrape/discovery/ec2/az.go b/lib/promscrape/discovery/ec2/az.go index ed299c454..42ce2fd84 100644 --- a/lib/promscrape/discovery/ec2/az.go +++ b/lib/promscrape/discovery/ec2/az.go @@ -30,7 +30,7 @@ func getAZMap(cfg *apiConfig) map[string]string { func getAvailabilityZones(cfg *apiConfig) ([]AvailabilityZone, error) { // See https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAvailabilityZones.html - azFilters := awsapi.GetFiltersQueryString(cfg.filters, azFiltersWhitelist) + azFilters := awsapi.GetFiltersQueryString(cfg.azFilters, azFiltersWhitelist) data, err := cfg.awsConfig.GetEC2APIResponse("DescribeAvailabilityZones", azFilters, "") if err != nil { return nil, fmt.Errorf("cannot obtain availability zones: %w", err) diff --git a/lib/promscrape/discovery/ec2/ec2.go b/lib/promscrape/discovery/ec2/ec2.go index 5cca0bc3b..dd229ae89 100644 --- a/lib/promscrape/discovery/ec2/ec2.go +++ b/lib/promscrape/discovery/ec2/ec2.go @@ -27,8 +27,9 @@ type SDConfig struct { RoleARN string `yaml:"role_arn,omitempty"` // RefreshInterval time.Duration `yaml:"refresh_interval"` // refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option. - Port *int `yaml:"port,omitempty"` - Filters []awsapi.Filter `yaml:"filters,omitempty"` + Port *int `yaml:"port,omitempty"` + InstanceFilters []awsapi.Filter `yaml:"filters,omitempty"` + AZFilters []awsapi.Filter `yaml:"az_filters,omitempty"` } // GetLabels returns ec2 labels according to sdc. diff --git a/lib/promscrape/discovery/ec2/instance.go b/lib/promscrape/discovery/ec2/instance.go index 89b0369e0..b7a219f0b 100644 --- a/lib/promscrape/discovery/ec2/instance.go +++ b/lib/promscrape/discovery/ec2/instance.go @@ -29,7 +29,7 @@ func getReservations(cfg *apiConfig) ([]Reservation, error) { // See https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html var rs []Reservation pageToken := "" - instanceFilters := awsapi.GetFiltersQueryString(cfg.filters, nil) + instanceFilters := awsapi.GetFiltersQueryString(cfg.instanceFilters, nil) for { data, err := cfg.awsConfig.GetEC2APIResponse("DescribeInstances", instanceFilters, pageToken) if err != nil {