VictoriaMetrics/VictoriaMetrics · error

cannot get API config: %w

Error message

cannot get API config: %w

What it means

Returned by SDConfig.GetLabels when building the OVH Cloud API client configuration (getAPIConfig) fails. Typically the provided SD config is invalid (bad credentials format, unreadable file referenced in config) so no API calls can even be attempted. The underlying cause is wrapped with %w.

Source

Thrown at lib/promscrape/discovery/ovhcloud/ovhcloud.go:35

// SDConfig is the configuration for OVH Cloud service discovery.
type SDConfig struct {
	Endpoint          string           `yaml:"endpoint"`
	ApplicationKey    string           `yaml:"application_key"`
	ApplicationSecret *promauth.Secret `yaml:"application_secret"`
	ConsumerKey       *promauth.Secret `yaml:"consumer_key"`
	Service           string           `yaml:"service"`

	HTTPClientConfig  promauth.HTTPClientConfig  `yaml:",inline"`
	ProxyURL          *proxy.URL                 `yaml:"proxy_url,omitempty"`
	ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
}

// GetLabels returns labels for OVH Cloud according to service discover config.
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)
	}
	switch sdc.Service {
	case "dedicated_server":
		return getDedicatedServerLabels(cfg)
	case "vps":
		return getVPSLabels(cfg)
	default:
		return nil, fmt.Errorf("skipping unexpected service=%q; only `dedicated_server` and `vps` are supported for now", sdc.Service)
	}
}

// MustStop stops further usage for sdc.
func (sdc *SDConfig) MustStop() {
	v := configMap.Delete(sdc)
	if v != nil {
		cfg := v.(*apiConfig)
		cfg.client.Stop()
	}

View on GitHub (pinned to 5079fb58f1)

Solutions

  1. Inspect the wrapped cause in the error message to see which config field failed
  2. Ensure application_key, application_secret and consumer_key are set and non-empty in the ovhcloud_sd_config
  3. If using file-based secrets, confirm the referenced files exist and are readable relative to baseDir
  4. Validate the whole scrape config with the config-check flag before reloading

Example fix

// before (missing secret)
ovhcloud_sd_configs:
  - service: dedicated_server
    application_key: xxx
// after
ovhcloud_sd_configs:
  - service: dedicated_server
    application_key: xxx
    application_secret: yyy
    consumer_key: zzz
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight config check in Go
cfg, err := getAPIConfig(sdc, baseDir)
if err != nil {
    return fmt.Errorf("invalid ovhcloud_sd_config: %w", err)
}
if sdc.ApplicationKey == "" || sdc.ApplicationSecret == "" || sdc.ConsumerKey == "" {
    return errors.New("ovhcloud_sd_config: all three credentials are required")
}

Try / catch

// fail fast at config load, not per scrape
if err := configCheck(); err != nil {
    log.Fatalf("ovhcloud sd config invalid: %v", err)
}

Prevention

When it happens

Trigger: getAPIConfig(sdc, baseDir) errors: missing/empty application_key, application_secret or consumer_key; invalid config fields; failure resolving paths relative to baseDir.

Common situations: Incomplete ovhcloud_sd_configs block in Prometheus/VictoriaMetrics scrape config; secrets placeholder not substituted (e.g. left as file: reference that doesn't resolve); typo in config keys.

Related errors


AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03). Data as JSON: /api/errors/15093b33679e4713. Report an issue: GitHub.