Skip to content

Commit a40bb88

Browse files
adding aggregation method
Signed-off-by: Lucas-Fernandes-Martins <lucasfmartins16@gmail.com>
1 parent c9f6369 commit a40bb88

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

pkg/epp/framework/interface/datalayer/state_store.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import (
2626
type StateKey string
2727

2828
// CrossReplicaStore is a cross-EPP state store for sharing state across replicas.
29-
// Implementations own the sync mechanism (e.g., Redis pub/sub, gossip) and the
30-
// aggregation strategy (e.g., sum for in-flight load, union for cache state).
29+
// Implementations own the sync mechanism (e.g., Redis pub/sub, gossip).
3130
type CrossReplicaStore interface {
3231
fwkplugin.Plugin
3332

@@ -65,4 +64,8 @@ type CrossReplicaSpec struct {
6564
// endpoint. The runtime calls this closure after Produce to snapshot
6665
// the current local state and Set it into the store.
6766
Supply func(endpointID string) func() Cloneable
67+
68+
// Aggregate combines per-replica values into a single aggregate.
69+
// Called by the store's Get to fold values from all replicas.
70+
Aggregate func(values []any) any
6871
}

pkg/epp/framework/plugins/requestcontrol/dataproducer/inflightload/producer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@ func (p *InFlightLoadProducer) CrossReplicaState() datalayer.CrossReplicaSpec {
292292
}
293293
}
294294
},
295+
Aggregate: func(values []any) any {
296+
total := &attrconcurrency.InFlightLoad{}
297+
for _, v := range values {
298+
if ifl, ok := v.(*attrconcurrency.InFlightLoad); ok {
299+
total.Requests += ifl.Requests
300+
total.Tokens += ifl.Tokens
301+
}
302+
}
303+
return total
304+
},
295305
}
296306
}
297307

0 commit comments

Comments
 (0)