Skip to content

feat: support log line content filtering via RELABEL_CONFIGS#98

Open
Omerlustig wants to merge 4 commits into
grafana:mainfrom
Omerlustig:feat/relabel-drop-log-lines
Open

feat: support log line content filtering via RELABEL_CONFIGS#98
Omerlustig wants to merge 4 commits into
grafana:mainfrom
Omerlustig:feat/relabel-drop-log-lines

Conversation

@Omerlustig

Copy link
Copy Markdown

Summary

  • Enable RELABEL_CONFIGS to filter log entries based on log line content using a synthetic __log_line__ label, allowing users to drop noisy lines (e.g. END RequestId:) before they are sent to Loki
  • The __log_line__ label is injected temporarily before relabeling and stripped afterwards so it never reaches Loki
  • Fix a pre-existing bug where ScratchBuilder.Sort() was missing before relabel.Process, which uses binary search internally and produced non-deterministic results on unsorted labels

How it works

Users can now use the existing RELABEL_CONFIGS env var with source_labels: ["__log_line__"] to match against log line content:

[{"source_labels":["__log_line__"],"regex":"END RequestId:.*","action":"drop"}]

All Prometheus relabel actions (drop, keep, replace, labeldrop, etc.) are supported. Existing label-only relabel configs continue to work unchanged.

Test plan

  • TestBatchAddDropsLogLinesViaRelabelConfig — drop action on log line content
  • TestBatchAddKeepsEntriesWithNoRelabelConfig — no-op when no configs set
  • TestBatchAddKeepActionFiltersLogLines — keep action filtering
  • TestBatchAddLogLineLabelNotInOutput__log_line__ label never in output
  • TestBatchAddLabelOnlyRelabelStillWorks — backward compat with label-only relabel
  • TestBatchAddDropMultiplePatterns — multi-pattern drop
  • All 39 existing tests continue to pass

🤖 Generated with Claude Code

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jeschkies jeschkies left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should rather support Promtail stages https://grafana.com/docs/loki/latest/send-data/promtail/stages/

Comment thread pkg/main.go
@Omerlustig Omerlustig force-pushed the feat/relabel-drop-log-lines branch from 299a023 to 5a8cb01 Compare June 13, 2026 08:48
Omerlustig pushed a commit to Omerlustig/lambda-promtail that referenced this pull request Jun 13, 2026
Salvage the relabel Sort() bug fix, drop the redundant __log_line__
feature in favor of native Promtail drop stages, and make stage-based
filtering deployable via a new loki_stage_configs Terraform var.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Omerlustig

Copy link
Copy Markdown
Author

Reworked per review feedback:

  • Dropped the synthetic __log_line__ relabel approach in favor of native Promtail pipeline stages, as suggested. Content-based filtering now uses the existing LOKI_STAGE_CONFIGS drop stage (already wired through LokiStages.Process), so no new filtering mechanism is introduced.
  • Added a loki_stage_configs Terraform variable + LOKI_STAGE_CONFIGS env wiring so the stage-based filtering is actually deployable, plus an end-to-end regression test (TestDropStageViaLokiStageConfigs) and a README section documenting the drop-stage recipe.
  • Restored the original applyLabels documentation (the file is now unchanged from main except the items below).
  • Kept a one-line builder.Sort() before relabel.Process to match its existing // Sort labels as required by Process comment (a no-op under the default slicelabels build, load-bearing under stringlabels).
  • Rebased onto current main.

Will sign the CLA.

omer-lustig-fpt and others added 4 commits June 13, 2026 11:54
applyRelabelConfigs carried the comment "Sort labels as required by
Process" but never called Sort(). Add the call so the code matches the
comment and stays correct under stringlabels builds (Loki's default),
where Labels.Get does a sorted binary search. No-op under this repo's
default slicelabels build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The code already reads LOKI_STAGE_CONFIGS but it was not settable via
Terraform. Plumb it through so deploys can configure Promtail pipeline
stages (e.g. a drop stage) to filter log lines by content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Omerlustig Omerlustig force-pushed the feat/relabel-drop-log-lines branch from 5a8cb01 to b55ed54 Compare June 13, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants