Skip to content

Commit 89599ba

Browse files
authored
[ML] Update ML mappings upgrade test and extend to config index (#61830)
The ML mappings upgrade test had become useless as it was checking a field that has been the same since 6.5. This commit switches to a field that was changed in 7.9. Additionally, the test only used to check the results index mappings. This commit also adds checking for the config index. Backport of #61340
1 parent d268540 commit 89599ba

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlMappingsUpgradeIT.java

+44-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.stream.Collectors;
2525
import java.util.stream.Stream;
2626

27+
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
28+
2729
public class MlMappingsUpgradeIT extends AbstractUpgradeTestCase {
2830

2931
private static final String JOB_ID = "ml-mappings-upgrade-job";
@@ -48,7 +50,9 @@ public void testMappingsUpgrade() throws Exception {
4850
// We don't know whether the job is on an old or upgraded node, so cannot assert that the mappings have been upgraded
4951
break;
5052
case UPGRADED:
51-
assertUpgradedMappings();
53+
assertUpgradedResultsMappings();
54+
closeAndReopenTestJob();
55+
assertUpgradedConfigMappings();
5256
break;
5357
default:
5458
throw new UnsupportedOperationException("Unknown cluster type [" + CLUSTER_TYPE + "]");
@@ -77,8 +81,21 @@ private void createAndOpenTestJob() throws IOException {
7781
assertEquals(200, response.getStatusLine().getStatusCode());
7882
}
7983

84+
// Doing this should force the config index mappings to be upgraded,
85+
// when the finished time is cleared on reopening the job
86+
private void closeAndReopenTestJob() throws IOException {
87+
88+
Request closeJob = new Request("POST", "_ml/anomaly_detectors/" + JOB_ID + "/_close");
89+
Response response = client().performRequest(closeJob);
90+
assertEquals(200, response.getStatusLine().getStatusCode());
91+
92+
Request openJob = new Request("POST", "_ml/anomaly_detectors/" + JOB_ID + "/_open");
93+
response = client().performRequest(openJob);
94+
assertEquals(200, response.getStatusLine().getStatusCode());
95+
}
96+
8097
@SuppressWarnings("unchecked")
81-
private void assertUpgradedMappings() throws Exception {
98+
private void assertUpgradedResultsMappings() throws Exception {
8299

83100
assertBusy(() -> {
84101
Request getMappings = new Request("GET", XPackRestTestHelper.resultsWriteAlias(JOB_ID) + "/_mappings");
@@ -97,17 +114,34 @@ private void assertUpgradedMappings() throws Exception {
97114
}
98115
}
99116
assertNotNull(indexLevel);
100-
Map<String, Object> mappingsLevel = (Map<String, Object>) indexLevel.get("mappings");
101-
assertNotNull(mappingsLevel);
102117

103-
Map<String, Object> metaLevel = (Map<String, Object>) mappingsLevel.get("_meta");
104-
assertEquals(Collections.singletonMap("version", Version.CURRENT.toString()), metaLevel);
105-
Map<String, Object> propertiesLevel = (Map<String, Object>) mappingsLevel.get("properties");
106-
assertNotNull(propertiesLevel);
118+
assertEquals(Version.CURRENT.toString(), extractValue("mappings._meta.version", indexLevel));
119+
120+
// TODO: as the years go by, the field we assert on here should be changed
121+
// to the most recent field we've added that is NOT of type "keyword"
122+
assertEquals("Incorrect type for peak_model_bytes in " + responseLevel, "long",
123+
extractValue("mappings.properties.model_size_stats.properties.peak_model_bytes.type", indexLevel));
124+
});
125+
}
126+
127+
@SuppressWarnings("unchecked")
128+
private void assertUpgradedConfigMappings() throws Exception {
129+
130+
assertBusy(() -> {
131+
Request getMappings = new Request("GET", ".ml-config/_mappings");
132+
Response response = client().performRequest(getMappings);
133+
134+
Map<String, Object> responseLevel = entityAsMap(response);
135+
assertNotNull(responseLevel);
136+
Map<String, Object> indexLevel = (Map<String, Object>) responseLevel.get(".ml-config");
137+
assertNotNull(indexLevel);
138+
139+
assertEquals(Version.CURRENT.toString(), extractValue("mappings._meta.version", indexLevel));
140+
107141
// TODO: as the years go by, the field we assert on here should be changed
108142
// to the most recent field we've added that is NOT of type "keyword"
109-
Map<String, Object> fieldLevel = (Map<String, Object>) propertiesLevel.get("multi_bucket_impact");
110-
assertEquals(Collections.singletonMap("type", "double"), fieldLevel);
143+
assertEquals("Incorrect type for annotations_enabled in " + responseLevel, "boolean",
144+
extractValue("mappings.properties.model_plot_config.properties.annotations_enabled.type", indexLevel));
111145
});
112146
}
113147
}

0 commit comments

Comments
 (0)