Skip to content

Commit 44340f7

Browse files
authored
Don't emit deprecation issue for compatible date format patterns (#127418)
1 parent d4ef0d3 commit 44340f7

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

docs/changelog/127418.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127418
2+
summary: Don't emit deprecation issue for compatible date format patterns
3+
area: Infra/Core
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/common/time/DateUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.time.Instant;
2121
import java.time.ZoneId;
2222
import java.time.ZonedDateTime;
23+
import java.util.Arrays;
2324
import java.util.Collections;
2425
import java.util.HashMap;
2526
import java.util.Map;
@@ -481,6 +482,6 @@ static void checkTextualDateFormats(String format) {
481482
}
482483

483484
public static boolean containsCompatOnlyDateFormat(String format) {
484-
return LEGACY_DATE_FORMAT_MATCHER.test(format);
485+
return LEGACY_DATE_FORMAT_MATCHER.test(format) && Arrays.stream(FormatNames.values()).noneMatch(f -> f.getName().equals(format));
485486
}
486487
}

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationCheckerTests.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
2222
import org.elasticsearch.common.collect.ImmutableOpenMap;
2323
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.common.time.FormatNames;
2425
import org.elasticsearch.core.TimeValue;
2526
import org.elasticsearch.index.IndexMode;
2627
import org.elasticsearch.index.IndexSettings;
@@ -36,6 +37,7 @@
3637

3738
import java.util.ArrayList;
3839
import java.util.List;
40+
import java.util.Locale;
3941
import java.util.Map;
4042

4143
import static java.util.Collections.singletonList;
@@ -234,6 +236,45 @@ public void testOldIndicesWithIncompatibleDateFormatsCheck() {
234236
assertEquals(singletonList(expected), issues);
235237
}
236238

239+
public void testOldIndicesWithCompatibleDateFormatter() {
240+
String pattern = randomFrom(FormatNames.values()).getName();
241+
242+
IndexMetadata indexMetadata = IndexMetadata.builder("test")
243+
.settings(settings(OLD_VERSION))
244+
.numberOfShards(1)
245+
.numberOfReplicas(0)
246+
.state(indexMetdataState)
247+
.putMapping(String.format(Locale.ROOT, """
248+
{
249+
"properties": {
250+
"date": {
251+
"type": "date",
252+
"format": "%s"
253+
}
254+
}
255+
}""", pattern))
256+
.build();
257+
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
258+
.metadata(Metadata.builder().put(indexMetadata, true))
259+
.blocks(clusterBlocksForIndices(indexMetadata))
260+
.build();
261+
DeprecationIssue expected = new DeprecationIssue(
262+
DeprecationIssue.Level.CRITICAL,
263+
"Old index with a compatibility version < 8.0",
264+
"https://www.elastic.co/guide/en/elastic-stack/9.0/upgrading-elastic-stack.html",
265+
"This index has version: " + OLD_VERSION.toReleaseVersion(),
266+
false,
267+
singletonMap("reindex_required", true)
268+
);
269+
Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
270+
clusterState,
271+
new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
272+
emptyPrecomputedData
273+
);
274+
List<DeprecationIssue> issues = issuesByIndex.get("test");
275+
assertEquals(singletonList(expected), issues);
276+
}
277+
237278
private IndexMetadata indexMetadata(String indexName, IndexVersion indexVersion) {
238279
return IndexMetadata.builder(indexName)
239280
.settings(settings(indexVersion))

0 commit comments

Comments
 (0)