Skip to content

Sort event metadata in notifications - #1369

Open
artur-chopikian wants to merge 1 commit into
fluxcd:mainfrom
artur-chopikian:fix/sort-event-metadata-fields
Open

Sort event metadata in notifications#1369
artur-chopikian wants to merge 1 commit into
fluxcd:mainfrom
artur-chopikian:fix/sort-event-metadata-fields

Conversation

@artur-chopikian

@artur-chopikian artur-chopikian commented Aug 11, 2026

Copy link
Copy Markdown

Notification fields are built by ranging over event.Metadata. Go randomises map iteration, so the same event produces a different field order on every send:

helmrelease/purple-backend.purple    cluster / env / revision / image-tag
helmrelease/purple-webcli.purple     image-tag / cluster / env / revision

Same four keys, two orders, seconds apart. The value being looked for moves between messages.

teams.go already sorts its Adaptive Card facts with slices.SortFunc, so the guarantee exists — it was not applied elsewhere, including to the deprecated connector payload in the same file.

Applied to the notifiers whose output is read in order: slack, discord, rocket, teams, google_chat, zoom, webex, grafana, lark, matrix, telegram. The iterate-sorted-keys form is used throughout because five of them concatenate strings and cannot be sorted afterwards.

Not applied to incidentio and sentry, where metadata goes into a map, nor to datadog and otel, where tags and attributes are sets.

TestSlack_PostFieldsAreSorted posts one event ten times and asserts the order each time. It fails on main. make tidy fmt vet and make test pass, working tree clean.

@artur-chopikian
artur-chopikian marked this pull request as ready for review August 11, 2026 07:30
Notification fields are built by ranging over event.Metadata. Go
randomises map iteration, so the same event produces a different field
order on every send and the value being looked for moves between
messages.

Iterating slices.Sorted(maps.Keys(...)) makes the order stable and
alphabetical. slices is already used in this package and the module is
on Go 1.26, so no helper is needed.

teams.go already does this for its Adaptive Card payload, sorting the
built facts with slices.SortFunc. The guarantee existed but was not
applied elsewhere, including to the deprecated connector payload in the
same file.

Applied to the notifiers whose output is read in order: slack, discord,
rocket, teams, google_chat, zoom, webex, grafana, lark, matrix,
telegram. The iterate-sorted-keys form is used throughout because five
of them concatenate strings and cannot be sorted after the fact.

Not applied to incidentio and sentry, where metadata goes into a map and
order cannot be observed, nor to datadog and otel, where tags and
attributes are sets.

Signed-off-by: Artur Chopikian <arturchopikian@gmail.com>
Assisted-by: claude-code/claude-opus-5
@artur-chopikian
artur-chopikian force-pushed the fix/sort-event-metadata-fields branch from d45c315 to 376eefe Compare August 11, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant