Skip to content

Commit 3d5c13f

Browse files
authored
[ML] Add an assertion on annotations mappings to upgrade test (#62331)
The annotations index is not covered by the comparison between mappings and templates, as it does not use an index template. This commit adds an assertion on annotations index mappings that will fail if the mappings are not upgraded as expected. Backport of #62325
1 parent ec335c7 commit 3d5c13f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public void testMappingsUpgrade() throws Exception {
5353
break;
5454
case UPGRADED:
5555
assertUpgradedResultsMappings();
56+
assertUpgradedAnnotationsMappings();
5657
closeAndReopenTestJob();
5758
assertUpgradedConfigMappings();
5859
assertMappingsMatchTemplates();
@@ -127,6 +128,37 @@ private void assertUpgradedResultsMappings() throws Exception {
127128
});
128129
}
129130

131+
@SuppressWarnings("unchecked")
132+
private void assertUpgradedAnnotationsMappings() throws Exception {
133+
134+
assertBusy(() -> {
135+
Request getMappings = new Request("GET", ".ml-annotations-write/_mappings");
136+
Response response = client().performRequest(getMappings);
137+
138+
Map<String, Object> responseLevel = entityAsMap(response);
139+
assertNotNull(responseLevel);
140+
Map<String, Object> indexLevel = null;
141+
// The name of the concrete index underlying the annotations index write alias may or may not have been
142+
// changed by the upgrade process (depending on what other tests are being run and the order they're run
143+
// in), so navigating to the next level of the tree must account for both cases
144+
for (Map.Entry<String, Object> entry : responseLevel.entrySet()) {
145+
if (entry.getKey().startsWith(".ml-annotations-")) {
146+
indexLevel = (Map<String, Object>) entry.getValue();
147+
break;
148+
}
149+
}
150+
assertNotNull(indexLevel);
151+
152+
assertEquals(Version.CURRENT.toString(), extractValue("mappings._meta.version", indexLevel));
153+
154+
// TODO: as the years go by, the field we assert on here should be changed
155+
// to the most recent field we've added that would be incorrectly mapped by dynamic
156+
// mappings, for example a field we want to be "keyword" incorrectly mapped as "text"
157+
assertEquals("Incorrect type for event in " + responseLevel, "keyword",
158+
extractValue("mappings.properties.event.type", indexLevel));
159+
});
160+
}
161+
130162
@SuppressWarnings("unchecked")
131163
private void assertUpgradedConfigMappings() throws Exception {
132164

0 commit comments

Comments
 (0)