Skip to content

Commit d690664

Browse files
authored
fix(limits): Adapt defaults and expose evict interval (#17808)
1 parent 7445efa commit d690664

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

docs/sources/shared/configuration.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ ingest_limits:
911911
# have not been updated within this window are considered inactive and not
912912
# counted towards limits.
913913
# CLI flag: -ingest-limits.active-window
914-
[active_window: <duration> | default = 1h]
914+
[active_window: <duration> | default = 2h]
915915

916916
# The time window for rate calculation. This should match the window used in
917917
# Prometheus rate() queries for consistency.
@@ -923,6 +923,10 @@ ingest_limits:
923923
# CLI flag: -ingest-limits.bucket-size
924924
[bucket_size: <duration> | default = 1m]
925925

926+
# The interval at which old streams are evicted.
927+
# CLI flag: -ingest-limits.eviction-interval
928+
[eviction_interval: <duration> | default = 30m]
929+
926930
# The number of partitions for the Kafka topic used to read and write stream
927931
# metadata. It is fixed, not a maximum.
928932
# CLI flag: -ingest-limits.num-partitions

pkg/limits/config.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
)
1313

1414
const (
15-
DefaultActiveWindow = 1 * time.Hour
15+
DefaultActiveWindow = 2 * time.Hour
1616
DefaultRateWindow = 5 * time.Minute
1717
DefaultBucketSize = 1 * time.Minute
18+
DefaultEvictInterval = 30 * time.Minute
1819
DefaultNumPartitions = 64
1920
)
2021

@@ -38,6 +39,9 @@ type Config struct {
3839
// memory.
3940
BucketSize time.Duration `yaml:"bucket_size"`
4041

42+
// EvictionInterval defines the interval at which old streams are evicted.
43+
EvictionInterval time.Duration `yaml:"eviction_interval"`
44+
4145
// The number of partitions for the Kafka topic used to read and write stream metadata.
4246
// It is fixed, not a maximum.
4347
NumPartitions int `yaml:"num_partitions"`
@@ -77,6 +81,12 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
7781
DefaultBucketSize,
7882
"The size of the buckets used to calculate stream rates. Smaller buckets provide more precise rates but require more memory.",
7983
)
84+
f.DurationVar(
85+
&cfg.EvictionInterval,
86+
"ingest-limits.eviction-interval",
87+
DefaultEvictInterval,
88+
"The interval at which old streams are evicted.",
89+
)
8090
f.IntVar(
8191
&cfg.NumPartitions,
8292
"ingest-limits.num-partitions",
@@ -98,6 +108,9 @@ func (cfg *Config) Validate() error {
98108
if cfg.RateWindow < cfg.BucketSize {
99109
return errors.New("rate-window must be greater than or equal to bucket-size")
100110
}
111+
if cfg.EvictionInterval <= 0 {
112+
return errors.New("eviction-interval must be greater than 0")
113+
}
101114
if cfg.NumPartitions <= 0 {
102115
return errors.New("num-partitions must be greater than 0")
103116
}

pkg/limits/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (s *Service) running(ctx context.Context) error {
321321
// evictOldStreamsPeriodic runs a periodic job that evicts old streams.
322322
// It runs two evictions per window size.
323323
func (s *Service) evictOldStreamsPeriodic(ctx context.Context) {
324-
ticker := time.NewTicker(s.cfg.ActiveWindow / 2)
324+
ticker := time.NewTicker(s.cfg.EvictionInterval)
325325
defer ticker.Stop()
326326
for {
327327
select {

pkg/limits/store_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func TestUsageStore_Evict(t *testing.T) {
179179
s.clock = clock
180180
s1 := streamUsage{hash: 0x1, lastSeenAt: clock.Now().UnixNano()}
181181
s.set("tenant1", s1)
182-
s2 := streamUsage{hash: 0x2, lastSeenAt: clock.Now().Add(-61 * time.Minute).UnixNano()}
182+
s2 := streamUsage{hash: 0x2, lastSeenAt: clock.Now().Add(-121 * time.Minute).UnixNano()}
183183
s.set("tenant1", s2)
184184
s3 := streamUsage{hash: 0x3, lastSeenAt: clock.Now().UnixNano()}
185185
s.set("tenant2", s3)

0 commit comments

Comments
 (0)