Skip to content

Commit

Permalink
instead of replacing the label with the _extracted suffix removed, ju…
Browse files Browse the repository at this point in the history
…st add a new label with the suffix removed. This will avoid any cases where a legit json or logfmt key ends with _extracted.
  • Loading branch information
slim-bean committed Feb 24, 2021
1 parent 51de82a commit 3847305
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/logql/log/parser_hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,22 @@ func (p *parserHint) NoLabels() bool {

// newParserHint creates a new parser hint using the list of labels that are seen and required in a query.
func newParserHint(requiredLabelNames, groups []string, without, noLabels bool, metricLabelName string) *parserHint {
//Strip the _extracted suffix from any labels which had collisions with stream labels
for i := range requiredLabelNames {
requiredLabelNames[i] = strings.TrimSuffix(requiredLabelNames[i], "_extracted")
// If a parsed label collides with a stream label we add the `_extracted` suffix to it, however hints
// are used by the parsers before we know they will collide with a stream label and hence before the
// _extracted suffix is added. Therefore we must strip the _extracted suffix from any required labels
// that were parsed from somewhere in the query, say in a filter or an aggregation clause.
// Because it's possible for a valid json or logfmt key to already end with _extracted, we'll just
// leave the existing entry ending with _extracted but also add a version with the suffix removed.
extractedLabels := []string{}
for _, l := range requiredLabelNames {
if strings.HasSuffix(l, "_extracted") {
extractedLabels = append(extractedLabels, strings.TrimSuffix(l, "_extracted"))
}
}
if len(extractedLabels) > 0 {
requiredLabelNames = append(requiredLabelNames, extractedLabels...)
}

if len(groups) > 0 {
requiredLabelNames = append(requiredLabelNames, groups...)
}
Expand Down

0 comments on commit 3847305

Please sign in to comment.