lib/promscrape/discovery/gce: do not pass filter arg when discovering zones

The filter arg isn't supported by zones API in GCE.

See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3202
This commit is contained in:
Aliaksandr Valialkin 2022-11-21 22:32:03 +02:00
parent 45c2651678
commit 4df78e8814
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
3 changed files with 7 additions and 3 deletions

View file

@ -15,6 +15,8 @@ The following tip changes can be tested by building VictoriaMetrics components f
## v1.79.x long-time support release (LTS)
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly discover GCE zones when `filter` option is set at [gce_sd_configs](https://docs.victoriametrics.com/sd_configs.html#gce_sd_configs). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3202).
## [v1.79.5](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.79.5)
Released at 10-11-2022

View file

@ -58,7 +58,9 @@ func newAPIConfig(sdc *SDConfig) (*apiConfig, error) {
logger.Infof("autodetected the current GCE zone: %q", zone)
} else if len(zones) == 1 && zones[0] == "*" {
// Autodetect zones for project.
zs, err := getZonesForProject(client, project, sdc.Filter)
// Do not pass sdc.Filter when discovering zones, since GCE doesn't support it.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3202
zs, err := getZonesForProject(client, project)
if err != nil {
return nil, fmt.Errorf("cannot obtain zones for project %q: %w", project, err)
}

View file

@ -6,13 +6,13 @@ import (
"net/http"
)
func getZonesForProject(client *http.Client, project, filter string) ([]string, error) {
func getZonesForProject(client *http.Client, project string) ([]string, error) {
// See https://cloud.google.com/compute/docs/reference/rest/v1/zones
zonesURL := fmt.Sprintf("https://compute.googleapis.com/compute/v1/projects/%s/zones", project)
var zones []string
pageToken := ""
for {
data, err := getAPIResponse(client, zonesURL, filter, pageToken)
data, err := getAPIResponse(client, zonesURL, "", pageToken)
if err != nil {
return nil, fmt.Errorf("cannot obtain zones: %w", err)
}