Skip to content

refactor: convert route groups to a sync map#4966

Merged
ultrotter merged 7 commits intoprometheus:mainfrom
ultrotter:groupssyncmap
Feb 11, 2026
Merged

refactor: convert route groups to a sync map#4966
ultrotter merged 7 commits intoprometheus:mainfrom
ultrotter:groupssyncmap

Conversation

@ultrotter
Copy link
Copy Markdown
Contributor

@ultrotter ultrotter commented Feb 5, 2026

This allows us to avoid taking the lock in most cases.

The exception is that we still need it when adding an aggrgroup, as multiple goroutines might be otherwise trying to add theirs, for the same fp.

This applies on top of #4958

@ultrotter ultrotter changed the title refactoring: convert route groups to a sync map refactor: convert route groups to a sync map Feb 5, 2026
Copy link
Copy Markdown
Contributor

@siavashs siavashs left a comment

Choose a reason for hiding this comment

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

Looks great!
Just added a few comments.

Comment thread dispatch/dispatch.go
Comment thread dispatch/dispatch.go
Comment thread dispatch/dispatch.go Outdated
@ultrotter ultrotter requested a review from siavashs February 6, 2026 12:48
Copy link
Copy Markdown
Contributor

@SoloJacobs SoloJacobs left a comment

Choose a reason for hiding this comment

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

Good enough for me. However, there is a commit missing from #4958 .

Comment thread dispatch/dispatch.go Outdated
Comment thread store/store.go Outdated
@ultrotter
Copy link
Copy Markdown
Contributor Author

Good enough for me. However, there is a commit missing from #4958 .

I know, but it rebases cleanly, so I was hoping github will happily rebase it once I merge that one :)

Comment thread store/store.go Outdated
@ultrotter ultrotter force-pushed the groupssyncmap branch 2 times, most recently from 2c3baf6 to 7870bac Compare February 11, 2026 13:18
@ultrotter
Copy link
Copy Markdown
Contributor Author

Good enough for me. However, there is a commit missing from #4958 .

Yes, I was waiting to finalize before rebasing! It's done now!

Guido Trotter added 7 commits February 11, 2026 10:32
This allows us to avoid taking the lock in most cases.

The exception is that we still need it when adding an aggrgroup, as
multiple goroutines might be otherwise trying to add theirs, for the
same fp.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
…ion when the map is dirty

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Use sync map swap operations, with max retries, to avoid one extra lock.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
This allows us to allocate the right amount of memory when we read them
for Groups(). The number may not be precise, but will work in most
cases.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
…e copy extra size

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Signed-off-by: Guido Trotter <guido@hudson-trading.com>
- just pass a DestroyIfEmpty value to DeleteIfNotModified
- never destroy in GC

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
@ultrotter ultrotter merged commit 92567c8 into prometheus:main Feb 11, 2026
7 checks passed
@ultrotter ultrotter deleted the groupssyncmap branch February 11, 2026 16:12
SoloJacobs pushed a commit to SoloJacobs/alertmanager that referenced this pull request Mar 15, 2026
* [dispatcher] Convert groups to a sync map

This allows us to avoid taking the lock in most cases.

The exception is that we still need it when adding an aggrgroup, as
multiple goroutines might be otherwise trying to add theirs, for the
same fp.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* Even with sync map snapshot the groups in each route to avoid contention when the map is dirty

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* Remove lock outside of the per route sync.Map

Use sync map swap operations, with max retries, to avoid one extra lock.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* keep groups len in routeAggrGroups

This allows us to allocate the right amount of memory when we read them
for Groups(). The number may not be precise, but will work in most
cases.

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* Use a constant instead of the concurrency field for the Groups() slice copy extra size

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* cast sync.Map Range value to aggrGroup only once

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

* Remove 'dontdestroy' property of the alert store

- just pass a DestroyIfEmpty value to DeleteIfNotModified
- never destroy in GC

Signed-off-by: Guido Trotter <guido@hudson-trading.com>

---------

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
Co-authored-by: Guido Trotter <guido@hudson-trading.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants