Skip to content

Commit bc745a5

Browse files
authored
[8.x] Optimize MlConfigVersion#getMinMaxMlConfigVersion (#125432) (#125500)
* Optimize MlConfigVersion#getMinMaxMlConfigVersion (#125432) * Revert part of #125432 The logic is more complicated on 8.x than on main, so we need more of the code to remain as it originally was.
1 parent d484828 commit bc745a5

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ public static MlConfigVersion getMlConfigVersionForNode(DiscoveryNode node) {
304304
return fromId(node.getPre811VersionId().orElseThrow(() -> new IllegalStateException("getting legacy version id not possible")));
305305
}
306306

307+
// supports fromString below
308+
private static final Pattern ML_VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)(?:-\\w+)?$");
309+
307310
// Parse an MlConfigVersion from a string.
308311
// Note that version "8.10.x" and "8.11.0" are silently converted to "10.0.0".
309312
// This is to support upgrade scenarios in pre-prod QA environments.
@@ -319,7 +322,7 @@ public static MlConfigVersion fromString(String str) {
319322
if (str.startsWith("8.10.") || str.equals("8.11.0")) {
320323
return V_10;
321324
}
322-
Matcher matcher = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)(?:-\\w+)?$").matcher(str);
325+
Matcher matcher = ML_VERSION_PATTERN.matcher(str);
323326
if (matcher.matches() == false) {
324327
throw new IllegalArgumentException("ML config version [" + str + "] not valid");
325328
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetTrainedModelsStatsAction.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ public static class TrainedModelStats implements ToXContentObject, Writeable {
9191
private final AssignmentStats deploymentStats;
9292
private final int pipelineCount;
9393

94-
private static final IngestStats EMPTY_INGEST_STATS = new IngestStats(
95-
IngestStats.Stats.IDENTITY,
96-
Collections.emptyList(),
97-
Collections.emptyMap()
98-
);
99-
10094
public TrainedModelStats(
10195
String modelId,
10296
TrainedModelSizeStats modelSizeStats,
@@ -107,7 +101,7 @@ public TrainedModelStats(
107101
) {
108102
this.modelId = Objects.requireNonNull(modelId);
109103
this.modelSizeStats = modelSizeStats;
110-
this.ingestStats = ingestStats == null ? EMPTY_INGEST_STATS : ingestStats;
104+
this.ingestStats = ingestStats == null ? IngestStats.IDENTITY : ingestStats;
111105
if (pipelineCount < 0) {
112106
throw new ElasticsearchException("[{}] must be a greater than or equal to 0", PIPELINE_COUNT.getPreferredName());
113107
}

0 commit comments

Comments
 (0)