Browse Source

Allow inc with negative, and dec with positive, values for Gauge.

pull/4/head
Fredrik Ekre 2 years ago
parent
commit
419b4e4f7d
  1. 6
      src/Prometheus.jl
  2. 2
      test/runtests.jl

6
src/Prometheus.jl

@ -236,9 +236,6 @@ Increment the value of the gauge `g` with `v`.
`v` defaults to `v = 1`. `v` defaults to `v = 1`.
""" """
function inc(m::Gauge, v = 1.0) function inc(m::Gauge, v = 1.0)
if v < 0
error("incrementing with negative value, use dec(...)?")
end
@atomic m.value += v @atomic m.value += v
return nothing return nothing
end end
@ -250,9 +247,6 @@ Decrement the value of the gauge `g` with `v`.
`v` defaults to `v = 1`. `v` defaults to `v = 1`.
""" """
function dec(m::Gauge, v = 1.0) function dec(m::Gauge, v = 1.0)
if v < 0
error("decrementing with negative value, use inc(...)?")
end
@atomic m.value -= v @atomic m.value -= v
return nothing return nothing
end end

2
test/runtests.jl

@ -76,13 +76,11 @@ end
@test c.value == 1 @test c.value == 1
Prometheus.inc(c, 2) Prometheus.inc(c, 2)
@test c.value == 3 @test c.value == 3
@test_throws ErrorException Prometheus.inc(c, -1)
# Prometheus.dec(...) # Prometheus.dec(...)
Prometheus.dec(c) Prometheus.dec(c)
@test c.value == 2 @test c.value == 2
Prometheus.dec(c, 1) Prometheus.dec(c, 1)
@test c.value == 1 @test c.value == 1
@test_throws ErrorException Prometheus.dec(c, -1)
# Prometheus.set_to_current_time(...) # Prometheus.set_to_current_time(...)
t0 = time() t0 = time()
sleep(0.1) sleep(0.1)

Loading…
Cancel
Save