From c13f29303e9aee62b799c78aad15880be5f71ffa Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 13 Dec 2023 08:53:28 -0800 Subject: [PATCH] fix: adjust formatting for heartbeat monitor and state loader (#37427) (#37434) * fix: adjust formatting for heartbeat monitor and state loader * reset ES error (cherry picked from commit 6c5d221596c64c0cd25ecf02cf4387171947b977) Co-authored-by: Vignesh Shanmugam --- CHANGELOG.next.asciidoc | 1 + heartbeat/monitors/active/icmp/stdloop.go | 2 +- heartbeat/monitors/monitor.go | 2 +- heartbeat/monitors/task.go | 6 +++--- heartbeat/monitors/wrappers/monitorstate/tracker.go | 2 +- x-pack/heartbeat/monitors/browser/sourcejob.go | 2 +- x-pack/heartbeat/monitors/browser/synthexec/synthexec.go | 2 +- x-pack/heartbeat/monitors/browser/synthexec/synthtypes.go | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 5d43975f56c6..2916f6ec5570 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -99,6 +99,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Fix panics when parsing dereferencing invalid parsed url. {pull}34702[34702] - Fix mapping errors with invalid urls. {pull}37255[37255] +- Added fix for formatting the logs from stateloader properly. {pull}37369[37369] *Metricbeat* diff --git a/heartbeat/monitors/active/icmp/stdloop.go b/heartbeat/monitors/active/icmp/stdloop.go index b49d243ec4c6..f67ae402bc70 100644 --- a/heartbeat/monitors/active/icmp/stdloop.go +++ b/heartbeat/monitors/active/icmp/stdloop.go @@ -165,7 +165,7 @@ func (l *stdICMPLoop) runICMPRecv(conn *icmp.PacketConn, proto int) { bytes := make([]byte, 512) err := conn.SetReadDeadline(time.Now().Add(time.Second)) if err != nil { - logp.L().Error("could not set read deadline for ICMP: %w", err) + logp.L().Errorf("could not set read deadline for ICMP: %w", err) return } _, addr, err := conn.ReadFrom(bytes) diff --git a/heartbeat/monitors/monitor.go b/heartbeat/monitors/monitor.go index 6a16c7d3f303..29e7713145ca 100644 --- a/heartbeat/monitors/monitor.go +++ b/heartbeat/monitors/monitor.go @@ -256,7 +256,7 @@ func (m *Monitor) Stop() { if m.close != nil { err := m.close() if err != nil { - logp.L().Error("error closing monitor %s: %w", m.String(), err) + logp.L().Errorf("error closing monitor %s: %w", m.String(), err) } } diff --git a/heartbeat/monitors/task.go b/heartbeat/monitors/task.go index ee0839fe14e5..a655e1d15467 100644 --- a/heartbeat/monitors/task.go +++ b/heartbeat/monitors/task.go @@ -80,13 +80,13 @@ func (t *configuredJob) Start(pubClient beat.Client) { t.pubClient = pubClient if err != nil { - logp.L().Info("could not start monitor: %v", err) + logp.L().Infof("could not start monitor: %v", err) return } t.cancelFn, err = t.monitor.addTask(t.config.Schedule, t.monitor.stdFields.ID, t.makeSchedulerTaskFunc(), t.config.Type) if err != nil { - logp.L().Info("could not start monitor: %v", err) + logp.L().Infof("could not start monitor: %v", err) } } @@ -107,7 +107,7 @@ func runPublishJob(job jobs.Job, pubClient beat.Client) []scheduler.TaskFunc { conts, err := job(event) if err != nil { - logp.L().Info("Job failed with: %s", err) + logp.L().Infof("Job failed with: %s", err) } hasContinuations := len(conts) > 0 diff --git a/heartbeat/monitors/wrappers/monitorstate/tracker.go b/heartbeat/monitors/wrappers/monitorstate/tracker.go index 03909d55aa83..e350294e46e8 100644 --- a/heartbeat/monitors/wrappers/monitorstate/tracker.go +++ b/heartbeat/monitors/wrappers/monitorstate/tracker.go @@ -104,7 +104,7 @@ func (t *Tracker) GetCurrentState(sf stdfields.StdMonitorFields) (state *State) time.Sleep(sleepFor) } if err != nil { - logp.L().Warn("could not load prior state from elasticsearch after %d attempts, will create new state for monitor: %s", tries, sf.ID) + logp.L().Warnf("could not load prior state from elasticsearch after %d attempts, will create new state for monitor: %s", tries, sf.ID) } if loadedState != nil { diff --git a/x-pack/heartbeat/monitors/browser/sourcejob.go b/x-pack/heartbeat/monitors/browser/sourcejob.go index c62c50b3bb17..697e51abf51a 100644 --- a/x-pack/heartbeat/monitors/browser/sourcejob.go +++ b/x-pack/heartbeat/monitors/browser/sourcejob.go @@ -125,7 +125,7 @@ func (sj *SourceJob) extraArgs(uiOrigin bool) []string { s, err := json.Marshal(sj.browserCfg.PlaywrightOpts) if err != nil { // This should never happen, if it was parsed as a config it should be serializable - logp.L().Warn("could not serialize playwright options '%v': %w", sj.browserCfg.PlaywrightOpts, err) + logp.L().Warnf("could not serialize playwright options '%v': %w", sj.browserCfg.PlaywrightOpts, err) } else { extraArgs = append(extraArgs, "--playwright-options", string(s)) } diff --git a/x-pack/heartbeat/monitors/browser/synthexec/synthexec.go b/x-pack/heartbeat/monitors/browser/synthexec/synthexec.go index fbfb71526cc5..32f127de98c3 100644 --- a/x-pack/heartbeat/monitors/browser/synthexec/synthexec.go +++ b/x-pack/heartbeat/monitors/browser/synthexec/synthexec.go @@ -219,7 +219,7 @@ func runCmd( break } if err != nil { - logp.L().Warn("error decoding json for test json results: %w", err) + logp.L().Warnf("error decoding json for test json results: %w", err) } mpx.writeSynthEvent(&se) diff --git a/x-pack/heartbeat/monitors/browser/synthexec/synthtypes.go b/x-pack/heartbeat/monitors/browser/synthexec/synthtypes.go index 8555ae448a71..ddd928b216d6 100644 --- a/x-pack/heartbeat/monitors/browser/synthexec/synthtypes.go +++ b/x-pack/heartbeat/monitors/browser/synthexec/synthtypes.go @@ -96,7 +96,7 @@ func (se SynthEvent) ToMap() (m mapstr.M) { u, e := url.Parse(se.URL) if e != nil { _, _ = m.Put("url", mapstr.M{"full": se.URL}) - logp.L().Warn("Could not parse synthetics URL '%s': %s", se.URL, e.Error()) + logp.L().Warnf("Could not parse synthetics URL '%s': %s", se.URL, e.Error()) } else { _, _ = m.Put("url", wraputil.URLFields(u)) }