mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-19 15:30:17 +00:00
lib/promscrape/discovery/gce: properly set filter
query arg in api url
This commit is contained in:
parent
0daa37fa02
commit
1acb6eb25a
1 changed files with 5 additions and 5 deletions
|
@ -124,8 +124,8 @@ func newAPIConfig(sdc *SDConfig) (*apiConfig, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAPIResponse(client *http.Client, apiURL, filter, pageToken string) ([]byte, error) {
|
func getAPIResponse(client *http.Client, apiURL, filter, pageToken string) ([]byte, error) {
|
||||||
apiURL = appendNonEmptyQueryArg(apiURL, filter)
|
apiURL = appendNonEmptyQueryArg(apiURL, "filter", filter)
|
||||||
apiURL = appendNonEmptyQueryArg(apiURL, pageToken)
|
apiURL = appendNonEmptyQueryArg(apiURL, "pageToken", pageToken)
|
||||||
resp, err := client.Get(apiURL)
|
resp, err := client.Get(apiURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot query %q: %s", apiURL, err)
|
return nil, fmt.Errorf("cannot query %q: %s", apiURL, err)
|
||||||
|
@ -146,15 +146,15 @@ func readResponseBody(resp *http.Response, apiURL string) ([]byte, error) {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendNonEmptyQueryArg(apiURL, arg string) string {
|
func appendNonEmptyQueryArg(apiURL, argName, argValue string) string {
|
||||||
if len(arg) == 0 {
|
if len(argValue) == 0 {
|
||||||
return apiURL
|
return apiURL
|
||||||
}
|
}
|
||||||
prefix := "?"
|
prefix := "?"
|
||||||
if strings.Contains(apiURL, "?") {
|
if strings.Contains(apiURL, "?") {
|
||||||
prefix = "&"
|
prefix = "&"
|
||||||
}
|
}
|
||||||
return apiURL + fmt.Sprintf("%spageToken=%s", prefix, url.QueryEscape(arg))
|
return apiURL + fmt.Sprintf("%s%s=%s", prefix, url.QueryEscape(argName), url.QueryEscape(argValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCurrentZone() (string, error) {
|
func getCurrentZone() (string, error) {
|
||||||
|
|
Loading…
Reference in a new issue