diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 1fd25b842017..2dd20d09e720 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -117,6 +117,7 @@ is collected by it. - Fix panics when parsing dereferencing invalid parsed url. {pull}34702[34702] - Fix retries to trigger on a down monitor with no previous state. {pull}36842[36842] +- Fix monitor duration calculation with retries. {pull}36842[36842] *Metricbeat* diff --git a/heartbeat/monitors/wrappers/summarizer/plugmondur.go b/heartbeat/monitors/wrappers/summarizer/plugmondur.go index f677e57693f8..171e3870269b 100644 --- a/heartbeat/monitors/wrappers/summarizer/plugmondur.go +++ b/heartbeat/monitors/wrappers/summarizer/plugmondur.go @@ -33,8 +33,7 @@ type LightweightDurationPlugin struct { func (lwdsp *LightweightDurationPlugin) EachEvent(event *beat.Event, _ error) EachEventActions { // Effectively only runs once, on the first event if lwdsp.startedAt == nil { - now := time.Now() - lwdsp.startedAt = &now + lwdsp.setEventStartAt() } return 0 } @@ -44,7 +43,15 @@ func (lwdsp *LightweightDurationPlugin) BeforeSummary(event *beat.Event) BeforeS return 0 } -func (lwdsp *LightweightDurationPlugin) BeforeRetry() {} +func (lwdsp *LightweightDurationPlugin) BeforeRetry() { + // Reset event.startAt + lwdsp.startedAt = nil +} + +func (lwdsp *LightweightDurationPlugin) setEventStartAt() { + now := time.Now() + lwdsp.startedAt = &now +} // BrowserDurationPlugin handles the logic for writing the `monitor.duration.us` field // for browser monitors. diff --git a/heartbeat/monitors/wrappers/summarizer/summarizer.go b/heartbeat/monitors/wrappers/summarizer/summarizer.go index 9c3f1bd8abdf..cca3fada663a 100644 --- a/heartbeat/monitors/wrappers/summarizer/summarizer.go +++ b/heartbeat/monitors/wrappers/summarizer/summarizer.go @@ -145,10 +145,10 @@ func (s *Summarizer) Wrap(j jobs.Job) jobs.Job { // kibana queries // 2. If the site error is very short 1s gives it a tiny bit of time to recover delayedRootJob := func(event *beat.Event) ([]jobs.Job, error) { + time.Sleep(s.retryDelay) for _, p := range s.plugins { p.BeforeRetry() } - time.Sleep(s.retryDelay) return s.rootJob(event) } diff --git a/x-pack/heartbeat/heartbeat.yml b/x-pack/heartbeat/heartbeat.yml index 76876b9c7ff5..d11f77e8b723 100644 --- a/x-pack/heartbeat/heartbeat.yml +++ b/x-pack/heartbeat/heartbeat.yml @@ -23,7 +23,7 @@ heartbeat.config.monitors: heartbeat.monitors: - type: http # Set enabled to true (or delete the following line) to enable this monitor - enabled: false + enabled: true # ID used to uniquely identify this monitor in Elasticsearch even if the config changes id: my-monitor # Human readable display name for this service in Uptime UI and elsewhere @@ -31,7 +31,8 @@ heartbeat.monitors: # List of URLs to query urls: ["http://localhost:9200"] # Configure task schedule - schedule: '@every 10s' + schedule: '@every 10000s' + max_attempts: 2 # Total test connection and data exchange timeout #timeout: 16s # Name of corresponding APM service, if Elastic APM is in use for the monitored service. @@ -98,9 +99,11 @@ setup.kibana: # Configure what output to use when sending the data collected by the beat. # ---------------------------- Elasticsearch Output ---------------------------- -output.elasticsearch: - # Array of hosts to connect to. - hosts: ["localhost:9200"] +# output.elasticsearch: +# # Array of hosts to connect to. +# hosts: ["localhost:9200"] +output.console: + pretty: true # Protocol - either `http` (default) or `https`. #protocol: "https"