From 3a419576efc8b750f98fb8290f0727fc76ec5fde Mon Sep 17 00:00:00 2001 From: Roman Karpenko Date: Thu, 12 Dec 2024 16:20:11 +0200 Subject: [PATCH 1/2] improve regexp performance in `loki.process`: call fmt only if debug is enabled --- CHANGELOG.md | 1 + internal/component/loki/process/stages/regex.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 439e9610cd..35acfba9df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ Main (unreleased) - Use a forked `github.com/goccy/go-json` module 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) ### Bugfixes diff --git a/internal/component/loki/process/stages/regex.go b/internal/component/loki/process/stages/regex.go index 531c230515..27c7daf381 100644 --- a/internal/component/loki/process/stages/regex.go +++ b/internal/component/loki/process/stages/regex.go @@ -112,7 +112,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 level.Debug(r.logger).Enabled() { + level.Debug(r.logger).Log("msg", "extracted data debug in regex stage", "extracted data", fmt.Sprintf("%v", extracted)) + } } // Name implements Stage From 69030d964caed2de55d25114a42218b18ae0cd30 Mon Sep 17 00:00:00 2001 From: Roman Karpenko Date: Fri, 20 Dec 2024 16:19:58 +0200 Subject: [PATCH 2/2] improve regexp performance in `loki.process`: call fmt only if debug is enabled. fix debug check --- internal/component/loki/process/stages/regex.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/component/loki/process/stages/regex.go b/internal/component/loki/process/stages/regex.go index 27c7daf381..29fe561250 100644 --- a/internal/component/loki/process/stages/regex.go +++ b/internal/component/loki/process/stages/regex.go @@ -112,7 +112,7 @@ func (r *regexStage) Process(labels model.LabelSet, extracted map[string]interfa extracted[name] = match[i] } } - if level.Debug(r.logger).Enabled() { + if level.DebugValue() { level.Debug(r.logger).Log("msg", "extracted data debug in regex stage", "extracted data", fmt.Sprintf("%v", extracted)) } }