Skip to content

Commit 626d100

Browse files
authored
Fix long metric deserialize & add - auto-resize needs to be set manually (#117105) (#117171)
* Fix long metric deserialize & add - auto-resize needs to be set manually
1 parent 6f3d152 commit 626d100

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

docs/changelog/117105.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 117105
2+
summary: Fix long metric deserialize & add - auto-resize needs to be set manually
3+
area: CCS
4+
type: bug
5+
issues:
6+
- 116914

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/LongMetric.java

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public static LongMetricValue fromStream(StreamInput in) throws IOException {
7474
try {
7575
// TODO: not sure what is the good value for minBarForHighestToLowestValueRatio here?
7676
Histogram dh = Histogram.decodeFromCompressedByteBuffer(bb, 1);
77+
dh.setAutoResize(true);
7778
return new LongMetricValue(dh);
7879
} catch (DataFormatException e) {
7980
throw new IOException(e);

server/src/test/java/org/elasticsearch/action/admin/cluster/stats/CCSTelemetrySnapshotTests.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.action.admin.cluster.stats.CCSTelemetrySnapshot.PerClusterCCSTelemetry;
1313
import org.elasticsearch.action.admin.cluster.stats.LongMetric.LongMetricValue;
1414
import org.elasticsearch.common.bytes.BytesArray;
15+
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1516
import org.elasticsearch.common.io.stream.Writeable;
1617
import org.elasticsearch.common.xcontent.XContentHelper;
1718
import org.elasticsearch.core.Tuple;
@@ -32,9 +33,13 @@
3233
public class CCSTelemetrySnapshotTests extends AbstractWireSerializingTestCase<CCSTelemetrySnapshot> {
3334

3435
private LongMetricValue randomLongMetricValue() {
36+
return randomLongMetricValueBetween(0, 1_000_000);
37+
}
38+
39+
private LongMetricValue randomLongMetricValueBetween(int low, int high) {
3540
LongMetric v = new LongMetric();
3641
for (int i = 0; i < randomIntBetween(5, 10); i++) {
37-
v.record(randomIntBetween(0, 1_000_000));
42+
v.record(randomIntBetween(low, high));
3843
}
3944
return v.getValue();
4045
}
@@ -330,4 +335,21 @@ private String readJSONFromResource(String fileName) throws IOException {
330335
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
331336
}
332337
}
338+
339+
public void testRanges() throws IOException {
340+
var value1 = randomLongMetricValueBetween(1_000_000, 10_000_000);
341+
var count1 = value1.count();
342+
var max1 = value1.max();
343+
var output = new BytesStreamOutput();
344+
value1.writeTo(output);
345+
var value1Read = LongMetricValue.fromStream(output.bytes().streamInput());
346+
var value2 = randomLongMetricValueBetween(0, 100);
347+
var count2 = value2.count();
348+
output = new BytesStreamOutput();
349+
value2.writeTo(output);
350+
var value2Read = LongMetricValue.fromStream(output.bytes().streamInput());
351+
value2Read.add(value1Read);
352+
assertThat(value2Read.count(), equalTo(count1 + count2));
353+
assertThat(value2Read.max(), equalTo(max1));
354+
}
333355
}

0 commit comments

Comments
 (0)