Skip to content

Commit

Permalink
Fix monitor duration calc and remove delay from elapsed time
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioalvap committed Oct 18, 2023
1 parent d3c42ef commit cc72e06
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
13 changes: 10 additions & 3 deletions heartbeat/monitors/wrappers/summarizer/plugmondur.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/wrappers/summarizer/summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
13 changes: 8 additions & 5 deletions x-pack/heartbeat/heartbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ 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
name: My Monitor
# 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.
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit cc72e06

Please sign in to comment.