Open sarthaktyagi-505 opened 2 months ago
Hi Guys,
I opened the following PR to fix the above issue https://github.com/prometheus/client_golang/pull/1558 can you guys please review it C.C - @kakkoyun @bwplotka @ArthurSens
Thanks in advance Sarthak
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.