Skip to content

Commit 8c50692

Browse files
committed
chore: Call shardstreams.Config by value instead of by reference (#12915)
Use `shardstreams.Config` by value instead of by reference to fix docs generation. Our `docs-generator` tool relies on the struct address/references to assume that flags are present. Using this config by value fixes it. (cherry picked from commit afd9e36)
1 parent 167b468 commit 8c50692

File tree

9 files changed

+37
-19
lines changed

9 files changed

+37
-19
lines changed

docs/sources/shared/configuration.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -3281,12 +3281,22 @@ ruler_remote_write_sigv4_config:
32813281
# Deprecated: Use deletion_mode per tenant configuration instead.
32823282
[allow_deletes: <boolean>]
32833283

3284+
# Define streams sharding behavior.
32843285
shard_streams:
3285-
[enabled: <boolean>]
3286+
# Automatically shard streams to keep them under the per-stream rate limit.
3287+
# Sharding is dictated by the desired rate.
3288+
# CLI flag: -shard-streams.enabled
3289+
[enabled: <boolean> | default = true]
32863290

3287-
[logging_enabled: <boolean>]
3291+
# Whether to log sharding streams behavior or not. Not recommended for
3292+
# production environments.
3293+
# CLI flag: -shard-streams.logging-enabled
3294+
[logging_enabled: <boolean> | default = false]
32883295

3289-
[desired_rate: <int>]
3296+
# Threshold used to cut a new shard. Default (1536KB) means if a rate is above
3297+
# 1536KB/s, it will be sharded into two streams.
3298+
# CLI flag: -shard-streams.desired-rate
3299+
[desired_rate: <int> | default = 1536KB]
32903300

32913301
[blocked_queries: <blocked_query...>]
32923302

pkg/distributor/distributor.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func (d *Distributor) shardStream(stream logproto.Stream, pushSize int, tenantID
559559
return d.divideEntriesBetweenShards(tenantID, shardCount, shardStreamsCfg, stream)
560560
}
561561

562-
func (d *Distributor) divideEntriesBetweenShards(tenantID string, totalShards int, shardStreamsCfg *shardstreams.Config, stream logproto.Stream) []KeyedStream {
562+
func (d *Distributor) divideEntriesBetweenShards(tenantID string, totalShards int, shardStreamsCfg shardstreams.Config, stream logproto.Stream) []KeyedStream {
563563
derivedStreams := d.createShards(stream, totalShards, tenantID, shardStreamsCfg)
564564

565565
for i := 0; i < len(stream.Entries); i++ {
@@ -571,7 +571,7 @@ func (d *Distributor) divideEntriesBetweenShards(tenantID string, totalShards in
571571
return derivedStreams
572572
}
573573

574-
func (d *Distributor) createShards(stream logproto.Stream, totalShards int, tenantID string, shardStreamsCfg *shardstreams.Config) []KeyedStream {
574+
func (d *Distributor) createShards(stream logproto.Stream, totalShards int, tenantID string, shardStreamsCfg shardstreams.Config) []KeyedStream {
575575
var (
576576
streamLabels = labelTemplate(stream.Labels, d.logger)
577577
streamPattern = streamLabels.String()
@@ -779,7 +779,7 @@ func (d *Distributor) parseStreamLabels(vContext validationContext, key string,
779779
// based on the rate stored in the rate store and will store the new evaluated number of shards.
780780
//
781781
// desiredRate is expected to be given in bytes.
782-
func (d *Distributor) shardCountFor(logger log.Logger, stream *logproto.Stream, pushSize int, tenantID string, streamShardcfg *shardstreams.Config) int {
782+
func (d *Distributor) shardCountFor(logger log.Logger, stream *logproto.Stream, pushSize int, tenantID string, streamShardcfg shardstreams.Config) int {
783783
if streamShardcfg.DesiredRate.Val() <= 0 {
784784
if streamShardcfg.LoggingEnabled {
785785
level.Error(logger).Log("msg", "invalid desired rate", "desired_rate", streamShardcfg.DesiredRate.String())

pkg/distributor/limits.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Limits interface {
2525
DiscoverServiceName(userID string) []string
2626
DiscoverLogLevels(userID string) bool
2727

28-
ShardStreams(userID string) *shardstreams.Config
28+
ShardStreams(userID string) shardstreams.Config
2929
IngestionRateStrategy() string
3030
IngestionRateBytes(userID string) float64
3131
IngestionBurstSizeBytes(userID string) int

pkg/distributor/ratestore_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,15 @@ type fakeOverrides struct {
341341
func (c *fakeOverrides) AllByUserID() map[string]*validation.Limits {
342342
return map[string]*validation.Limits{
343343
"ingester0": {
344-
ShardStreams: &shardstreams.Config{
344+
ShardStreams: shardstreams.Config{
345345
Enabled: c.enabled,
346346
},
347347
},
348348
}
349349
}
350350

351-
func (c *fakeOverrides) ShardStreams(_ string) *shardstreams.Config {
352-
return &shardstreams.Config{
351+
func (c *fakeOverrides) ShardStreams(_ string) shardstreams.Config {
352+
return shardstreams.Config{
353353
Enabled: c.enabled,
354354
}
355355
}

pkg/distributor/shardstreams/config.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
)
88

99
type Config struct {
10-
Enabled bool `yaml:"enabled" json:"enabled"`
11-
LoggingEnabled bool `yaml:"logging_enabled" json:"logging_enabled"`
10+
Enabled bool `yaml:"enabled" json:"enabled" doc:"description=Automatically shard streams to keep them under the per-stream rate limit. Sharding is dictated by the desired rate."`
11+
12+
LoggingEnabled bool `yaml:"logging_enabled" json:"logging_enabled" doc:"description=Whether to log sharding streams behavior or not. Not recommended for production environments."`
1213

1314
// DesiredRate is the threshold used to shard the stream into smaller pieces.
1415
// Expected to be in bytes.
15-
DesiredRate flagext.ByteSize `yaml:"desired_rate" json:"desired_rate"`
16+
DesiredRate flagext.ByteSize `yaml:"desired_rate" json:"desired_rate" doc:"description=Threshold used to cut a new shard. Default (1536KB) means if a rate is above 1536KB/s, it will be sharded into two streams."`
1617
}
1718

1819
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, fs *flag.FlagSet) {

pkg/ingester/instance_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ func (f fakeLimits) AllByUserID() map[string]*validation.Limits {
10491049

10501050
func TestStreamShardingUsage(t *testing.T) {
10511051
setupCustomTenantLimit := func(perStreamLimit string) *validation.Limits {
1052-
shardStreamsCfg := &shardstreams.Config{Enabled: true, LoggingEnabled: true}
1052+
shardStreamsCfg := shardstreams.Config{Enabled: true, LoggingEnabled: true}
10531053
shardStreamsCfg.DesiredRate.Set("6MB") //nolint:errcheck
10541054

10551055
customTenantLimits := &validation.Limits{}

pkg/ingester/limiter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Limits interface {
2727
MaxLocalStreamsPerUser(userID string) int
2828
MaxGlobalStreamsPerUser(userID string) int
2929
PerStreamRateLimit(userID string) validation.RateLimit
30-
ShardStreams(userID string) *shardstreams.Config
30+
ShardStreams(userID string) shardstreams.Config
3131
}
3232

3333
// Limiter implements primitives to get the maximum number of streams

pkg/loki/loki.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type Config struct {
9797
CompactorConfig compactor.Config `yaml:"compactor,omitempty"`
9898
CompactorHTTPClient compactorclient.HTTPConfig `yaml:"compactor_client,omitempty" doc:"hidden"`
9999
CompactorGRPCClient compactorclient.GRPCConfig `yaml:"compactor_grpc_client,omitempty"`
100-
LimitsConfig validation.Limits `yaml:"limits_config,omitempty"`
100+
LimitsConfig validation.Limits `yaml:"limits_config"`
101101
Worker worker.Config `yaml:"frontend_worker,omitempty"`
102102
TableManager index.TableManagerConfig `yaml:"table_manager,omitempty"`
103103
MemberlistKV memberlist.KVConfig `yaml:"memberlist"`

pkg/validation/limits.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ type Limits struct {
185185
// Deprecated
186186
CompactorDeletionEnabled bool `yaml:"allow_deletes" json:"allow_deletes" doc:"deprecated|description=Use deletion_mode per tenant configuration instead."`
187187

188-
ShardStreams *shardstreams.Config `yaml:"shard_streams" json:"shard_streams"`
188+
ShardStreams shardstreams.Config `yaml:"shard_streams" json:"shard_streams" doc:"description=Define streams sharding behavior."`
189189

190190
BlockedQueries []*validation.BlockedQuery `yaml:"blocked_queries,omitempty" json:"blocked_queries,omitempty"`
191191

@@ -376,7 +376,14 @@ func (l *Limits) RegisterFlags(f *flag.FlagSet) {
376376
),
377377
)
378378

379-
l.ShardStreams = &shardstreams.Config{}
379+
_ = l.BloomCompactorMaxBloomSize.Set(defaultBloomCompactorMaxBloomSize)
380+
f.Var(&l.BloomCompactorMaxBloomSize, "bloom-compactor.max-bloom-size",
381+
fmt.Sprintf(
382+
"Experimental. The maximum bloom size per log stream. A log stream whose generated bloom filter exceeds this size will be discarded. A value of 0 sets an unlimited size. Default is %s.",
383+
defaultBloomCompactorMaxBloomSize,
384+
),
385+
)
386+
380387
l.ShardStreams.RegisterFlagsWithPrefix("shard-streams", f)
381388

382389
f.IntVar(&l.VolumeMaxSeries, "limits.volume-max-series", 1000, "The default number of aggregated series or labels that can be returned from a log-volume endpoint")
@@ -879,7 +886,7 @@ func (o *Overrides) DeletionMode(userID string) string {
879886
return o.getOverridesForUser(userID).DeletionMode
880887
}
881888

882-
func (o *Overrides) ShardStreams(userID string) *shardstreams.Config {
889+
func (o *Overrides) ShardStreams(userID string) shardstreams.Config {
883890
return o.getOverridesForUser(userID).ShardStreams
884891
}
885892

0 commit comments

Comments
 (0)