Repository navigation
Replace the config-remote-sync YAML patcher with a go-yaml v4 editor - #8169
ilyakuz-db wants to merge 4 commits into
Conversation
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
…d styles under null parents Co-authored-by: Isaac <no-reply@databricks.com>
…-remote-sync aws: TestAccept/bundle/config-remote-sync Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
Automated review at 8aa7f2c. Each finding was verified against the code.
Not ready yet: 1 blocking issue(s), tagged [blocking].
This PR replaces the palantir yamlpatch/yaml.v3 patcher in config-remote-sync with a small go-yaml v4 editor. Each file is now parsed once, gets all of its changes applied to one tree, and is encoded once. The structure is cleaner, and the merge-key and missing-sequence fixes show up in the goldens. I'd fix one thing before merging: a replace silently deletes the user's inline comment on the old value. Separately, values that look like YAML 1.1 bools now get different quoting depending on the write path, and the user-visible output changes need a changelog fragment.
Comments outside the changed lines
- [nice to have]
bundle/configsync/patch.go: This changes whatbundle config-remote-syncwrites into user files:<<:instead of!!merge <<:, sequences instead of"0"/"-"keys under created ancestors, and new quoting of multi-line strings. There is no.nextchanges/fragment for it. Can you add one under.nextchanges/bundles/covering at least the merge-key and sequence fixes, as a single*line ending with the PR link (see.nextchanges/README.md)?
| if err != nil { | ||
| return err | ||
| } | ||
| container.Content[slices.Index(container.Content, child)] = node |
There was a problem hiding this comment.
[blocking] setYAMLChild puts a freshly encoded node into the slot and throws away the old value's LineComment, HeadComment and FootComment. go-yaml keeps an inline comment on the value scalar, so replacing job.timeout_seconds in timeout_seconds: 3600 # one hour writes timeout_seconds: 7200 and the comment is gone. A head comment above a replaced sequence item (# keep b over - b) is lost the same way. This path serves both replaceYAML and the add-onto-existing-key branch of addYAML. Can you carry the comments over the way replaceYAMLNode in patch.go already does (scalar or flow keeps the line comment, a block container moves it to the key)? Please also add a test with an inline comment on the replaced value; the current "replace key" case only has a head comment on the key node, and that one survives anyway.
| return nil, err | ||
| } | ||
| if plain { | ||
| walkYAML(&node, func(n *yaml.Node) { n.Style = 0 }) |
There was a problem hiding this comment.
[nice to have] With plain, every style that node.Encode set is cleared, including the double quotes go-yaml adds to strings like yes, no, on and 1:30. The node encoder only forces quotes when the 1.2 resolver disagrees, and it resolves yes as !!str. So adding job.flag = "yes" under an existing job: mapping now writes flag: yes, while the same value under a null parent stays "yes", which is what your new "YAML 1.1 bool under a null parent" test pins. The old patcher quoted it on both paths, and YAML 1.1 readers load the unquoted form as a bool. Could plain mode keep the double-quoted style that the encoder chose for scalars and only drop the flow/container styles? Please also add the existing-parent case to the test table.
Regression test report ✅Commit: Selected 3 changed tests (limit=20, 0 not selected) 129 tests: regression=6 unreleased=20 coverage=103 failing=0
TestAccept/bundle/config-remote-sync/cluster_override_existing_key/DMS=: branch ✅ | main (5cdaeb8) ✅ | latest (v1.28.0) ❌latest (v1.28.0): TestAccept/bundle/config-remote-sync/cluster_override_existing_key/DMS=true: branch ✅ | main (5cdaeb8) ✅ | latest (v1.28.0) ❌latest (v1.28.0): TestAccept/bundle/config-remote-sync/cluster_override_merge_key/DMS=: branch ✅ | main (5cdaeb8) ❌ | latest (v1.28.0) ❌main (5cdaeb8): latest (v1.28.0): TestAccept/bundle/config-remote-sync/cluster_override_merge_key/DMS=true: branch ✅ | main (5cdaeb8) ❌ | latest (v1.28.0) ❌main (5cdaeb8): latest (v1.28.0): TestAccept/bundle/config-remote-sync/merge_key_inherited/DMS=: branch ✅ | main (5cdaeb8) ❌ | latest (v1.28.0) ❌main (5cdaeb8): latest (v1.28.0): TestAccept/bundle/config-remote-sync/merge_key_inherited/DMS=true: branch ✅ | main (5cdaeb8) ❌ | latest (v1.28.0) ❌main (5cdaeb8): latest (v1.28.0): TestAccept/bundle/config-remote-sync/remove_multiple_tasks/DMS=: branch ✅ | main (5cdaeb8) ✅ | latest (v1.28.0) ❌latest (v1.28.0): TestAccept/bundle/config-remote-sync/remove_multiple_tasks/DMS=true: branch ✅ | main (5cdaeb8) ✅ | latest (v1.28.0) ❌latest (v1.28.0): TestAccept/bundle/config-remote-sync/split/anchored_override_field/DMS=: branch ✅ | main (5cdaeb8) ✅ | latest (v1.28.0) ❌latest (v1.28.0): TestAccept/bundle/config-remote-sync/split/anchored_override_field/DMS=true: branch ✅ | main (5cdaeb8) ✅ | latest (v1.28.0) ❌latest (v1.28.0): TestAccept/bundle/config-remote-sync/split/cleared_key_override/DMS=: branch ✅ | main (5cdaeb8) ❌ | latest (v1.28.0) ❌main (5cdaeb8): latest (v1.28.0): 15 more failure details omitted, see the full report in the run. |
✅ Integration test reportCommit: 8aa7f2c
63 interesting tests: 62 MISS, 1 RECOVERED
Top 7 slowest tests (at least 2 minutes):
|
Changes
bundle/configsync/yamledit.go: a small editor on go-yaml v4 that adds, replaces and removes nodes addressed by structpath, and creates missing or null ancestors. One walk with a typed stop (found, missing, null, scalar) serves the edits andkeyWrittenAt/yamlKeyValue, so resolve and patch follow aliases the same way.ApplyChangesToYAMLparses each file once, applies all of its changes to that tree and encodes it once.patch.gokeeps the policy: which write path wins (existing parent, then null ancestor, then missing ancestor), anchor relocation (later changes now follow an alias to where its anchor moved), blank-line markers, flow-style clearing and the error messages.github.com/palantir/pkg/yamlpatch, the only path togopkg.in/yaml.v3andgithub.com/pkg/errorsin the binary, and the code that worked around it: JSON Pointer conversion, parsing its error strings, re-parsing after every change.Output differs from the old patcher only where it was wrong or fragile:
<<:instead of becoming!!merge <<:. A string value<<is quoted instead of turning into a merge key, and a leading newline in a string is kept.[*]under ancestors that the sync creates builds a sequence. The old patcher wrote"0"or"-"mapping keys, or failed.{},[...]) that the sync then writes in block style no longer keeps the quoting flow style needed, soa, bstays plain and a multi-line string becomes a|-block.Why
Each change was parsed and encoded several times, switching between yaml.v3 (the patcher) and v4 (our helpers), and most of the code around the patcher only worked around it.
Tests
Unit tests in
bundle/configsyncpass, with new table tests for map, sequence and[*]edits, missing, null and{}parents, aliases, merge keys, moved anchors and exact quoting; the editor cases replaceTestBuildNestedMaps. Localconfig-remote-syncacceptance tests pass and only the three merge-key outputs changed. I also diffed old and new output locally over generated changes to every bundle acceptance YAML file (harness not committed); the list above is what it found.go list -deps .no longer has yaml.v3, yamlpatch or pkg/errors. The head commit requests the aws runs ofTestAccept/bundle/config-remote-sync.29ea2744c64d68RIGHT-SIZED: swaps the v3 patcher for the v4 node edits the code already did around it8aa7f2c(latest)TestAccept/bundle/config-remote-sync(29 cloud test dirs)8aa7f2c(latest)8aa7f2c(latest)8aa7f2c(latest)✅ success · ⏳ pending ·⚠️ warning · ❌ failed · ➖ n/a
This pull request and its description were written by Isaac.