Skip to content

Commit 63ade66

Browse files
committed
Add max value for batch size windowed histograms
1 parent 298d894 commit 63ade66

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

config/logstash.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
# Default is "minimal".
6565
#
6666
# pipeline.batch.metrics.sampling_mode: "minimal"
67+
pipeline.batch.metrics.sampling_mode: full
6768
#
6869
# Force Logstash to exit during shutdown even if there are still inflight
6970
# events in memory. By default, logstash will refuse to quit until all

logstash-core/lib/logstash/api/commands/stats.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ def refine_batch_metrics(stats)
213213
byte_size_histogram_value = byte_size_histogram.value
214214
if byte_size_histogram_value[window.to_s]
215215
reshape_histogram_percentiles_for_window(:byte_size, byte_size_histogram_value, window, result)
216+
result[:byte_size][:max] ||= {}
217+
result[:byte_size][:max][window] = byte_size_histogram_value[window.to_s].max_value.round
216218
end
217219
end
218220
end

logstash-core/src/main/java/org/logstash/instrument/metrics/BatchStructureMetric.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ public static class HistogramMetricData implements Serializable {
111111
private static final long serialVersionUID = 4711735381843512566L;
112112
private final long percentile50;
113113
private final long percentile90;
114+
private final long maxValue;
114115

115116
public HistogramMetricData(ValueHistogram histogram) {
116117
percentile50 = histogram.getValueAtPercentile(50);
117118
percentile90 = histogram.getValueAtPercentile(90);
119+
maxValue = histogram.getMaxValue();
118120
}
119121

120122
@JsonProperty("p50")
@@ -127,11 +129,17 @@ public long get90Percentile() {
127129
return percentile90;
128130
}
129131

132+
@JsonProperty("max")
133+
public long getMaxValue() {
134+
return maxValue;
135+
}
136+
130137
@Override
131138
public String toString() {
132139
return "HistogramMetricData{" +
133140
"percentile50=" + percentile50 +
134141
", percentile90=" + percentile90 +
142+
", maxValue=" + maxValue +
135143
'}';
136144
}
137145
}
@@ -165,8 +173,6 @@ Optional<ValueHistogram> calculateValue() {
165173
if (compareCapture == null) { return Optional.empty(); }
166174
if (baselineCapture == null) { return Optional.empty(); }
167175

168-
// var result = compareCapture.getValueHistogram();
169-
// result.subtract(baselineCapture.getValueHistogram());
170176
var result = compareCapture.getValueHistogram().subtract(baselineCapture.getValueHistogram());
171177
return Optional.of(result);
172178
});

logstash-core/src/main/java/org/logstash/instrument/metrics/histogram/LifetimeHistogramMetric.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public long getTotalCount() {
8585
return delegate.getTotalCount();
8686
}
8787

88+
public long getMaxValue() {
89+
return delegate.getMaxValue();
90+
}
91+
8892
public ValueHistogram subtract(ValueHistogram other) {
8993
if (Objects.isNull(other) || Objects.isNull(other.delegate) || other.delegate.getTotalCount() <= 0) {
9094
return this;

logstash-core/src/test/java/org/logstash/instrument/metrics/histogram/LifetimeHistogramMetricTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void givenValueRecordedThen90thPercentileFromGetValueReflectsIt() {
4242
ValueHistogram h = sut.getValue();
4343
assertEquals(1, h.getTotalCount());
4444
assertEquals(1000L, h.getValueAtPercentile(90));
45+
assertEquals(1000L, h.getMaxValue());
4546
}
4647

4748
@Test
@@ -56,14 +57,24 @@ public void givenLifetimeHistogramWhenRecordingSecondLargerValueThenP90Increases
5657
ValueHistogram afterFirst = sut.getValue();
5758
long p90AfterFirst = afterFirst.getValueAtPercentile(90);
5859
assertEquals(100L, p90AfterFirst);
60+
assertEquals(100L, afterFirst.getMaxValue());
5961

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

6669
long p50AfterSecond = afterSecond.getValueAtPercentile(50);
6770
assertEquals("previous 90th percentile value (100) should now be at 50th percentile", 100L, p50AfterSecond);
6871
}
72+
73+
@Test
74+
public void givenValuesRecordedThenGetMaxValueReturnsLargestRecordedValue() {
75+
sut.recordValue(100);
76+
sut.recordValue(1000);
77+
ValueHistogram h = sut.getValue();
78+
assertEquals(1000L, h.getMaxValue());
79+
}
6980
}

0 commit comments

Comments
 (0)