Skip to content

Commit 916a272

Browse files
authored
[ML] Add an assertion on annotations mappings to upgrade test (#62325)
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.
1 parent 3ccbebe commit 916a272

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
@@ -52,6 +52,7 @@ public void testMappingsUpgrade() throws Exception {
5252
break;
5353
case UPGRADED:
5454
assertUpgradedResultsMappings();
55+
assertUpgradedAnnotationsMappings();
5556
closeAndReopenTestJob();
5657
assertUpgradedConfigMappings();
5758
IndexMappingTemplateAsserter.assertMlMappingsMatchTemplates(client());
@@ -126,6 +127,37 @@ private void assertUpgradedResultsMappings() throws Exception {
126127
});
127128
}
128129

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

0 commit comments

Comments
 (0)