lib/promscrape/discovery/ec2: add ability to filter Availability Zones in ec2_sd_config via az_filters section

This commit is contained in:
Aliaksandr Valialkin 2022-05-06 12:43:29 +03:00
parent 8babb4aebc
commit 9d40bb7137
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
5 changed files with 15 additions and 10 deletions

View file

@ -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).

View file

@ -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
}

View file

@ -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)

View file

@ -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.

View file

@ -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 {