Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlertingRule and RecordingRule struct in api.go missing Type variable #1557

Open
sarthaktyagi-505 opened this issue Jul 9, 2024 · 1 comment

Comments

@sarthaktyagi-505
Copy link

sarthaktyagi-505 commented Jul 9, 2024

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.

@sarthaktyagi-505
Copy link
Author

sarthaktyagi-505 commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant