Skip to content

Commit debfc11

Browse files
committed
Fix AnalyticsStats response serialization
Fixes incorrect serialization of cumulativeCardinalityUsage Relates to elastic#55162
1 parent ef32dc0 commit debfc11

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.analytics.action;
8+
9+
import org.elasticsearch.Version;
10+
import org.elasticsearch.cluster.node.DiscoveryNode;
11+
import org.elasticsearch.common.io.stream.Writeable;
12+
import org.elasticsearch.test.AbstractWireSerializingTestCase;
13+
import org.elasticsearch.xpack.core.analytics.action.AnalyticsStatsAction;
14+
15+
public class AnalyticsStatsActionNodeResponseTests extends AbstractWireSerializingTestCase<AnalyticsStatsAction.NodeResponse> {
16+
17+
@Override
18+
protected Writeable.Reader<AnalyticsStatsAction.NodeResponse> instanceReader() {
19+
return AnalyticsStatsAction.NodeResponse::new;
20+
}
21+
22+
@Override
23+
protected AnalyticsStatsAction.NodeResponse createTestInstance() {
24+
String nodeName = randomAlphaOfLength(10);
25+
DiscoveryNode node = new DiscoveryNode(nodeName, buildNewFakeTransportAddress(), Version.CURRENT);
26+
return new AnalyticsStatsAction.NodeResponse(node, randomLongBetween(0, 1000), randomLongBetween(0, 1000),
27+
randomLongBetween(0, 1000), randomLongBetween(0, 1000));
28+
}
29+
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/analytics/action/AnalyticsStatsAction.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void writeTo(StreamOutput out) throws IOException {
152152
if (out.getVersion().onOrAfter(Version.V_7_7_0)) {
153153
out.writeVLong(boxplotUsage);
154154
}
155-
out.writeVLong(cumulativeCardinalityUsage);
155+
out.writeZLong(cumulativeCardinalityUsage);
156156
if (out.getVersion().onOrAfter(Version.V_7_7_0)) {
157157
out.writeVLong(stringStatsUsage);
158158
out.writeVLong(topMetricsUsage);
@@ -185,5 +185,21 @@ public long getStringStatsUsage() {
185185
public long getTopMetricsUsage() {
186186
return topMetricsUsage;
187187
}
188+
189+
@Override
190+
public boolean equals(Object o) {
191+
if (this == o) return true;
192+
if (o == null || getClass() != o.getClass()) return false;
193+
NodeResponse that = (NodeResponse) o;
194+
return boxplotUsage == that.boxplotUsage &&
195+
cumulativeCardinalityUsage == that.cumulativeCardinalityUsage &&
196+
stringStatsUsage == that.stringStatsUsage &&
197+
topMetricsUsage == that.topMetricsUsage;
198+
}
199+
200+
@Override
201+
public int hashCode() {
202+
return Objects.hash(boxplotUsage, cumulativeCardinalityUsage, stringStatsUsage, topMetricsUsage);
203+
}
188204
}
189205
}

0 commit comments

Comments
 (0)