fix: Set first interval based on last result time#1528
fix: Set first interval based on last result time#1528PythonGermany wants to merge 1 commit intoTwiN:masterfrom
Conversation
| return | ||
| case <-ticker.C: | ||
| executeExternalEndpointHeartbeat(ee, cfg, extraLabels) | ||
| ticker.Reset(ee.Heartbeat.Interval) |
There was a problem hiding this comment.
Not sure if this is considered a "hack". I'd love to learn how to do this in a more clean looking way.
| ticker := time.NewTicker(ee.Heartbeat.Interval) | ||
| timeToNextCheck := ee.Heartbeat.Interval | ||
|
|
||
| lastStatus, err := store.Get().GetEndpointStatusByKey(ee.Key(), paging.NewEndpointStatusParams().WithResults(0, 1)) |
There was a problem hiding this comment.
Is this an appropriate way to do this here with this store method and results size 1?
| if results := lastStatus.Results; len(results) > 0 { | ||
| timeSinceLastResult := time.Since(results[0].Timestamp) | ||
| logr.Debugf("[watchdog.monitorExternalEndpointHeartbeat] Time since last result: '%s'", timeSinceLastResult) | ||
| if timeSinceLastResult < timeToNextCheck { |
There was a problem hiding this comment.
One question still open for me is which way to handle what should happen if the time since the last result is longer than the configured heartbeat interval. Currently it will wait for the duration of the heartbeat interval before the first check.
Alternatively the behaviour could be that a failure is created immediately. However I suspect this could often lead to false positives, especially for very short intervals.
I think I prefer the currently implemented behaviour. Just wanted to throw the different possible approaches out there!
Summary
Closes #1237 by introducing a check after startup adjusting the time to wait for the first heartbeat check based on the time that has passed since the last received result
Checklist
README.md, if applicable.