Skip to content

Commit

Permalink
fix(hstore): JRaft Histogram Metrics Value NaN (#2631)
Browse files Browse the repository at this point in the history
Co-authored-by: imbajin <[email protected]>
Co-authored-by: yangjiaqi <jiaqi.yang@veriti@xyz>
  • Loading branch information
3 people authored and VGalaxies committed Nov 6, 2024
1 parent 18acf61 commit 24c3fb3
Showing 1 changed file with 14 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ private static void registerNodeMetrics() {

}

private static HistogramWrapper toWrapper(com.codahale.metrics.Histogram histogram) {
return new HistogramWrapper(histogram);
}

private static String refineMetrics(String name, List<Tag> tags) {
if (name == null || name.isEmpty()) {
return name;
Expand Down Expand Up @@ -172,35 +168,33 @@ private static void registerHistogram(String group, String name,

String baseName = PREFIX + "." + name.toLowerCase();

HistogramWrapper wrapper = toWrapper(histogram);

Gauge.builder(baseName + ".median", wrapper, (d) -> d.getSnapshot().getMedian())
Gauge.builder(baseName + ".median", histogram, h -> h.getSnapshot().getMedian())
.tags(tags).register(registry);
Gauge.builder(baseName + ".min", wrapper, (d) -> d.getSnapshot().getMin())
Gauge.builder(baseName + ".min", histogram, h -> h.getSnapshot().getMin())
.tags(tags).register(registry);
Gauge.builder(baseName + ".max", wrapper, (d) -> d.getSnapshot().getMax())
Gauge.builder(baseName + ".max", histogram, h -> h.getSnapshot().getMax())
.tags(tags).register(registry);
Gauge.builder(baseName + ".mean", wrapper, (d) -> d.getSnapshot().getMean())
Gauge.builder(baseName + ".mean", histogram, h -> h.getSnapshot().getMean())
.tags(tags).register(registry);

baseName = baseName + ".summary";
Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().getMedian())
Gauge.builder(baseName, histogram, h -> h.getSnapshot().getMedian())
.tags(tags).tag(LABELS, LABEL_50).register(registry);
Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get75thPercentile())
Gauge.builder(baseName, histogram, h -> h.getSnapshot().get75thPercentile())
.tags(tags).tag(LABELS, LABEL_75).register(registry);
Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get95thPercentile())
Gauge.builder(baseName, histogram, h -> h.getSnapshot().get95thPercentile())
.tags(tags).tag(LABELS, LABEL_95).register(registry);
Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get98thPercentile())
Gauge.builder(baseName, histogram, h -> h.getSnapshot().get98thPercentile())
.tags(tags).tag(LABELS, LABEL_98).register(registry);
Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get99thPercentile())
Gauge.builder(baseName, histogram, h -> h.getSnapshot().get99thPercentile())
.tags(tags).tag(LABELS, LABEL_99).register(registry);
Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get999thPercentile())
Gauge.builder(baseName, histogram, h -> h.getSnapshot().get999thPercentile())
.tags(tags).tag(LABELS, LABEL_999).register(registry);

Gauge.builder(baseName + ".sum", wrapper,
(d) -> Arrays.stream(d.getSnapshot().getValues()).sum())
Gauge.builder(baseName + ".sum", histogram,
h -> Arrays.stream(h.getSnapshot().getValues()).sum())
.tags(tags).register(registry);
Gauge.builder(baseName + ".count", wrapper, (d) -> d.getSnapshot().size())
Gauge.builder(baseName + ".count", histogram, h -> h.getSnapshot().size())
.tags(tags).register(registry);

}
Expand All @@ -214,7 +208,7 @@ private static void registerTimer(String group, String name, com.codahale.metric

String baseName = PREFIX + "." + name.toLowerCase();

Gauge.builder(baseName + ".count", timer, t->t.getCount())
Gauge.builder(baseName + ".count", timer, t -> t.getCount())
.tags(tags).register(registry);
Gauge.builder(baseName + ".min", timer, t -> t.getSnapshot().getMin())
.tags(tags).register(registry);
Expand Down Expand Up @@ -309,26 +303,4 @@ private static void registerGauge(String group, String name,
}

}

private static class HistogramWrapper {

private final com.codahale.metrics.Histogram histogram;

private Snapshot snapshot;
private long ts = System.currentTimeMillis();

HistogramWrapper(com.codahale.metrics.Histogram histogram) {
this.histogram = histogram;
this.snapshot = this.histogram.getSnapshot();
}

Snapshot getSnapshot() {
if (System.currentTimeMillis() - this.ts > 30_000) {
this.snapshot = this.histogram.getSnapshot();
this.ts = System.currentTimeMillis();
}
return this.snapshot;
}
}

}

0 comments on commit 24c3fb3

Please sign in to comment.