Skip to content

Commit

Permalink
fix(metrics): record drift from last resource check (#976)
Browse files Browse the repository at this point in the history
* fix(metrics): record drift from last resource check

Calculate the resource check drift metric (keel.resource.check.drift)
by using the last time resource check succeeded as the start time.

Previously, it was calculating based on the beginning of the actuation
loop, which would drop to zero when the loop restarted due to timeout.

Fixes #950

* fix(pr): move ResourceCheckCompleted, remove ScheduledResourceCheckStarting

Remove ScheduledResourceCheckStarting since it's no longer used.

Move ResourceCheckCompleted to a separate file.

* fix(pr): add missing import
  • Loading branch information
Lorin Hochstein committed Apr 7, 2020
1 parent 8987784 commit 399d102
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class CheckScheduler(
fun checkResources() {
if (enabled.get()) {
log.debug("Starting scheduled resource validation…")
publisher.publishEvent(ScheduledResourceCheckStarting)

val job = launch {
supervisorScope {
Expand All @@ -79,7 +78,10 @@ class CheckScheduler(
* to prevent the cancellation of all coroutines under [job]
*/
withTimeout(checkTimeout.toMillis()) {
launch { resourceActuator.checkResource(it) }
launch {
resourceActuator.checkResource(it)
publisher.publishEvent(ResourceCheckCompleted)
}
}
} catch (e: TimeoutCancellationException) {
log.error("Timed out checking resource ${it.id}", e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.netflix.spinnaker.keel.actuation

object ScheduledResourceCheckStarting
object ResourceCheckCompleted

object ScheduledEnvironmentCheckStarting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.netflix.spectator.api.BasicTag
import com.netflix.spectator.api.Counter
import com.netflix.spectator.api.Registry
import com.netflix.spectator.api.patterns.PolledMeter
import com.netflix.spinnaker.keel.actuation.ResourceCheckCompleted
import com.netflix.spinnaker.keel.actuation.ScheduledArtifactCheckStarting
import com.netflix.spinnaker.keel.actuation.ScheduledEnvironmentCheckStarting
import com.netflix.spinnaker.keel.actuation.ScheduledResourceCheckStarting
import com.netflix.spinnaker.keel.events.ResourceActuationLaunched
import com.netflix.spinnaker.keel.events.ResourceCheckResult
import java.time.Clock
Expand Down Expand Up @@ -115,8 +115,8 @@ class TelemetryListener(
).safeIncrement()
}

@EventListener(ScheduledResourceCheckStarting::class)
fun onScheduledCheckStarting(event: ScheduledResourceCheckStarting) {
@EventListener(ResourceCheckCompleted::class)
fun onResourceCheckCompleted(event: ResourceCheckCompleted) {
lastResourceCheck.set(clock.instant())
}

Expand Down

0 comments on commit 399d102

Please sign in to comment.