VictoriaMetrics/VictoriaMetrics · error
cannot get API config: %w
Error message
cannot get API config: %w
What it means
GetLabels is the entry point for DigitalOcean service discovery. This error wraps any failure returned while obtaining (or constructing and caching) the apiConfig — i.e. any of the auth-parse, proxy-auth-parse, or client-creation errors above — so it fires at config-usage time, not request time.
Source
Thrown at lib/promscrape/discovery/digitalocean/digitalocean.go:37
"This works only if digitalocean_sd_configs is configured in '-promscrape.config' file. "+
"See https://docs.victoriametrics.com/victoriametrics/sd_configs/#digitalocean_sd_configs for details")
// SDConfig represents service discovery config for digital ocean.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#digitalocean_sd_config
type SDConfig struct {
Server string `yaml:"server,omitempty"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
Port int `yaml:"port,omitempty"`
}
// GetLabels returns Digital Ocean droplet labels according to sdc.
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutil.Labels, error) {
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
return nil, fmt.Errorf("cannot get API config: %w", err)
}
droplets, err := getDroplets(cfg.client.GetAPIResponse)
if err != nil {
return nil, err
}
return addDropletLabels(droplets, cfg.port), nil
}
// https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-droplet-by-id
type droplet struct {
ID int `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Features []string `json:"features"`
Image dropletImage `json:"image"`
SizeSlug string `json:"size_slug"`
Networks networks `json:"networks"`View on GitHub (pinned to 5079fb58f1)
Solutions
- Look at the wrapped cause after 'cannot get API config:' — it will name the real failing step
- Validate the entire digitalocean_sd_config block (auth, proxy, server fields)
- Ensure all referenced files (tokens, certs, CA) exist and are readable by vmagent
- Reload vmagent config only after running config validation
- Temporarily use defaults (no http_client_config) to isolate which subsection is broken
Example fix
# before
- digitalocean_sd_configs:
- port: 80
http_client_config:
authorization:
credentials_file: /etc/do/missing.txt
# after
- digitalocean_sd_configs:
- port: 80
http_client_config:
authorization:
credentials: <base64 of token or use credentials_file with an existing file> Defensive patterns
Strategy: validation
Validate before calling
# Validate the whole digitalocean_sd_config before reload:
# - http_client_config auth files exist and readable
# - proxy files exist
# - server is a valid URL
for f in /etc/do/token.txt /etc/do/ca.pem; do test -r "$f" || { echo "missing $f"; exit 1; }; done
# then run vmagent config validation Try / catch
labels, err := sdc.GetLabels(baseDir)
if err != nil {
var cfgErr = strings.Contains(err.Error(), "cannot get API config")
if cfgErr {
// surface the wrapped cause (auth/proxy/client) to config tooling; fix and re-validate
}
return err
} Prevention
- Run config validation on every config change before reload
- Never delete/rotate credential files without updating the config
- Keep sd_config subsections correctly nested in YAML
- Stage config reloads with a canary vmagent instance
When it happens
Trigger: digitalocean_sd_config with broken http_client_config, proxy_client_config, or api_server such that newAPIConfig fails; the config map re-creates the client after a config reload and hits the same failure.
Common situations: First scrape after adding a digitalocean_sd_config with a typo; credentials file deleted after initial config load; certificate rotation breaking TLS config; indentation errors after editing prometheus.yml.
Related errors
- missing `subscription_id` config option
- cannot parse proxy auth config: %w
- cannot read configs for `environment: %q`: %w
- unsupported `authentication_method: %q` only `OAuth` and `Ma
- cannot get API config: %w
AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03).
Data as JSON: /api/errors/ab476cdd42ee0a96.
Report an issue: GitHub.