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

Metadata to labels result and filtering support #9702

Merged
merged 22 commits into from
Jul 24, 2023

Conversation

salvacorts
Copy link
Contributor

@salvacorts salvacorts commented Jun 13, 2023

What this PR does / why we need it:
In #9700, we support encoding and decoding metadata for each entry into the chunks. This PR adds support for returning metadata labels for matching entries in a query to the returned LabelResults. It also supports filtering out logs by metadata labels.

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/upgrading/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR

@salvacorts salvacorts changed the title Salvacorts/metadata to labels result and filtering Metadata to labels result and filtering support Jun 13, 2023
@salvacorts salvacorts changed the base branch from main to salvacorts/metadata-to-chunk June 26, 2023 12:38
@salvacorts salvacorts force-pushed the salvacorts/metadata-to-chunk branch from 0fa7568 to 21df77b Compare July 13, 2023 09:39
Base automatically changed from salvacorts/metadata-to-chunk to main July 18, 2023 06:37
@salvacorts salvacorts force-pushed the salvacorts/metadata-to-labelsResult-and-filtering branch from accd132 to 2826cee Compare July 18, 2023 10:23
@@ -23,8 +23,8 @@ type StreamPipeline interface {
BaseLabels() LabelsResult
// Process processes a log line and returns the transformed line and the labels.
// The buffer returned for the log line can be reused on subsequent calls to Process and therefore must be copied.
Process(ts int64, line []byte) (resultLine []byte, resultLabels LabelsResult, matches bool)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering if the nonIndexedLabels argument should be variadic. I decided to make it variadic so we didn't have to refactor all the tests calling Process without any non-indexed labels. I also think it makes sense to be variadic since non-indexed labels are optional. Happy to change my mind tho. Wdyt?

@salvacorts salvacorts marked this pull request as ready for review July 19, 2023 07:40
@salvacorts salvacorts requested a review from a team as a code owner July 19, 2023 07:40
@salvacorts salvacorts force-pushed the salvacorts/metadata-to-labelsResult-and-filtering branch from aac6753 to 1e6f49b Compare July 19, 2023 13:18
Copy link
Contributor

@sandeepsukhani sandeepsukhani left a comment

Choose a reason for hiding this comment

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

The changes look good to me. I think it would be good to add some tests with non-indexed labels to TestNewLineSampleExtractor and Test_labelSampleExtractor_Extract

si.currTs = ts
si.currLine = line
si.currMetadataLabels = metaLabels
si.currMetadataLabels = nonIndexedLabels
Copy link
Contributor

Choose a reason for hiding this comment

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

please rename currMetadataLabels to currNonIndexedLabels. maybe in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a separate PR in the oven renaming all those "metadata" references.

@@ -80,22 +80,25 @@ type streamLineSampleExtractor struct {
builder *LabelsBuilder
}

func (l *streamLineSampleExtractor) Process(ts int64, line []byte) (float64, LabelsResult, bool) {
func (l *streamLineSampleExtractor) Process(ts int64, line []byte, metadataLabels ...labels.Label) (float64, LabelsResult, bool) {
l.builder.Reset()
Copy link
Contributor

Choose a reason for hiding this comment

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

it changes the logic. previously if stage is NoopStage we return l.LineExtractor(line), l.builder.GroupedLabels(), true that uses values from the builder, otherwise we rest it and continue processing

Copy link
Contributor

@sandeepsukhani sandeepsukhani Jul 24, 2023

Choose a reason for hiding this comment

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

If I read the code correctly, it should not cause any problems because Reset just clears any buffered changes done on top of base labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reset just clears any buffered changes done on top of base labels.

Correct, that's my understanding as well

Copy link
Contributor

@vlad-diachenko vlad-diachenko left a comment

Choose a reason for hiding this comment

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

Lgtm

Copy link
Contributor

@sandeepsukhani sandeepsukhani left a comment

Choose a reason for hiding this comment

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

I have left just one nit. Good to merge it once it is addressed.

pkg/logql/log/pipeline.go Outdated Show resolved Hide resolved
Co-authored-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>
@salvacorts salvacorts merged commit 1d04cd5 into main Jul 24, 2023
@salvacorts salvacorts deleted the salvacorts/metadata-to-labelsResult-and-filtering branch July 24, 2023 08:31
sandeepsukhani pushed a commit that referenced this pull request Jul 26, 2023
**What this PR does / why we need it**:
In #9700, we support encoding and decoding metadata for each entry into
the chunks. This PR adds support for returning metadata labels for
matching entries in a query to the returned LabelResults. It also
supports filtering out logs by metadata labels.

**Special notes for your reviewer**:

**Checklist**
- [x] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [ ] Documentation added
- [x] Tests updated
- [ ] `CHANGELOG.md` updated
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`
- [ ] For Helm chart changes bump the Helm chart version in
`production/helm/loki/Chart.yaml` and update
`production/helm/loki/CHANGELOG.md` and
`production/helm/loki/README.md`. [Example
PR](d10549e)

---------

Co-authored-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>
(cherry picked from commit 1d04cd5)
salvacorts added a commit that referenced this pull request Jul 28, 2023
#10082)

**What this PR does / why we need it**:

In #9702 we added support for
returning non-indexed labels in the labels results. The problem is that
non-indexed labels may overwrite stream labels if both are named the
same way. This PR fixes this by adding an `_extracted` suffix if the
non-indexed label is already present in the stream labels.

**Special notes for your reviewer**:

**Checklist**
- [ ] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [ ] Documentation added
- [x] Tests updated
- [ ] `CHANGELOG.md` updated
- [ ] If the change is worth mentioning in the release notes, add
`add-to-release-notes` label
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/setup/upgrade/_index.md`
- [ ] For Helm chart changes bump the Helm chart version in
`production/helm/loki/Chart.yaml` and update
`production/helm/loki/CHANGELOG.md` and
`production/helm/loki/README.md`. [Example
PR](d10549e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants