Skip to content

Commit ddb1d3c

Browse files
author
David Roberts
committed
[ML] Add an assertion on annotations mappings to upgrade test
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 elastic#62325
1 parent 9eff4e8 commit ddb1d3c

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
@@ -51,6 +51,7 @@ public void testMappingsUpgrade() throws Exception {
5151
break;
5252
case UPGRADED:
5353
assertUpgradedResultsMappings();
54+
assertUpgradedAnnotationsMappings();
5455
closeAndReopenTestJob();
5556
assertUpgradedConfigMappings();
5657
break;
@@ -124,6 +125,37 @@ private void assertUpgradedResultsMappings() throws Exception {
124125
});
125126
}
126127

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

0 commit comments

Comments
 (0)