Skip to content
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

Ordered tag comparisons result in spurious diff reports #239

Closed
rainest opened this issue Dec 2, 2020 · 0 comments · Fixed by #240
Closed

Ordered tag comparisons result in spurious diff reports #239

rainest opened this issue Dec 2, 2020 · 0 comments · Fixed by #240
Assignees
Labels
bug Something isn't working

Comments

@rainest
Copy link
Contributor

rainest commented Dec 2, 2020

Originally reported internally in Jira ticket FTI-2097. tl;dr deck thinks tag order matters and tries to act on it. Tag order doesn't actually matter, and deck shouldn't do that.

Assume you have a service whose tags are [foo,bar]. When dumping configuration using --select-tag foo, deck stores the resulting dump with something like the following:

_format_version: "1.1"
_info:
  select_tags:
  - foo
services:
- host: example.com
  name: example
  ...
  tags:
  - bar

Although the selected tag is present on the object, it isn't shown directly in the object itself, only in the _info block. When syncing, tag information is rebuilt, and tags are added to internal Go structures in some specific order. This order does not necessarily match the order reported by the admin API on Cassandra-backed nodes for an unknown reason (I did not investigate to see exactly how deck and Cassandra build the tag set to determine why this happens, but observed that it did happen with the provided customer data).

Because deck represents the tag set internally with an ordered slice, this order change can result in a reported difference when we compare the target object (from the dump YAML) to the current object (from the admin API). This difference in the Go structures does not correspond to an actual difference, however: the tags associated with a Kong object are sets, and their order is only an artifact of the YAML or JSON arrays we use to display them.

Although the apparent difference has no logical impact on the object, deck perceives one, and will attempt to update or create it (depending on whether or not you ignore IDs, I think). This either results in unnecessary requests or a failure (attempting to create a new object with the "correct" tag order will usually result in a uniqueness conflict).

Although the example code here is for services, this can affect any taggable entity (i.e. most entities).

@rainest rainest added the bug Something isn't working label Dec 2, 2020
@rainest rainest self-assigned this Dec 2, 2020
rainest pushed a commit that referenced this issue Dec 3, 2020
Ignore tag order for object comparisons by sorting the string slices
that contain them before checking object equality. This avoids issues
with spurious diffs resulting in unnecessary changes when the tag order
constructed by deck from dump YAML and the tag order reported by admin
API JSON differ.

Because Kong object tags are logical string sets, their order does not
matter: it is only a perceived difference because JSON and YAML lack set
types and represent them with ordered arrays.

Fix #239
rainest pushed a commit that referenced this issue Dec 3, 2020
Ignore tag order for object comparisons by sorting the string slices
that contain them before checking object equality. This avoids issues
with spurious diffs resulting in unnecessary changes when the tag order
constructed by deck from dump YAML and the tag order reported by admin
API JSON differ.

Because Kong object tags are logical string sets, their order does not
matter: it is only a perceived difference because JSON and YAML lack set
types and represent them with ordered arrays.

Fix #239
hbagdi pushed a commit that referenced this issue Dec 7, 2020
Ignore tag order for object comparisons by sorting the string slices
that contain them before checking object equality. This avoids issues
with spurious diffs resulting in unnecessary changes when the tag order
constructed by deck from dump YAML and the tag order reported by admin
API JSON differ.

Because Kong object tags are logical string sets, their order does not
matter: it is only a perceived difference because JSON and YAML lack set
types and represent them with ordered arrays.

Fix #239
From #240
rainest pushed a commit that referenced this issue Apr 21, 2021
Ignore tag order for object comparisons by sorting the string slices
that contain them before checking object equality. This avoids issues
with spurious diffs resulting in unnecessary changes when the tag order
constructed by deck from dump YAML and the tag order reported by admin
API JSON differ.

Because Kong object tags are logical string sets, their order does not
matter: it is only a perceived difference because JSON and YAML lack set
types and represent them with ordered arrays.

Fix #239
From #240
AntoineJac pushed a commit that referenced this issue Jan 23, 2024
Ignore tag order for object comparisons by sorting the string slices
that contain them before checking object equality. This avoids issues
with spurious diffs resulting in unnecessary changes when the tag order
constructed by deck from dump YAML and the tag order reported by admin
API JSON differ.

Because Kong object tags are logical string sets, their order does not
matter: it is only a perceived difference because JSON and YAML lack set
types and represent them with ordered arrays.

Fix #239
From #240
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant