You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While using prometheus api to get the rules using Rule API in api.go I ran into the following issue, While trying to marshall the body into a json. I am trying to cache the results.
<*errors.errorString | 0xc0002c9c50>: {
s: "v1.RulesResult.Groups: []v1.RuleGroup: unmarshalerDecoder: failed to decode JSON into an alerting or recording rule, error found in #10 byte of ...|00:00Z\"}]}]}|..., bigger context ...|Time\":0,\"lastEvaluation\":\"0001-01-01T00:00:00Z\"}]}]}|...",
}
v1.RulesResult.Groups: []v1.RuleGroup: unmarshalerDecoder: failed to decode JSON into an alerting or recording rule, error found in #10 byte of ...|00:00Z"}]}]}|..., bigger context ...|Time":0,"lastEvaluation":"0001-01-01T00:00:00Z"}]}]}|...
occurred
// following stacktrace
type field not present in rule
On looking closely in the api.go file I found that Type variable is not defined in the struct for AlertingRule and RecordingRule, hence when we are trying to get the Rules using the api, we get an unmarshall failed error. I also checked in the same file which is specifically checking for the Type field to be present in the json on the following lines https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go#L739C1-L751C3. I also checked the sample json response which is expected and it also contains the type field. The sample can be found here.
Solution
We add the Type field in both the structs and set them alerting and recording which are already defined as constant in the file. I tested it on my local and it works.
The text was updated successfully, but these errors were encountered:
Problem Description:
While using prometheus api to get the rules using Rule API in api.go I ran into the following issue, While trying to marshall the body into a json. I am trying to cache the results.
On looking closely in the api.go file I found that Type variable is not defined in the struct for AlertingRule and RecordingRule, hence when we are trying to get the Rules using the api, we get an unmarshall failed error. I also checked in the same file which is specifically checking for the Type field to be present in the json on the following lines https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go#L739C1-L751C3. I also checked the sample json response which is expected and it also contains the type field. The sample can be found here.
Solution
We add the Type field in both the structs and set them alerting and recording which are already defined as constant in the file. I tested it on my local and it works.
The text was updated successfully, but these errors were encountered: