Skip to content

Commit

Permalink
fix: attempt non-string label filtering when errors are present
Browse files Browse the repository at this point in the history
  • Loading branch information
MasslessParticle committed Mar 27, 2024
1 parent 04398a1 commit a845194
Showing 1 changed file with 24 additions and 21 deletions.
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

0 comments on commit a845194

Please sign in to comment.