From 8a56ef81034dc0f917e132fd3cd0189891797348 Mon Sep 17 00:00:00 2001 From: Marc Guasch Date: Fri, 6 Sep 2024 14:39:32 +0200 Subject: [PATCH] Only init metrics if needed (#40703) --- winlogbeat/eventlog/wineventlog.go | 4 +++- winlogbeat/eventlog/wineventlog_experimental.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/winlogbeat/eventlog/wineventlog.go b/winlogbeat/eventlog/wineventlog.go index d558a477845..e418f22bf06 100644 --- a/winlogbeat/eventlog/wineventlog.go +++ b/winlogbeat/eventlog/wineventlog.go @@ -317,7 +317,9 @@ func (l *winEventLog) Open(state checkpoint.EventLogState) error { var err error // we need to defer metrics initialization since when the event log // is used from winlog input it would register it twice due to CheckConfig calls - l.metrics = newInputMetrics(l.channelName, l.id) + if l.metrics == nil { + l.metrics = newInputMetrics(l.channelName, l.id) + } if len(state.Bookmark) > 0 { bookmark, err = win.CreateBookmarkFromXML(state.Bookmark) } else if state.RecordNumber > 0 && l.channelName != "" { diff --git a/winlogbeat/eventlog/wineventlog_experimental.go b/winlogbeat/eventlog/wineventlog_experimental.go index 3a6a9b2fe92..126e92fdace 100644 --- a/winlogbeat/eventlog/wineventlog_experimental.go +++ b/winlogbeat/eventlog/wineventlog_experimental.go @@ -158,7 +158,9 @@ func (l *winEventLogExp) Open(state checkpoint.EventLogState) error { l.lastRead = state // we need to defer metrics initialization since when the event log // is used from winlog input it would register it twice due to CheckConfig calls - l.metrics = newInputMetrics(l.channelName, l.id) + if l.metrics == nil { + l.metrics = newInputMetrics(l.channelName, l.id) + } var err error l.iterator, err = win.NewEventIterator(