{"record":{"id":"2ebb677cc5ccd644","repo":"thanos-io/thanos","slug":"expected-alertmanager-api-version-to-be-one-of-v","errorCode":null,"errorMessage":"expected Alertmanager API version to be one of %v but got %q","messagePattern":"expected Alertmanager API version to be one of (.+?) but got %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/alert/config.go","lineNumber":59,"sourceCode":"\nvar supportedAPIVersions = []APIVersion{\n\tAPIv1, APIv2,\n}\n\n// UnmarshalYAML implements the yaml.Unmarshaler interface.\nfunc (v *APIVersion) UnmarshalYAML(unmarshal func(any) error) error {\n\tvar s string\n\tif err := unmarshal(&s); err != nil {\n\t\treturn errors.Wrap(err, \"invalid Alertmanager API version\")\n\t}\n\n\tfor _, ver := range supportedAPIVersions {\n\t\tif APIVersion(s) == ver {\n\t\t\t*v = ver\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn errors.Errorf(\"expected Alertmanager API version to be one of %v but got %q\", supportedAPIVersions, s)\n}\n\nfunc DefaultAlertmanagerConfig() AlertmanagerConfig {\n\treturn AlertmanagerConfig{\n\t\tEndpointsConfig: clientconfig.HTTPEndpointsConfig{\n\t\t\tScheme:          \"http\",\n\t\t\tStaticAddresses: []string{},\n\t\t\tFileSDConfigs:   []clientconfig.HTTPFileSDConfig{},\n\t\t},\n\t\tTimeout:    model.Duration(time.Second * 10),\n\t\tAPIVersion: APIv2,\n\t}\n}\n\n// UnmarshalYAML implements the yaml.Unmarshaler interface.\nfunc (c *AlertmanagerConfig) UnmarshalYAML(unmarshal func(any) error) error {\n\t*c = DefaultAlertmanagerConfig()\n\ttype plain AlertmanagerConfig","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/alert/config.go#L41-L77","documentation":"After decoding api_version as a string, UnmarshalYAML compares it against supportedAPIVersions; if no match, it errors with the list of accepted versions and the offending value. This rejects Alertmanager API versions this Thanos build does not support.","triggerScenarios":"Setting api_version to any string not in supportedAPIVersions (e.g. api_version: v1 or api_version: v3) in AlertmanagerConfig YAML.","commonSituations":"Targeting an old Alertmanager with v1; using a newer API version (api_version: v3) than the embedded Thanos/prometheus/alertmanager client supports; typos like \"V2\" (case-sensitive).","solutions":["Set api_version to one of the supported values listed in the error message (typically \"api/v2\"), or remove the field to accept the default.","If you need a newer API version, upgrade Thanos to a build whose supportedAPIVersions includes it.","Check case and spelling against the exact supported list."],"exampleFix":"// before\napi_version: v3\n// after\napi_version: \"v2\"","handlingStrategy":"validation","validationCode":"allowed := []APIVersion{\"api/v2\"} // mirror supportedAPIVersions\nif !slices.Contains(allowed, APIVersion(cfg.APIVersion)) {\n    return fmt.Errorf(\"api_version %q not in %v\", cfg.APIVersion, allowed)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy the api_version value from the error's supported list verbatim","Never assume v1/v3; check the Thanos version's supportedAPIVersions","Pin config to a version validated against the running Thanos build"],"tags":["config","alertmanager","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}