Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/logql/log/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ func (b *LabelsBuilder) HasErrorDetails() bool {
return b.errDetails != ""
}

// HasInCategory returns whether the builder has the given key in the specified category.
func (b *LabelsBuilder) HasInCategory(key string, category LabelCategory) bool {
return labelsContain(b.add[category], key)
}

// BaseHas returns the base labels have the given key
func (b *LabelsBuilder) BaseHas(key string) bool {
return b.base.Has(key)
Expand Down
18 changes: 9 additions & 9 deletions pkg/logql/log/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (j *JSONParser) parseLabelValue(key, value []byte, dataType jsonparser.Valu
return nil
}

if j.lbs.BaseHas(sanitizedKey) {
if j.lbs.BaseHas(sanitizedKey) || j.lbs.HasInCategory(sanitizedKey, StructuredMetadataLabel) {
sanitizedKey = sanitizedKey + duplicateSuffix
}

Expand Down Expand Up @@ -179,7 +179,7 @@ func (j *JSONParser) parseLabelValue(key, value []byte, dataType jsonparser.Valu
return string(sanitized), true
})

if j.lbs.BaseHas(keyString) {
if j.lbs.BaseHas(keyString) || j.lbs.HasInCategory(keyString, StructuredMetadataLabel) {
j.prefixBuffer[prefixLen] = make([]byte, 0, len(key)+len(duplicateSuffix))
j.prefixBuffer[prefixLen] = append(j.prefixBuffer[prefixLen], key...)
j.prefixBuffer[prefixLen] = append(j.prefixBuffer[prefixLen], duplicateSuffix...)
Expand Down Expand Up @@ -339,7 +339,7 @@ func (r *RegexpParser) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]byte
continue
}

if lbs.BaseHas(key) {
if lbs.BaseHas(key) || lbs.HasInCategory(key, StructuredMetadataLabel) {
key = fmt.Sprintf("%s%s", key, duplicateSuffix)
}

Expand Down Expand Up @@ -406,7 +406,7 @@ func (l *LogfmtParser) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]byte
continue
}

if lbs.BaseHas(key) {
if lbs.BaseHas(key) || lbs.HasInCategory(key, StructuredMetadataLabel) {
key = key + duplicateSuffix
}

Expand Down Expand Up @@ -478,7 +478,7 @@ func (l *PatternParser) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]byt
names := l.names[:len(matches)]
for i, m := range matches {
name := names[i]
if lbs.BaseHas(name) {
if lbs.BaseHas(name) || lbs.HasInCategory(name, StructuredMetadataLabel) {
name = name + duplicateSuffix
}

Expand Down Expand Up @@ -544,7 +544,7 @@ func (l *LogfmtExpressionParser) Process(_ int64, line []byte, lbs *LabelsBuilde
keys := make(map[string]string, len(l.expressions))
for id, paths := range l.expressions {
keys[id] = fmt.Sprintf("%v", paths...)
if !lbs.BaseHas(id) {
if !lbs.BaseHas(id) && !lbs.HasInCategory(id, StructuredMetadataLabel) {
lbs.Set(ParsedLabel, id, "")
}
}
Expand Down Expand Up @@ -599,7 +599,7 @@ func (l *LogfmtExpressionParser) Process(_ int64, line []byte, lbs *LabelsBuilde
}

if _, ok := l.expressions[key]; ok {
if lbs.BaseHas(key) {
if lbs.BaseHas(key) || lbs.HasInCategory(key, StructuredMetadataLabel) {
key = key + duplicateSuffix
if lbs.ParserLabelHints().Extracted(key) || !lbs.ParserLabelHints().ShouldExtract(key) {
// Don't extract duplicates if we don't have to
Expand Down Expand Up @@ -693,7 +693,7 @@ func (j *JSONExpressionParser) Process(_ int64, line []byte, lbs *LabelsBuilder)
return identifier, true
})

if lbs.BaseHas(key) {
if lbs.BaseHas(key) || lbs.HasInCategory(key, StructuredMetadataLabel) {
key = key + duplicateSuffix
}

Expand Down Expand Up @@ -808,7 +808,7 @@ func (u *UnpackParser) unpack(entry []byte, lbs *LabelsBuilder) ([]byte, error)
return string(key), true
})

if lbs.BaseHas(key) {
if lbs.BaseHas(key) || lbs.HasInCategory(key, StructuredMetadataLabel) {
key = key + duplicateSuffix
}

Expand Down
Loading
Loading