Skip to content

feat: add dry-run mode for checking limits in distributors #16754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/sources/shared/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2557,6 +2557,11 @@ otlp_config:
# CLI flag: -distributor.ingest-limits-enabled
[ingest_limits_enabled: <boolean> | default = false]

# Enable dry-run mode where limits are checked the ingest-limits service, but
# not enforced. Defaults to false.
# CLI flag: -distributor.ingest-limits-dry-run-enabled
[ingest_limits_dry_run_enabled: <boolean> | default = false]

tenant_topic:
# Enable the tenant topic tee, which writes logs to Kafka topics based on
# tenant IDs instead of using multitenant topics/partitions.
Expand Down
19 changes: 12 additions & 7 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ type Config struct {

OTLPConfig push.GlobalOTLPConfig `yaml:"otlp_config"`

KafkaEnabled bool `yaml:"kafka_writes_enabled"`
IngesterEnabled bool `yaml:"ingester_writes_enabled"`
IngestLimitsEnabled bool `yaml:"ingest_limits_enabled"`
KafkaEnabled bool `yaml:"kafka_writes_enabled"`
IngesterEnabled bool `yaml:"ingester_writes_enabled"`
IngestLimitsEnabled bool `yaml:"ingest_limits_enabled"`
IngestLimitsDryRunEnabled bool `yaml:"ingest_limits_dry_run_enabled"`

KafkaConfig kafka.Config `yaml:"-"`

Expand All @@ -121,6 +122,7 @@ func (cfg *Config) RegisterFlags(fs *flag.FlagSet) {
fs.BoolVar(&cfg.KafkaEnabled, "distributor.kafka-writes-enabled", false, "Enable writes to Kafka during Push requests.")
fs.BoolVar(&cfg.IngesterEnabled, "distributor.ingester-writes-enabled", true, "Enable writes to Ingesters during Push requests. Defaults to true.")
fs.BoolVar(&cfg.IngestLimitsEnabled, "distributor.ingest-limits-enabled", false, "Enable checking limits against the ingest-limits service. Defaults to false.")
fs.BoolVar(&cfg.IngestLimitsDryRunEnabled, "distributor.ingest-limits-dry-run-enabled", false, "Enable dry-run mode where limits are checked the ingest-limits service, but not enforced. Defaults to false.")
}

func (cfg *Config) Validate() error {
Expand Down Expand Up @@ -696,12 +698,15 @@ func (d *Distributor) PushWithResolver(ctx context.Context, req *logproto.PushRe
}

if d.cfg.IngestLimitsEnabled {
exceedsLimits, _, err := d.exceedsLimits(ctx, tenantID, streams, d.doExceedsLimitsRPC)
exceedsLimits, reasons, err := d.exceedsLimits(ctx, tenantID, streams, d.doExceedsLimitsRPC)
if err != nil {
level.Error(d.logger).Log("msg", "failed to check if request exceeds limits, request has been accepted", "err", err)
}
if exceedsLimits {
level.Info(d.logger).Log("msg", "request exceeded limits", "tenant", tenantID)
} else if exceedsLimits {
if d.cfg.IngestLimitsDryRunEnabled {
level.Debug(d.logger).Log("msg", "request exceeded limits", "tenant", tenantID)
} else {
return nil, httpgrpc.Error(http.StatusBadRequest, strings.Join(reasons, ","))
}
}
}

Expand Down