Skip to content

Commit e750160

Browse files
Guido Trotterultrotter
authored andcommitted
dispatch: cache the formatted aggregation group key
Build the group key once from the route key and immutable group labels when constructing an aggregation group avoiding repeated label sorting, formatting, and string Sprintf every time it's needed. Signed-off-by: Guido Trotter <guido@hudson-trading.com>
1 parent ae96210 commit e750160

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎dispatch/dispatch.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ type aggrGroup struct {
614614
opts *RouteOpts
615615
logger *slog.Logger
616616
routeID string
617-
routeKey string
617+
groupKey string
618618
matchers labels.Matchers
619619

620620
alerts *store.Alerts
@@ -667,7 +667,7 @@ func newAggrGroup(
667667
ag := &aggrGroup{
668668
labels: labels,
669669
routeID: r.ID(),
670-
routeKey: r.Key(),
670+
groupKey: fmt.Sprintf("%s:%s", r.Key(), labels),
671671
matchers: r.Matchers,
672672
opts: &r.RouteOpts,
673673
timeout: to,
@@ -697,8 +697,10 @@ func (ag *aggrGroup) fingerprint() model.Fingerprint {
697697
return ag.labels.Fingerprint()
698698
}
699699

700+
// GroupKey returns the key built from the route and immutable group labels.
701+
// Note that multiple aggregation groups can have the same key.
700702
func (ag *aggrGroup) GroupKey() string {
701-
return fmt.Sprintf("%s:%s", ag.routeKey, ag.labels)
703+
return ag.groupKey
702704
}
703705

704706
func (ag *aggrGroup) String() string {

0 commit comments

Comments
 (0)