client_golang
client_golang copied to clipboard
Add type field to AlertingRule and RecordingRule struct
Describe your PR
AlertingRules and ReocrdingRules are missing the type field in their struct, this leads to json unmarshalling issues in the library. This returns an error on client side which looks like
<*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
In order to fix this I added the type field to both the structs. There is a specific check for type field in Unmarshall functions for both the structs as can be seen in the following lines of code.
AlertingRule -> https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go#L740-L751 RecordingRule -> https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go#L785-L796
It works now and is able to unmarshall the object and return a valid RuleResult object back which can be marshalled in json on client side.
What type of PR is this?
/kind bugfix
Changelog Entry
[BUGFIX] fix GetRules API response to be json marshallable. #1557
Changelog Entry
api: add type field to AlertingRule and RecordingRule struct.
C.C - @ArthurSens @bwplotka @kakkoyun