Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Counters not idempotent / state & lifecycle unclear #1713

Closed
dylanraithel opened this issue Nov 19, 2019 · 7 comments
Closed

Counters not idempotent / state & lifecycle unclear #1713

dylanraithel opened this issue Nov 19, 2019 · 7 comments

Comments

@dylanraithel
Copy link

dylanraithel commented Nov 19, 2019

Counters (and presumably other metering classes) don't appear to be idempotent. A single instance of a Counter class, registered to a DataDogRegistry doesn't produce consistent results when calling count() or measure(). The below example is from a scala sbt console and is a verbatim output, in order.

res74: io.micrometer.core.instrument.Counter = io.micrometer.core.instrument.step.StepCounter@34cb4a37

scala> counter.count()
res75: Double = 0.0

scala> counter.increment(10)

scala> counter.count()
res77: Double = 0.0

scala> counter.measure()
res78: Iterable[io.micrometer.core.instrument.Measurement] = [Measurement{statistic='COUNT', value=0.0}]

scala> counter.increment(10)

scala> counter.measure()
res80: Iterable[io.micrometer.core.instrument.Measurement] = [Measurement{statistic='COUNT', value=20.0}]

scala> counter.count()
res81: Double = 20.0

scala> counter.count()
res82: Double = 0.0

What's the lifecycle of the state of this object supposed to look like? Should the count values ever reset on their own? I'd really like to use this library and not go back to Dropwizard metrics if I don't have to

@dylanraithel
Copy link
Author

Here's another example:


scala> counter.increment(10)

scala> counter.increment(10)

scala> counter.increment(10)

scala> counter.increment(10)

scala> counter.increment(10)

scala> counter.increment(10)

scala> counter.increment(10)

scala> counter.increment(10)

scala> counter.count()
res107: Double = 0.0

scala> counter.measure()
res108: Iterable[io.micrometer.core.instrument.Measurement] = [Measurement{statistic='COUNT', value=0.0}]

scala> counter.measure()
res109: Iterable[io.micrometer.core.instrument.Measurement] = [Measurement{statistic='COUNT', value=0.0}]

scala> counter.count()
res110: Double = 0.0

scala> counter.increment()

scala> counter.measure()
res112: Iterable[io.micrometer.core.instrument.Measurement] = [Measurement{statistic='COUNT', value=101.0}]

scala> counter.count()
res113: Double = 101.0```

@dylanraithel
Copy link
Author

It seems the call to a parameter-less increment method resolves the missing counted values with the state of the object. This doesn't make much sense to me :D

@checketts
Copy link
Contributor

checketts commented Nov 19, 2019

That is bizarre behavior and not at all what I would expect (especially based on my understanding of how it is implemented).

Increment takes a double. Is it possible the Scala 10 isn't calling the method correctly? How does it behave if you use 10.0?

@dylanraithel
Copy link
Author

It behaves the same, but I do eventually see the metrics in DataDog, so are the values in the Counter instance(s) just being reset after the library purges data to DataDog?

res156: Double = 0.0

scala> counter.increment(10.0)

scala> counter.count
res158: Double = 0.0

scala> counter.measure()
res159: Iterable[io.micrometer.core.instrument.Measurement] = [Measurement{statistic='COUNT', value=10.0}]

scala> counter.count
res160: Double = 10.0

@shakuzen
Copy link
Member

shakuzen commented Dec 5, 2019

This, I believe, is due to timing and because the Step* implementations will return the value (count) for the previous interval. I'll open a separate issue to add some unit tests that demonstrate this for Step* metrics, as it has confused others and it would be nice to have something to point people to that also verifies the behavior. For now you can check the TCK test for counter increments.

/**
* @return The value for the last completed interval.
*/
public double poll() {
rollCount(clock.wallTime());
return previous;
}

@DisplayName("multiple increments are maintained")
@Test
default void increment(MeterRegistry registry) {
Counter c = registry.counter("myCounter");
c.increment();
clock(registry).add(step());
assertThat(c.count()).isEqualTo(1.0, offset(1e-12));
c.increment();
c.increment();
clock(registry).add(step());
// in the case of a step aggregating system will be 2, otherwise 3
assertThat(c.count()).isGreaterThanOrEqualTo(2.0);
}

@marcingrzejszczak marcingrzejszczak added the waiting for feedback We need additional information before we can continue label Dec 20, 2023
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Copy link

github-actions bot commented Jan 4, 2024

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2024
@jonatan-ivanov jonatan-ivanov removed waiting for feedback We need additional information before we can continue feedback-reminder labels Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants