Skip to content

Commit

Permalink
fix(qos): Use PolledMeter to prevent metric deletion by Garbage Colle…
Browse files Browse the repository at this point in the history
…ctor (#4810)

Depending on the load and configuration, the metric may be updated infrequently, and therefore the real value is deleted. As a result, instead of the value you see N/A. Replaced with PolledMeter to hold a strong reference

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
kbatalin and mergify[bot] authored Dec 11, 2024
1 parent 266ce73 commit 8e1ec6d
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.netflix.spinnaker.orca.qos

import com.netflix.spectator.api.Registry
import com.netflix.spectator.api.patterns.PolledMeter
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import com.netflix.spinnaker.orca.annotations.Sync
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus.BUFFERED
Expand All @@ -29,6 +30,7 @@ import net.logstash.logback.argument.StructuredArguments.value
import org.slf4j.LoggerFactory
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component
import java.util.concurrent.atomic.AtomicLong

/**
* Determines if an execution should be buffered.
Expand All @@ -50,6 +52,11 @@ class ExecutionBufferActuator(
private val enqueuedId = registry.createId("qos.executionsEnqueued")
private val elapsedTimeId = registry.createId("qos.actuator.elapsedTime")

// have to use PolledMeter because an ordinary metric is deleted by Garbage Collector
private val bufferingEnabled = PolledMeter.using(registry)
.withId(bufferingId)
.monitorValue(AtomicLong(0))

@Sync
@EventListener(BeforeInitialExecutionPersist::class)
fun beforeInitialPersist(event: BeforeInitialExecutionPersist) {
Expand All @@ -61,7 +68,7 @@ class ExecutionBufferActuator(

val supplierName = bufferStateSupplier.javaClass.simpleName
if (bufferStateSupplier.get() == ACTIVE) {
registry.gauge(bufferingId).set(1.0)
bufferingEnabled.set(1)

val execution = event.execution
withActionDecision(execution) {
Expand All @@ -83,7 +90,7 @@ class ExecutionBufferActuator(
}
}
} else {
registry.gauge(bufferingId).set(0.0)
bufferingEnabled.set(0)
}
}

Expand Down

0 comments on commit 8e1ec6d

Please sign in to comment.