-
Notifications
You must be signed in to change notification settings - Fork 70
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 marshalling scalar blocks #247
Conversation
e79cd62
to
065c802
Compare
Fixes #245 There is currently a bug in [go-yaml/yaml](https://github.com/go-yaml/yaml) causing indentation hints on scalar blocks to be set incorrectly. As a result, they can not be unmarshalled. This PR is an attempt at fixing this (un)marshalling issue by using an alternative, regurlarly maintained, YAML library: [goccy/go-yaml](https://github.com/goccy/go-yaml) Some quick manual testing showed that goccy/go-yaml resolves #245, but there is more validation needed to decide if switching to a new dependency is viable: * goccy/go-yaml is highly likely to marshal resources differently. While some degree of change is *probably* acceptable, I currently don't know how different marshalled resources are. * there isn't any unit test covering the issue, I will add one.
065c802
to
aa6b2fb
Compare
The marshaled resources are actually fairly similar with the new library. The main differences come from inconsistencies in go-yaml/yaml. For example, it would output: panels:
- id: 4
gridPos:
h: 22
w: 10
x: 14
"y": 0
tags:
- hosted-metrics (note the inconsistent indentation: mostly 4 spaces but sometimes 2 spaces) While goccy/go-yaml generates: panels:
- id: 4
gridPos:
h: 22
w: 10
x: 14
"y": 0
tags:
- hosted-metrics (consistent, 4 spaces indentation) |
cdf446d
to
88016e1
Compare
Hi @K-Phoen, I tried to
It also looks like similar differences are detected when following the same steps with the current version (using -- Other than that, is there any other test that you would suggest doing before merging this PR? (cc/ @malcolmholmes) Thanks! |
The thing that stopped me merging this PR is the fact that it results in whitespace (and other) no-op diffs. Any users that are using diff to detect meaningful changes would find a whitespace change annoying. And given that there's a simple solution (don't lead your queries with a newline), I didn't tackle the question of whether this was a valid/valuable change. I'm totally open to using a different approach to YAML marshalling, I just want to know its enough to justify any discomfort users may experience. |
What do you think would be actually annoying?
-- In my opinion (which might be totally wrong!), what I think that could be annoying is only the 2nd, cause would be equivalent to saying "your local files aren't in sync" - while this would not necessarily be true. In that sense, I think we could kinda sort it with a different diff algorithm, that compares "objects" (like JSON comparison) not string literals. That should reduce most (if not all) the no-op diffs (it would still display white spaces and newlines within values, but I guess that should be fair cause they could technically have different meanings / end in different results. Regarding the 1st one, I guess it's like when adding a new linter rule or something like that, could be a bit annoying as well, but less likely to cause problems if we provide a real comparator ( Wdyt? cc/ @K-Phoen |
Interesting questions - you're totally on the mark here. A JSON diff would be amazing, actually. And whitespace changes are less of a bad thing in PRs nowadays due to clever diff highlighting whitespace differently. |
FTR: This PR improves matters but does not resolve them. Grafana dashboards can do some weird things with their JSON. Here's some issues that show up with this library when parsing and rendering dashboards found in the wild: goccy/go-yaml#418 |
converted to draft as there's nothing final here |
Unfortunately, this library introduces a separate set of issues caused by the new library. I'm closing it for now. Should this library resolve its issues, we can re-open/reconsider. Keeping #245 open to keep track of the original issue. |
Fixes #245
There is currently a bug in go-yaml/yaml causing indentation hints on scalar blocks to be set incorrectly. As a result, they can not be unmarshalled.
A PR has been open upstream a few years ago but hasn't seen any meaningful activity recently.
This PR is an attempt at fixing this (un)marshalling issue by using an alternative, regurlarly maintained, YAML library: goccy/go-yaml
Some quick manual testing showed that goccy/go-yaml resolves #245, but there is more validation needed to decide if switching to a new dependency is viable: