micrometer icon indicating copy to clipboard operation
micrometer copied to clipboard

Histogram with negative values

Open joeo73 opened this issue 5 years ago • 9 comments

I'm migrating from drop wizard to micrometer. I used to use a Histogram to record the difference between two time values.

Micrometer doesn't support negative values, but here is a good use case here for doing just that.

joeo73 avatar Nov 15 '19 23:11 joeo73

Can you help me understand how it would have negative AND positive values?

I understand a difference is subtracting times. So START - END would be negative, but END - START would be positive. Just reversing the order to measure a duration makes more sense and would be supported.

So a histogram with -1, -2, and -3 could just as easily be represented as 1, 2, and 3 with the understanding of that metric being a difference of time.

checketts avatar Nov 15 '19 23:11 checketts

In my use case, am I tracking synchronization of time across servers measuring the difference on timestamped messages passed between the system. The value is a measure of clock drift (and network latency.)

The timestamp on a message from host FOO may be after or before the time on host BAR. Hence the calculated duration may be positive of negative.

joeo73 avatar Nov 16 '19 00:11 joeo73

Great use case! I think the problem you are running into is the minimumExpectedValue defaults to 1. See https://micrometer.io/docs/concepts#_scaling_and_histograms for how you can configure that.

Let me know if that works for you.

checketts avatar Nov 16 '19 02:11 checketts

Setting this value doesn't have any affect. Ref the record method in AbstractDistributionSummary . It ignores all negative values. Sample code and output:

public void testDistribution() {
    MeterRegistry meterRegistry = new SimpleMeterRegistry();

    DistributionSummary summary = DistributionSummary
        .builder("foo")
        .minimumExpectedValue(-100L)
        .tags(Tags.empty())
        .register(meterRegistry);

    summary.record(-10);
    summary.record(10);

    HistogramSnapshot result = summary.takeSnapshot();

    System.out.println(result.toString());

    summary.measure().forEach((m) -> {
      System.out.println(m.toString());
    });
  }

Output:

HistogramSnapshot{count=1, total=10.0, mean=10.0, max=10.0}
Measurement{statistic='COUNT', value=1.0}
Measurement{statistic='TOTAL', value=10.0}
Measurement{statistic='MAX', value=10.0}

joeo73 avatar Nov 18 '19 19:11 joeo73

Just for reference, the discussion in OpenMetrics.

mweirauch avatar Nov 18 '19 20:11 mweirauch

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.

github-actions[bot] avatar Dec 28 '23 01:12 github-actions[bot]

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[bot] avatar Jan 04 '24 01:01 github-actions[bot]

What additional information is requested? There has been no movement on this in over 4 years, I assume this project is dead as I am talking to a bot.

joeo73-impinj avatar Jan 04 '24 16:01 joeo73-impinj

You might want to talk to people then. :)

I think closing this was an accidental. Let me reopen it to track user interest: right now we don't support negative values since as far as I remember there are some arithmetical issues that we need to fix and max decaying to zero would be also weird.

jonatan-ivanov avatar Feb 06 '24 23:02 jonatan-ivanov