Skip to content

Conversation

@kelnage
Copy link
Contributor

@kelnage kelnage commented Dec 31, 2025

Lambda-Promtail currently offers the ability to manipulate labels using Prometheus's relabelling configuration, but does not yet support Promtail/Loki's wider pipeline stages.

This PR introduces support for them into Lambda-Promtail. It provides support for all the stages defined in the logentry package (Apache 2 licensed), using a JSON configuration format (rather than YAML that pipeline requires, given the existing use of JSON configuration).

The implementation adds a new LokiStages type that stores all the relevant stages defined in the LOKI_STAGE_CONFIGS environment variable. It updates the batch processing to process each entry with the configured stages and adds the processed entries to the batch that is sent.

The current Stages implementation is predominantly designed for asynchronous usage (via channels and Run), but Lambda-Promtail uses synchronous functions. If a synchronous Process function is provided for a stage, it will be used, otherwise we use short-lived channels to achieve the equivalent. Where asynchronous calls are used, a PIPELINE_TIMEOUT configures the maximum duration (currently 1s by default) before producing an empty entry.

Closes #7

Copy link
Collaborator

@jeschkies jeschkies left a comment

Choose a reason for hiding this comment

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

Nice work. I have a few suggestions.

}
entry = processedEntry
case <-time.After(timeout):
return stages.Entry{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you log the timeout? Do we have to cancel anything here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I was debating whether, if the processing does timeout, we should simply return the unprocessed entry rather than an dropping the result - thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should error instead. Otherwise users will get unexpected log lines.

pkg/promtail.go Outdated
stream.Entries = append(stream.Entries, e.entry)
// Apply pipeline stages to entry
stageEntry := stages.Entry{
Extracted: map[string]interface{}{},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is this used? I'm wondering if we could avoud allocations here.

Copy link
Contributor Author

@kelnage kelnage Jan 2, 2026

Choose a reason for hiding this comment

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

I included this based on this code - from the comment above, it seems some stages expect the Extracted labels to already contain any existing labels. I agree it's not ideal, but not something I think we can necessarily fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On a bit of reflection, I've updated this code to skip this entire step if there are no processing stages specified.

Copy link
Collaborator

@jeschkies jeschkies left a comment

Choose a reason for hiding this comment

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

Ok. I have only a nit. Also, we should follo up with some documentation.

pkg/main.go Outdated
batchSize, _ = strconv.Atoi(batch)
}

pipelineTimeout = 1 * time.Second
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you make a constant for the default at the top?

@kelnage kelnage force-pushed the kelnage/process-loki-stages branch from 8a9e387 to 1cf0ea0 Compare January 5, 2026 17:34
@jeschkies jeschkies merged commit a180134 into grafana:main Jan 5, 2026
9 checks passed
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.

[lambda-promtail] Add support for log line parsing/transforming/filtering feature

2 participants