Skip to content

Commit

Permalink
Fix long metric deserialize & add - auto-resize needs to be set manua…
Browse files Browse the repository at this point in the history
…lly (elastic#117105)

* Fix long metric deserialize & add - auto-resize needs to be set manually
  • Loading branch information
smalyshev authored Nov 20, 2024
1 parent c2c0901 commit 9477bd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/changelog/117105.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 117105
summary: Fix long metric deserialize & add - auto-resize needs to be set manually
area: CCS
type: bug
issues:
- 116914
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static LongMetricValue fromStream(StreamInput in) throws IOException {
try {
// TODO: not sure what is the good value for minBarForHighestToLowestValueRatio here?
Histogram dh = Histogram.decodeFromCompressedByteBuffer(bb, 1);
dh.setAutoResize(true);
return new LongMetricValue(dh);
} catch (DataFormatException e) {
throw new IOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.admin.cluster.stats.CCSTelemetrySnapshot.PerClusterCCSTelemetry;
import org.elasticsearch.action.admin.cluster.stats.LongMetric.LongMetricValue;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.Tuple;
Expand All @@ -32,9 +33,13 @@
public class CCSTelemetrySnapshotTests extends AbstractWireSerializingTestCase<CCSTelemetrySnapshot> {

private LongMetricValue randomLongMetricValue() {
return randomLongMetricValueBetween(0, 1_000_000);
}

private LongMetricValue randomLongMetricValueBetween(int low, int high) {
LongMetric v = new LongMetric();
for (int i = 0; i < randomIntBetween(5, 10); i++) {
v.record(randomIntBetween(0, 1_000_000));
v.record(randomIntBetween(low, high));
}
return v.getValue();
}
Expand Down Expand Up @@ -330,4 +335,21 @@ private String readJSONFromResource(String fileName) throws IOException {
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
}
}

public void testRanges() throws IOException {
var value1 = randomLongMetricValueBetween(1_000_000, 10_000_000);
var count1 = value1.count();
var max1 = value1.max();
var output = new BytesStreamOutput();
value1.writeTo(output);
var value1Read = LongMetricValue.fromStream(output.bytes().streamInput());
var value2 = randomLongMetricValueBetween(0, 100);
var count2 = value2.count();
output = new BytesStreamOutput();
value2.writeTo(output);
var value2Read = LongMetricValue.fromStream(output.bytes().streamInput());
value2Read.add(value1Read);
assertThat(value2Read.count(), equalTo(count1 + count2));
assertThat(value2Read.max(), equalTo(max1));
}
}

0 comments on commit 9477bd6

Please sign in to comment.