-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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.
<*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.
Activity
sarthaktyagi-505 commentedon Jul 10, 2024
Hi Guys,
I opened the following PR to fix the above issue #1558 can you guys please review it C.C - @kakkoyun @bwplotka @ArthurSens
Thanks in advance
Sarthak
stale commentedon Jul 19, 2025
Hello 👋 Looks like there was no activity on this issue for the last 3 months. Do you mind updating us on the status? Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗
If there will be no activity in the next 4 weeks, this issue will be closed (we can always reopen an issue if we need!).