Skip to content

Commit

Permalink
Add "add(Long)" method to CounterMetric.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcsf committed Aug 10, 2022
1 parent bca37ac commit fea17fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class CounterMetric @JvmOverloads constructor(

override fun register(registry: CollectorRegistry) = this.also { registry.register(counter) }

/**
* Atomically adds the given value to this counter.
*/
fun add(delta: Long) = synchronized(counter) { counter.inc(delta.toDouble()) }

/**
* Atomically adds the given value to this counter, returning the updated value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MetricsContainerTest : ShouldSpec() {
}
context("and altering their values") {
booleanMetric.set(!booleanMetric.get())
counter.addAndGet(5)
counter.add(5)
longGauge.set(5)
context("then resetting all metrics in the MetricsContainer") {
mc.resetAll()
Expand Down

0 comments on commit fea17fb

Please sign in to comment.