Skip to content

Add Opsgenie alias field for alert deduplication - #1292

Merged
matheuscscp merged 3 commits into
fluxcd:mainfrom
cairon-ab:opsgenie-alias-dedup
Aug 7, 2026
Merged

Add Opsgenie alias field for alert deduplication#1292
matheuscscp merged 3 commits into
fluxcd:mainfrom
cairon-ab:opsgenie-alias-dedup

Conversation

@cairon-ab

Copy link
Copy Markdown
Contributor

Summary

Set the alias field on Opsgenie alerts using a SHA-256 hash of the involved object's Kind, Namespace, Name, and event Reason. This allows Opsgenie to deduplicate repeated alerts for the same source instead of creating new pages for each firing.

Changes

  • Added Alias field to OpsgenieAlert struct with json:"alias,omitempty"
  • Added generateOpsgenieAlias() function that creates a deterministic SHA-256 hash from the event's InvolvedObject.Kind, InvolvedObject.Namespace, InvolvedObject.Name, and Reason
  • Wired the alias into Post() so every alert carries a stable alias
  • Added comprehensive tests: TestOpsgenie_PostAlias (verifies alias in HTTP payload across multiple scenarios) and TestGenerateOpsgenieAlias (determinism, length, uniqueness)

Why

Currently, Opsgenie creates a new alert for every notification event, even when it's for the same object and reason. The Opsgenie Alert API supports an alias field that acts as a deduplication key — alerts with the same alias are grouped as a single incident.

By hashing Kind/Namespace/Name/Reason, we ensure:

  • Determinism: Same event source always produces the same alias
  • Deduplication: Repeated firings update the existing alert instead of paging again
  • Differentiation: Different reasons (e.g. ReconciliationFailed vs HealthCheckFailed) create separate alerts
  • Size safety: The 64-char hex hash stays well within Opsgenie's 512-char alias limit

Fixes #460

Comment thread internal/notifier/opsgenie.go
Set the alias field on Opsgenie alerts using a SHA-256 hash of the
involved object's Kind, Namespace, Name, and event Reason. This allows
Opsgenie to deduplicate repeated alerts for the same source instead of
creating new pages for each firing.

Fixes fluxcd#460

Signed-off-by: Cairon <cairon-ab@users.noreply.github.com>
Without the provider UID in the alias hash, alerts from different
clusters sharing the same involved object (e.g.
Kustomization/flux-system/flux-system) would produce identical aliases
and Opsgenie would aggregate them into a single incident.

Thread the ProviderUID from notifierOptions into the Opsgenie struct
and prepend it to the alias hash input so each cluster's Provider
resource produces a unique alias.

Signed-off-by: cairon-ab <cairon-ab@users.noreply.github.com>
Signed-off-by: Cairon <cairon-ab@users.noreply.github.com>
@matheuscscp
matheuscscp force-pushed the opsgenie-alias-dedup branch from f322c46 to 1a93ec3 Compare August 7, 2026 11:18
@stefanprodan stefanprodan added the area/alerting Alerting related issues and PRs label Aug 7, 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

Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
@matheuscscp
matheuscscp merged commit 9b1030c into fluxcd:main Aug 7, 2026
5 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.

Opsgenie Alias for deduplication of alerts

3 participants