Skip to content

Commit

Permalink
take into account 8.17.x transport version
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvg committed Nov 28, 2024
1 parent ddf13c1 commit 9ff2469
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ static TransportVersion def(int id) {
public static final TransportVersion ESQL_ENRICH_RUNTIME_WARNINGS = def(8_796_00_0);
public static final TransportVersion INGEST_PIPELINE_CONFIGURATION_AS_MAP = def(8_797_00_0);
public static final TransportVersion LOGSDB_TELEMETRY_CUSTOM_CUTOFF_DATE_FIX_8_17 = def(8_797_00_1);
public static final TransportVersion SOURCE_MODE_TELEMETRY_FIX_8_17 = def(8_797_00_2);
public static final TransportVersion INDEXING_PRESSURE_THROTTLING_STATS = def(8_798_00_0);
public static final TransportVersion REINDEX_DATA_STREAMS = def(8_799_00_0);
public static final TransportVersion ESQL_REMOVE_NODE_LEVEL_PLAN = def(8_800_00_0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package org.elasticsearch.action.admin.cluster.stats;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.TransportVersions;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata;
Expand Down Expand Up @@ -261,7 +262,8 @@ private static int countOccurrences(String script, Pattern pattern) {
}
fieldTypeStats = in.readCollectionAsImmutableList(FieldStats::new);
runtimeFieldStats = in.readCollectionAsImmutableList(RuntimeFieldStats::new);
sourceModeUsageCount = in.getTransportVersion().onOrAfter(TransportVersions.SOURCE_MODE_TELEMETRY)
var transportVersion = in.getTransportVersion();
sourceModeUsageCount = canReadOrWriteSourceModeTelemetry(transportVersion)
? in.readImmutableMap(StreamInput::readString, StreamInput::readVInt)
: Map.of();
}
Expand All @@ -275,11 +277,17 @@ public void writeTo(StreamOutput out) throws IOException {
}
out.writeCollection(fieldTypeStats);
out.writeCollection(runtimeFieldStats);
if (out.getTransportVersion().onOrAfter(TransportVersions.SOURCE_MODE_TELEMETRY)) {
var transportVersion = out.getTransportVersion();
if (canReadOrWriteSourceModeTelemetry(transportVersion)) {
out.writeMap(sourceModeUsageCount, StreamOutput::writeVInt);
}
}

private static boolean canReadOrWriteSourceModeTelemetry(TransportVersion version) {
return version.isPatchFrom(TransportVersions.SOURCE_MODE_TELEMETRY_FIX_8_17)
|| version.onOrAfter(TransportVersions.SOURCE_MODE_TELEMETRY);
}

private static OptionalLong ofNullable(Long l) {
return l == null ? OptionalLong.empty() : OptionalLong.of(l);
}
Expand Down

0 comments on commit 9ff2469

Please sign in to comment.