diff --git a/CHANGELOG.md b/CHANGELOG.md index e9aed6a44d..a033cec980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ Main (unreleased) - Upgrade `github.com/goccy/go-json` to v0.10.4, which reduces the memory consumption of an Alloy instance by 20MB. If Alloy is running certain otelcol components, this reduction will not apply. (@ptodev) +- improve performance in regexp component: call fmt only if debug is enabled (@r0ka) - Update `prometheus.write.queue` library for performance increases in cpu. (@mattdurham) diff --git a/internal/component/loki/process/stages/regex.go b/internal/component/loki/process/stages/regex.go index 531c230515..48eba6a80d 100644 --- a/internal/component/loki/process/stages/regex.go +++ b/internal/component/loki/process/stages/regex.go @@ -83,13 +83,17 @@ 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 } @@ -97,13 +101,17 @@ func (r *regexStage) Process(labels model.LabelSet, extracted map[string]interfa } 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 } @@ -112,7 +120,9 @@ func (r *regexStage) Process(labels model.LabelSet, extracted map[string]interfa extracted[name] = match[i] } } - level.Debug(r.logger).Log("msg", "extracted data debug in regex stage", "extracted data", fmt.Sprintf("%v", extracted)) + if Debug { + level.Debug(r.logger).Log("msg", "extracted data debug in regex stage", "extracted data", fmt.Sprintf("%v", extracted)) + } } // Name implements Stage