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: attempt non-string label filtering when errors are present #12378

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions pkg/logql/log/label_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,18 @@ func NewBytesLabelFilter(t LabelFilterType, name string, b uint64) *BytesLabelFi
}

func (d *BytesLabelFilter) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]byte, bool) {
if lbs.HasErr() {
// if there's an error only the string matchers can filter it out.
return line, true
}
v, ok := lbs.Get(d.Name)
if !ok {
// we have not found this label.
return line, false
}
value, err := humanize.ParseBytes(v)
if err != nil {
lbs.SetErr(errLabelFilter)
lbs.SetErrorDetails(err.Error())
// Don't overwrite what might be a more useful error
if !lbs.HasErr() {
lbs.SetErr(errLabelFilter)
lbs.SetErrorDetails(err.Error())
}
return line, true
}
switch d.Type {
Expand All @@ -202,7 +201,9 @@ func (d *BytesLabelFilter) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]
case LabelFilterLesserThanOrEqual:
return line, value <= d.Value
default:
lbs.SetErr(errLabelFilter)
if !lbs.HasErr() {
lbs.SetErr(errLabelFilter)
}
return line, true
}
}
Expand Down Expand Up @@ -240,19 +241,18 @@ func NewDurationLabelFilter(t LabelFilterType, name string, d time.Duration) *Du
}

func (d *DurationLabelFilter) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]byte, bool) {
if lbs.HasErr() {
// if there's an error only the string matchers can filter out.
return line, true
}
v, ok := lbs.Get(d.Name)
if !ok {
// we have not found this label.
return line, false
}
value, err := time.ParseDuration(v)
if err != nil {
lbs.SetErr(errLabelFilter)
lbs.SetErrorDetails(err.Error())
// Don't overwrite what might be a more useful error
if !lbs.HasErr() {
lbs.SetErr(errLabelFilter)
lbs.SetErrorDetails(err.Error())
}
return line, true
}
switch d.Type {
Expand All @@ -269,7 +269,9 @@ func (d *DurationLabelFilter) Process(_ int64, line []byte, lbs *LabelsBuilder)
case LabelFilterLesserThanOrEqual:
return line, value <= d.Value
default:
lbs.SetErr(errLabelFilter)
if !lbs.HasErr() {
lbs.SetErr(errLabelFilter)
}
return line, true
}
}
Expand Down Expand Up @@ -302,19 +304,18 @@ func NewNumericLabelFilter(t LabelFilterType, name string, v float64) *NumericLa
}

func (n *NumericLabelFilter) Process(_ int64, line []byte, lbs *LabelsBuilder) ([]byte, bool) {
if lbs.HasErr() {
// if there's an error only the string matchers can filter out.
return line, true
}
v, ok := lbs.Get(n.Name)
if !ok {
// we have not found this label.
return line, false
}
value, err := strconv.ParseFloat(v, 64)
if err != nil {
lbs.SetErr(errLabelFilter)
lbs.SetErrorDetails(err.Error())
// Don't overwrite what might be a more useful error
if !lbs.HasErr() {
lbs.SetErr(errLabelFilter)
lbs.SetErrorDetails(err.Error())
}
return line, true
}
switch n.Type {
Expand All @@ -331,7 +332,9 @@ func (n *NumericLabelFilter) Process(_ int64, line []byte, lbs *LabelsBuilder) (
case LabelFilterLesserThanOrEqual:
return line, value <= n.Value
default:
lbs.SetErr(errLabelFilter)
if !lbs.HasErr() {
lbs.SetErr(errLabelFilter)
}
return line, true
}

Expand Down
Loading