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

fix(hstore): JRaft Histogram Metrics Value NaN #2631

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, (d) -> d.getSnapshot().getMedian())
JackyYangPassion marked this conversation as resolved.
Show resolved Hide resolved
.tags(tags).register(registry);
Gauge.builder(baseName + ".min", wrapper, (d) -> d.getSnapshot().getMin())
Gauge.builder(baseName + ".min", histogram, (d) -> d.getSnapshot().getMin())
JackyYangPassion marked this conversation as resolved.
Show resolved Hide resolved
.tags(tags).register(registry);
Gauge.builder(baseName + ".max", wrapper, (d) -> d.getSnapshot().getMax())
Gauge.builder(baseName + ".max", histogram, (d) -> d.getSnapshot().getMax())
JackyYangPassion marked this conversation as resolved.
Show resolved Hide resolved
.tags(tags).register(registry);
Gauge.builder(baseName + ".mean", wrapper, (d) -> d.getSnapshot().getMean())
Gauge.builder(baseName + ".mean", histogram, (d) -> d.getSnapshot().getMean())
.tags(tags).register(registry);

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

Gauge.builder(baseName + ".sum", wrapper,
Gauge.builder(baseName + ".sum", histogram,
(d) -> Arrays.stream(d.getSnapshot().getValues()).sum())
.tags(tags).register(registry);
Gauge.builder(baseName + ".count", wrapper, (d) -> d.getSnapshot().size())
Gauge.builder(baseName + ".count", histogram, (d) -> d.getSnapshot().size())
.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;
}
}

}
Loading