Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions logstash-core/lib/logstash/api/commands/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def refine_batch_metrics(stats)
byte_size_histogram_value = byte_size_histogram.value
if byte_size_histogram_value[window.to_s]
reshape_histogram_percentiles_for_window(:byte_size, byte_size_histogram_value, window, result)
result[:byte_size][:max] ||= {}
result[:byte_size][:max][window] = byte_size_histogram_value[window.to_s].max_value.round
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ public static class HistogramMetricData implements Serializable {
private static final long serialVersionUID = 4711735381843512566L;
private final long percentile50;
private final long percentile90;
private final long maxValue;

public HistogramMetricData(ValueHistogram histogram) {
percentile50 = histogram.getValueAtPercentile(50);
percentile90 = histogram.getValueAtPercentile(90);
maxValue = histogram.getMaxValue();
}

@JsonProperty("p50")
Expand All @@ -127,11 +129,17 @@ public long get90Percentile() {
return percentile90;
}

@JsonProperty("max")
public long getMaxValue() {
return maxValue;
}

@Override
public String toString() {
return "HistogramMetricData{" +
"percentile50=" + percentile50 +
", percentile90=" + percentile90 +
", maxValue=" + maxValue +
'}';
}
}
Expand Down Expand Up @@ -165,8 +173,6 @@ Optional<ValueHistogram> calculateValue() {
if (compareCapture == null) { return Optional.empty(); }
if (baselineCapture == null) { return Optional.empty(); }

// var result = compareCapture.getValueHistogram();
// result.subtract(baselineCapture.getValueHistogram());
var result = compareCapture.getValueHistogram().subtract(baselineCapture.getValueHistogram());
return Optional.of(result);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public long getTotalCount() {
return delegate.getTotalCount();
}

public long getMaxValue() {
return delegate.getMaxValue();
}

public ValueHistogram subtract(ValueHistogram other) {
if (Objects.isNull(other) || Objects.isNull(other.delegate) || other.delegate.getTotalCount() <= 0) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void givenValueRecordedThen90thPercentileFromGetValueReflectsIt() {
ValueHistogram h = sut.getValue();
assertEquals(1, h.getTotalCount());
assertEquals(1000L, h.getValueAtPercentile(90));
assertEquals(1000L, h.getMaxValue());
}

@Test
Expand All @@ -56,14 +57,24 @@ public void givenLifetimeHistogramWhenRecordingSecondLargerValueThenP90Increases
ValueHistogram afterFirst = sut.getValue();
long p90AfterFirst = afterFirst.getValueAtPercentile(90);
assertEquals(100L, p90AfterFirst);
assertEquals(100L, afterFirst.getMaxValue());

sut.recordValue(1000);
ValueHistogram afterSecond = sut.getValue();
long p90AfterSecond = afterSecond.getValueAtPercentile(90);
assertTrue("90th percentile should increase after recording a larger value", p90AfterSecond > p90AfterFirst);
assertEquals(1000L, p90AfterSecond);
assertEquals(1000L, afterSecond.getMaxValue());

long p50AfterSecond = afterSecond.getValueAtPercentile(50);
assertEquals("previous 90th percentile value (100) should now be at 50th percentile", 100L, p50AfterSecond);
}

@Test
public void givenValuesRecordedThenGetMaxValueReturnsLargestRecordedValue() {
sut.recordValue(100);
sut.recordValue(1000);
ValueHistogram h = sut.getValue();
assertEquals(1000L, h.getMaxValue());
}
}
Loading