Skip to content
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

LogQL: Selective label extraction with logfmt pipeline #3355

Closed
dannykopping opened this issue Feb 18, 2021 · 6 comments · Fixed by #6675
Closed

LogQL: Selective label extraction with logfmt pipeline #3355

dannykopping opened this issue Feb 18, 2021 · 6 comments · Fixed by #6675
Labels
component/logql keepalive An issue or PR that will be kept alive and never marked as stale. type/feature Something new we should do

Comments

@dannykopping
Copy link
Contributor

dannykopping commented Feb 18, 2021

Is your feature request related to a problem? Please describe.
When processing log lines through the logfmt pipeline, I would like to be able to selectively extract labels in the same way that the regexp and now json pipelines allow.

Describe the solution you'd like
Instead of extracting all labels from a logfmt-formatted line, I only want selected labels extracted.

The log line:

level=error ts=2021-02-12T19:18:10.037940878Z caller=client.go:294 component=client host=observability-loki-gateway msg="final error sending batch" status=400 error="server returned HTTP status 400 Bad Request (400): entry with timestamp 2021-02-12 19:18:08.917452 +0000 UTC ignored, reason: 'entry out of order' for stream..."

Will produce the following labels with a plain | logfmt pipeline:

  • level=”error”
  • ts=”2021-02-12T19:18:10.037940878Z”
  • caller=”client.go:294”
  • component=”client”
  • host=”observability-loki-gateway”
  • msg="final error sending batch"
  • status=”400”
  • error="server returned HTTP status 400 Bad Request (400): entry with timestamp 2021-02-12 19:18:08.917452 +0000 UTC ignored, reason: 'entry out of order' for stream..."

That’s a lot of labels!

If I only need the msg and status labels extracted, it would be nice to use the following:

{app=”foo”} | logfmt msg,status will produce:

  • msg="final error sending batch"
  • status=”400”

Or even {app=”foo”} | logfmt message="msg", status if I wanted to rename the label:

  • message="final error sending batch"
  • status=”400”

Describe alternatives you've considered
N/A

Additional context

@dannykopping dannykopping added the keepalive An issue or PR that will be kept alive and never marked as stale. label Feb 18, 2021
@dannykopping dannykopping self-assigned this Feb 18, 2021
@hugree
Copy link

hugree commented Mar 1, 2021

This is a very nice idea... same with JSON.

@owen-d owen-d added revivable We'd like this, but not immediately prioritizing. Please open a PR! component/logql keepalive An issue or PR that will be kept alive and never marked as stale. type/feature Something new we should do and removed keepalive An issue or PR that will be kept alive and never marked as stale. revivable We'd like this, but not immediately prioritizing. Please open a PR! labels Sep 9, 2021
@btaani
Copy link
Contributor

btaani commented Jun 1, 2022

I would like to work on this one if no one else is

@dannykopping
Copy link
Contributor Author

@btaani go for it 👍

@dannykopping dannykopping removed their assignment Jun 2, 2022
@danpoltawski
Copy link
Contributor

👍 to this idea - when trying to do metric queries extracting all the logfmt labels creates a huge amount of cardinality

@winston0410
Copy link

New to LogQL. Does that mean that right now we have to output all value from logfmt? Can we filter out values there?

@btaani
Copy link
Contributor

btaani commented Oct 17, 2022

@winston0410 The goal of this feature is to be able to select only the desired labels from a log line instead of displaying all of them. The PR is already under review: #6675

owen-d pushed a commit that referenced this issue Feb 22, 2023
<!--  Thanks for sending a pull request!  Before submitting:

1. Read our CONTRIBUTING.md guide
2. Name your PR as `<Feature Area>: Describe your change`.
a. Do not end the title with punctuation. It will be added in the
changelog.
b. Start with an imperative verb. Example: Fix the latency between
System A and System B.
  c. Use sentence case, not title case.
d. Use a complete phrase or sentence. The PR title will appear in a
changelog, so help other people understand what your change will be.
3. Rebase your PR if it gets out of sync with main
-->

**What this PR does / why we need it**:
This PR introduces extracting labels from a log line in `logfmt`, with
an extra option to rename them.

For example, this query:
```
{app=”foo”} | logfmt msg,status
```

will extract the labels `msg` and `status` from the following logfmt
line:
```
level=error ts=2021-02-12T19:18:10.037940878Z caller=client.go:294 component=client host=observability-loki-gateway msg="final error sending batch" status=400 error="server returned HTTP status 400 Bad Request (400): entry with timestamp 2021-02-12 19:18:08.917452 +0000 UTC ignored, reason: 'entry out of order' for stream..."
```
With the following results:
```
msg="final error sending batch"
status=”400”
```
--------------
Another possible scenario with label renaming:
```
{app=”foo”} | logfmt message="msg", status
```
That produces the following results:
```
message="final error sending batch"
status=”400”
```


**Which issue(s) this PR fixes**:
Fixes #3355 

**Special notes for your reviewer**:

<!--
Note about CHANGELOG entries, if a change adds:
* an important feature
* fixes an issue present in a previous release, 
* causes a change in operation that would be useful for an operator of
Loki to know
then please add a CHANGELOG entry.

For documentation changes, build changes, simple fixes etc please skip
this step. We are attempting to curate a changelog of the most relevant
and important changes to be easier to ingest by end users of Loki.

Note about the upgrade guide, if this changes:
* default configuration values
* metric names or label names
* changes existing log lines such as the metrics.go query output line
* configuration parameters 
* anything to do with any API
* any other change that would require special attention or extra steps
to upgrade
Please document clearly what changed AND what needs to be done in the
upgrade guide.
-->
**Checklist**
- [x] Documentation added
- [x] Tests updated
- [x] Is this an important fix or new feature? Add an entry in the
`CHANGELOG.md`.
- [x] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`

---------

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
Co-authored-by: Christian Haudum <christian.haudum@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/logql keepalive An issue or PR that will be kept alive and never marked as stale. type/feature Something new we should do
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants