Skip to content

Sort event metadata in notifications - #1369

Merged
stefanprodan merged 1 commit into
fluxcd:mainfrom
artur-chopikian:fix/sort-event-metadata-fields
Aug 22, 2026
Merged

Sort event metadata in notifications#1369
stefanprodan merged 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
Contributor

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
@artur-chopikian

Copy link
Copy Markdown
Contributor Author

Hello! @stefanprodan, can you check this one? Any comments?

@stefanprodan stefanprodan added the area/alerting Alerting related issues and PRs label Aug 22, 2026

@stefanprodan stefanprodan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @artur-chopikian

@stefanprodan
stefanprodan merged commit 6df4b92 into fluxcd:main Aug 22, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/alerting Alerting related issues and PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants