Skip to content

Commit

Permalink
improve regexp performance in loki.process: call fmt only if debug …
Browse files Browse the repository at this point in the history
…is enabled. surrounding rest of the debug messages with debug check.
  • Loading branch information
r0ka committed Jan 7, 2025
1 parent d4ed45a commit 9c2d6c4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions internal/component/loki/process/stages/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,35 @@ func (r *regexStage) Process(labels model.LabelSet, extracted map[string]interfa

if r.config.Source != nil {
if _, ok := extracted[*r.config.Source]; !ok {
level.Debug(r.logger).Log("msg", "source does not exist in the set of extracted values", "source", *r.config.Source)
if Debug {
level.Debug(r.logger).Log("msg", "source does not exist in the set of extracted values", "source", *r.config.Source)
}
return
}

value, err := getString(extracted[*r.config.Source])
if err != nil {
level.Debug(r.logger).Log("msg", "failed to convert source value to string", "source", *r.config.Source, "err", err, "type", reflect.TypeOf(extracted[*r.config.Source]))
if Debug {
level.Debug(r.logger).Log("msg", "failed to convert source value to string", "source", *r.config.Source, "err", err, "type", reflect.TypeOf(extracted[*r.config.Source]))
}
return
}

input = &value
}

if input == nil {
level.Debug(r.logger).Log("msg", "cannot parse a nil entry")
if Debug {
level.Debug(r.logger).Log("msg", "cannot parse a nil entry")
}
return
}

match := r.expression.FindStringSubmatch(*input)
if match == nil {
level.Debug(r.logger).Log("msg", "regex did not match", "input", *input, "regex", r.expression)
if Debug {
level.Debug(r.logger).Log("msg", "regex did not match", "input", *input, "regex", r.expression)
}
return
}

Expand Down

0 comments on commit 9c2d6c4

Please sign in to comment.