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
Fix mashaling of URL, Regex wrappers with nil value, and empty Matchers. #2607
Fix mashaling of URL, Regex wrappers with nil value, and empty Matchers. #2607
Conversation
(This is currently blocking cortexproject/cortex#4237, where it was first found -- integration tests were failing) |
1dce377
to
56751a7
Compare
I need to take a deep loop. This might be a subtle "breaking" API change. |
That's fair. Let me break this down, since this PR actually packs many changes at once. Let's see if it makes sense to split them.
If you want me to get rid of change 2), I'm fine with that. It would mean that |
I think I will go ahead and revert this part, to avoid breaking changes. |
nil
URL, Regex and Matchers.
To avoid introducing breaking changes, I've removed changes to unmarshalling. Unit tests documenting current behaviour are left in place. |
bd92523
to
b2219bd
Compare
Fix JSON marshalling of empty Matchers. Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
b2219bd
to
270d844
Compare
@roidelapluie I wouldn't think that these presented any breaking changes given the JSON marshalling of these structs wasn't introduced until recently (by prometheus/common#297 IIRC) and to my best of my understanding, it is currently not used by any of the Prometheus repositories. The reason why this wasn't breaking before it's because YAML is a superset of JSON so unmarshaling would actually produce results, if anything this would be a bugfix of the recently introduced behaviour as we would like the output to be consistent. WDYT? |
Just to be clear, I don't expect 2) to be done as part of this PR. I'd like to merge this fix ASAP as Grafana is also suffering from this problem. |
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
490746b
to
40a8035
Compare
This does not really address my concern about breaking changes, which is when we unmarshal. The MarshalJSON is used in API's, e.g. to list the silences. Does this mean that now, when you get an empty regex or empty matchers from the API's it will always be null, when it was hidden before? |
After reading the docs this indeed seems correct. |
Unmarshalling is not changed by this PR. Marshalling of wrappers with nil value was broken before and returned error. Now such wrappers marshal to
In case of matchers, marshalling empty slice previously didn't work, now it does and produces empty JSON list. Unmarshalling is not affected. |
MarshalJSON
method must return valid JSON or error.This PR fixes JSON marshaling
and unmarshallingofconfig.URL
andconfig.Regex
wrappers withnil
values. Such values are now mashalled intonull
json literal, and can be unmarshalled properly as well. (Empty strings are also unmarshalled into wrappers withnil
value).Also fixed JSON marshalling of empty
Matchers
.I will send similar patch to
common
repository, which also hasconfig.URL
.Update: To avoid introducing breaking changes, I've removed changes to unmarshalling. Unit tests documenting current behaviour are left in place.