-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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: align semantics of metric and log query label extraction #11587
Changes from 6 commits
14f2ead
3eacd02
877d0a1
aa99dfd
ed0d366
147dbab
0cfd58c
ed74485
c08fbe1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,10 +58,6 @@ type Hints struct { | |
} | ||
|
||
func (p *Hints) ShouldExtract(key string) bool { | ||
if len(p.requiredLabels) == 0 { | ||
return true | ||
} | ||
|
||
for _, l := range p.extracted { | ||
if l == key { | ||
return false | ||
|
@@ -74,7 +70,7 @@ func (p *Hints) ShouldExtract(key string) bool { | |
} | ||
} | ||
|
||
return false | ||
return len(p.requiredLabels) == 0 | ||
} | ||
|
||
func (p *Hints) ShouldExtractPrefix(prefix string) bool { | ||
|
@@ -95,19 +91,25 @@ func (p *Hints) NoLabels() bool { | |
} | ||
|
||
func (p *Hints) RecordExtracted(key string) { | ||
for _, l := range p.requiredLabels { | ||
if l == key { | ||
p.extracted = append(p.extracted, key) | ||
return | ||
} | ||
} | ||
p.extracted = append(p.extracted, key) | ||
} | ||
|
||
func (p *Hints) AllRequiredExtracted() bool { | ||
if len(p.requiredLabels) == 0 { | ||
if len(p.requiredLabels) == 0 || len(p.extracted) < len(p.requiredLabels) { | ||
return false | ||
} | ||
return len(p.extracted) == len(p.requiredLabels) | ||
|
||
found := map[string]interface{}{} | ||
for _, e := range p.extracted { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might also be worth seeing if it's faster to just compare the list in two loops. It's an n^2 algorithm but it might be faster because it requires no allocs. (This function is called a lot) It's the same reason |
||
for _, l := range p.requiredLabels { | ||
if e == l { | ||
found[l] = nil | ||
break | ||
} | ||
} | ||
} | ||
|
||
return len(p.requiredLabels) == len(found) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is needed because previously, |
||
} | ||
|
||
func (p *Hints) Reset() { | ||
|
@@ -172,9 +174,6 @@ func NewParserHint(requiredLabelNames, groups []string, without, noLabels bool, | |
return ph | ||
} | ||
|
||
ph.requiredLabels = hints | ||
ph.shouldPreserveError = containsError(hints) | ||
|
||
return &Hints{requiredLabels: hints, extracted: extracted, shouldPreserveError: containsError(hints)} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to say
found := make(map[string]struct{}, len(p.requiredLabels))
here.struct{}
is smaller thaninterface{}
and initializing with the max len we'll need ensures only one alloc