mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-05 03:56:26 +03:00
Fixed the behaviour of the noop metrics gauge (#18252)
Before this change, the noop metrics gauge just ignored any value update. Now, it's backed by an atomic ref.
This commit is contained in:
parent
c62c9d4eea
commit
932a3ac226
@ -5,6 +5,7 @@ package com.daml.metrics.api.noop
|
||||
|
||||
import java.time.Duration
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
import com.daml.metrics.api.MetricHandle.Timer.TimerHandle
|
||||
import com.daml.metrics.api.MetricHandle.{Counter, Gauge, Histogram, Meter, Timer}
|
||||
@ -31,11 +32,15 @@ case object NoOpTimerHandle extends TimerHandle {
|
||||
|
||||
case class NoOpGauge[T](name: String, value: T) extends Gauge[T] {
|
||||
|
||||
override def updateValue(newValue: T): Unit = ()
|
||||
private val ref = new AtomicReference[T](value)
|
||||
|
||||
override def getValue: T = value
|
||||
override def updateValue(newValue: T): Unit = ref.set(newValue)
|
||||
|
||||
override def updateValue(f: T => T): Unit = ()
|
||||
override def getValue: T = ref.get()
|
||||
|
||||
override def updateValue(f: T => T): Unit = {
|
||||
val _ = ref.updateAndGet(f(_))
|
||||
}
|
||||
|
||||
override def close(): Unit = ()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user