Skip to content

Commit

Permalink
Switch to patience diff algorithm (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-evans authored Mar 8, 2022
1 parent b74cc0a commit 97df38f
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 102 deletions.
2 changes: 1 addition & 1 deletion core/operators/acl/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (a *applier) updateApplyResult() error {
// displayPendingOps displays pending operations.
func (a *applier) displayPendingOps() {
log.Infof("acl definition %q diff (local -> remote):", a.localDef.Metadata.Name)
fmt.Print(a.res.Diff)
fmt.Println(a.res.Diff)
}

// executeOps executes update operations.
Expand Down
2 changes: 1 addition & 1 deletion core/operators/broker/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (a *applier) updateApplyResult() error {
// displayPendingOps displays pending operations.
func (a *applier) displayPendingOps() {
log.Infof("broker definition %q diff (local -> remote):", a.localDef.Metadata.Name)
fmt.Print(a.res.Diff)
fmt.Println(a.res.Diff)
}

// executeOps executes update operations.
Expand Down
2 changes: 1 addition & 1 deletion core/operators/brokers/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (a *applier) updateApplyResult() error {
// displayPendingOps displays pending operations.
func (a *applier) displayPendingOps() {
log.Infof("brokers definition %q diff (local -> remote):", a.localDef.Metadata.Name)
fmt.Print(a.res.Diff)
fmt.Println(a.res.Diff)
}

// executeOps executes update operations.
Expand Down
2 changes: 1 addition & 1 deletion core/operators/topic/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (a *applier) displayPendingOps() {
}

log.Infof("topic definition %q diff (local -> remote):", a.localDef.Metadata.Name)
fmt.Print(a.res.Diff)
fmt.Println(a.res.Diff)
}

// executeOps executes update operations.
Expand Down

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions core/test/fixtures/broker/core.operators.broker.applier.1.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"10\",\n- \"log.retention.ms\": null\n+ \"background.threads\": \"12\",\n+ \"follower.replication.throttled.rate\": \"700000000\",\n+ \"leader.replication.throttled.rate\": \"700000000\",\n+ \"listener.name.listener_host.ssl.keystore.password\": \"123foo\",\n+ \"listener.name.listener_host.ssl.truststore.password\": \"123foo\",\n+ \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"700000000\",\n+ \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"700000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n- \"listener.name.listener_host.ssl.truststore.password\": null,\n+ \"listener.name.listener_host.ssl.keystore.password\": \"123foo\",\n+ \"listener.name.listener_host.ssl.truststore.password\": \"123foo\",\n \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"700000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n- \"listener.name.listener_host.ssl.truststore.password\": null,\n- \"log.retention.ms\": \"604800000\"\n+ \"listener.name.listener_host.ssl.keystore.password\": \"123foo\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n \"follower.replication.throttled.rate\": \"600000000\",\n- \"leader.replication.throttled.rate\": \"700000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n- \"log.retention.ms\": null\n+ \"leader.replication.throttled.rate\": \"600000000\",\n+ \"listener.name.listener_host.ssl.keystore.password\": \"123foo\",\n+ \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"600000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": false\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"600000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n"
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"10\",\n- \"log.retention.ms\": null\n+ \"background.threads\": \"12\",\n+ \"follower.replication.throttled.rate\": \"700000000\",\n+ \"leader.replication.throttled.rate\": \"700000000\",\n+ \"listener.name.listener_host.ssl.keystore.password\": \"123foo\",\n+ \"listener.name.listener_host.ssl.truststore.password\": \"123foo\",\n+ \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"700000000\",\n+ \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"700000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n- \"listener.name.listener_host.ssl.truststore.password\": null,\n+ \"listener.name.listener_host.ssl.keystore.password\": \"123foo\",\n+ \"listener.name.listener_host.ssl.truststore.password\": \"123foo\",\n \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"700000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n- \"listener.name.listener_host.ssl.truststore.password\": null,\n- \"log.retention.ms\": \"604800000\"\n+ \"listener.name.listener_host.ssl.keystore.password\": \"123foo\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n \"follower.replication.throttled.rate\": \"600000000\",\n- \"leader.replication.throttled.rate\": \"700000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n- \"log.retention.ms\": null\n+ \"leader.replication.throttled.rate\": \"600000000\",\n+ \"listener.name.listener_host.ssl.keystore.password\": \"123foo\",\n+ \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"600000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": false\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"broker\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"1\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"600000000\",\n- \"listener.name.listener_host.ssl.keystore.password\": null,\n \"log.retention.ms\": \"604800000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }"
]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n+ \"configs\": {\n+ \"background.threads\": \"12\",\n+ \"follower.replication.throttled.rate\": \"700000000\",\n+ \"leader.replication.throttled.rate\": \"700000000\"\n+ },\n \"deleteUndefinedConfigs\": true\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"700000000\",\n+ \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"700000000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"700000000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n+ \"follower.replication.throttled.rate\": \"700000000\",\n \"leader.replication.throttled.rate\": \"700000000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"700000000\",\n- \"leader.replication.throttled.rate\": \"700000000\"\n+ \"background.threads\": \"12\"\n },\n \"deleteUndefinedConfigs\": false\n }\n }\n",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"700000000\",\n- \"leader.replication.throttled.rate\": \"700000000\"\n+ \"background.threads\": \"12\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }\n"
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n+ \"configs\": {\n+ \"background.threads\": \"12\",\n+ \"follower.replication.throttled.rate\": \"700000000\",\n+ \"leader.replication.throttled.rate\": \"700000000\"\n+ },\n \"deleteUndefinedConfigs\": true\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"700000000\",\n+ \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"700000000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"600000000\",\n \"leader.replication.throttled.rate\": \"700000000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n \"background.threads\": \"12\",\n+ \"follower.replication.throttled.rate\": \"700000000\",\n \"leader.replication.throttled.rate\": \"700000000\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"700000000\",\n- \"leader.replication.throttled.rate\": \"700000000\"\n+ \"background.threads\": \"12\"\n },\n \"deleteUndefinedConfigs\": false\n }\n }",
" {\n \"apiVersion\": \"v1\",\n \"kind\": \"brokers\",\n \"metadata\": {\n \"labels\": {\n \"baz\": \"qux\",\n \"foo\": \"bar\"\n },\n \"name\": \"core.operators.brokers.applier.foo\"\n },\n \"spec\": {\n \"configs\": {\n- \"background.threads\": \"12\",\n- \"follower.replication.throttled.rate\": \"700000000\",\n- \"leader.replication.throttled.rate\": \"700000000\"\n+ \"background.threads\": \"12\"\n },\n \"deleteUndefinedConfigs\": true\n }\n }"
]
42 changes: 28 additions & 14 deletions core/test/fixtures/diff/test2.diff
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,37 @@
- 2
- ],
- [
2,
3
],
[
- 2,
- 3
- ],
- [
- 3,
- 1
- ],
- [
- 1,
- 2
- ],
- [
- 2,
- 3
+ 2,
+ 3
+ ],
+ [
+ 2,
3,
1
],
[
+ 3,
1,
2
],
[
+ 1
+ ],
+ [
+ 3,
+ 1,
2,
3
+ 2
+ ],
+ [
+ 1,
+ 2,
+ 3
+ ],
+ [
+ 2,
Expand Down
12 changes: 6 additions & 6 deletions core/test/fixtures/diff/test3.diff
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"assignments": [
[
- 1
- ],
- [
+ 1,
+ 2
2
],
[
- 2
+ 2,
+ 3
],
[
- 3
3
+ ],
+ [
+ 3,
+ 1
]
Expand Down
2 changes: 1 addition & 1 deletion core/test/fixtures/jsondiff/test1.diff
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
+ "bar",
+ "baz"
]
}
}
2 changes: 1 addition & 1 deletion core/test/fixtures/jsondiff/test2.diff
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
+ "bar",
+ "baz"
+ ]
+}
+}
Loading

0 comments on commit 97df38f

Please sign in to comment.