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

fix: correct _extracted logic in detected fields #14064

Merged
merged 9 commits into from
Sep 6, 2024

Conversation

trevorwhitney
Copy link
Collaborator

What this PR does / why we need it:

Explore logs passes multiple parsers in the query to detected_fields, which has resulted in a whole bunch of unknown edge cases. This fixes:

  1. making sure _extracted is correctly applied when the incoming stream labels already have extracted fields because of the formatters included in the query
  2. Returning the Parsed values on the entry being parsed if not additional parsed values are found
  3. Correctly apply logfmt and json parsers to already parsed fields
  4. Drop special error labels from detected fields response

Which issue(s) this PR fixes:
Fixes #14063

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • 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
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@trevorwhitney trevorwhitney requested a review from a team as a code owner September 5, 2024 22:04
@trevorwhitney trevorwhitney changed the title Svennergr/detected fields only parsed check fix: correct _extracted logic in detected fields Sep 5, 2024
}
}
func parseEntry(entry push.Entry, lbls *logql_log.LabelsBuilder) (map[string][]string, []string) {
logFmtParser := logql_log.NewLogfmtParser(false, false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was part of the problem, we had strict turned on previously

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to only initialise the parser (call logFmtParser := logql_log.NewLogfmtParser(false, false)) when we need it? I.e. move it somewhere here https://github.com/grafana/loki/pull/14064/files#diff-a0b881d1b7b99f439716f189b50eef90ccdaea00845b087c0dbce0e148aa2c0eR1339

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, can do... missed that when I change the order to try json first

@@ -1403,12 +1420,28 @@ func streamsForFieldDetection(i iter.EntryIterator, size uint32) (logqlmodel.Str
// If lastEntry.Unix < 0 this is the first pass through the loop and we should output the line.
// Then check to see if the entry is equal to, or past a forward step
if lastEntry.Unix() < 0 || shouldOutput {
stream, ok := streams[streamLabels]
allLbls, err := syntax.ParseLabels(streamLabels)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the logic added here is to extract the stream labels from the additional labels via parsing and structured metadata. this likely needs a test

need this now that logfmt isn't strict
Copy link
Contributor

@svennergr svennergr left a comment

Choose a reason for hiding this comment

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

Nice, LGTM!

@trevorwhitney trevorwhitney added type/bug Somehing is not working as expected product-approved backport k218 labels Sep 6, 2024
@grafanabot
Copy link
Collaborator

This PR must be merged before a backport PR will be created.

2 similar comments
@grafanabot
Copy link
Collaborator

This PR must be merged before a backport PR will be created.

@grafanabot
Copy link
Collaborator

This PR must be merged before a backport PR will be created.

@trevorwhitney trevorwhitney merged commit 1b3ba53 into main Sep 6, 2024
63 checks passed
@trevorwhitney trevorwhitney deleted the svennergr/detected-fields-only-parsed-check branch September 6, 2024 19:05
grafanabot pushed a commit that referenced this pull request Sep 6, 2024
Co-authored-by: Sven Grossmann <[email protected]>
(cherry picked from commit 1b3ba53)
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.

detected_fields API response with multiple parsers
3 participants