Skip to content

Commit 1a05a5a

Browse files
authored
Introduce deprecation categories (#67443)
Closes #64824. Introduce the concept of categories to deprecation logging. Every location where we log a deprecation message must now include a deprecation category.
1 parent ea395d3 commit 1a05a5a

File tree

82 files changed

+336
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+336
-161
lines changed

modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
117117
import org.elasticsearch.cluster.service.ClusterService;
118118
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
119+
import org.elasticsearch.common.logging.DeprecationCategory;
119120
import org.elasticsearch.common.logging.DeprecationLogger;
120121
import org.elasticsearch.common.regex.Regex;
121122
import org.elasticsearch.common.settings.Settings;
@@ -253,7 +254,7 @@ public TokenStream create(TokenStream tokenStream) {
253254
"The [edgeNGram] token filter name was deprecated in 6.4 and cannot be used in new indices. "
254255
+ "Please change the filter name to [edge_ngram] instead.");
255256
} else {
256-
deprecationLogger.deprecate("edgeNGram_deprecation",
257+
deprecationLogger.deprecate(DeprecationCategory.ANALYSIS, "edgeNGram_deprecation",
257258
"The [edgeNGram] token filter name is deprecated and will be removed in a future version. "
258259
+ "Please change the filter name to [edge_ngram] instead.");
259260
}
@@ -290,7 +291,7 @@ public TokenStream create(TokenStream tokenStream) {
290291
"The [nGram] token filter name was deprecated in 6.4 and cannot be used in new indices. "
291292
+ "Please change the filter name to [ngram] instead.");
292293
} else {
293-
deprecationLogger.deprecate("nGram_deprecation",
294+
deprecationLogger.deprecate(DeprecationCategory.ANALYSIS, "nGram_deprecation",
294295
"The [nGram] token filter name is deprecated and will be removed in a future version. "
295296
+ "Please change the filter name to [ngram] instead.");
296297
}
@@ -346,7 +347,7 @@ public Map<String, AnalysisProvider<TokenizerFactory>> getTokenizers() {
346347
throw new IllegalArgumentException("The [nGram] tokenizer name was deprecated in 7.6. "
347348
+ "Please use the tokenizer name to [ngram] for indices created in versions 8 or higher instead.");
348349
} else if (indexSettings.getIndexVersionCreated().onOrAfter(org.elasticsearch.Version.V_7_6_0)) {
349-
deprecationLogger.deprecate("nGram_tokenizer_deprecation",
350+
deprecationLogger.deprecate(DeprecationCategory.ANALYSIS, "nGram_tokenizer_deprecation",
350351
"The [nGram] tokenizer name is deprecated and will be removed in a future version. "
351352
+ "Please change the tokenizer name to [ngram] instead.");
352353
}
@@ -358,7 +359,7 @@ public Map<String, AnalysisProvider<TokenizerFactory>> getTokenizers() {
358359
throw new IllegalArgumentException("The [edgeNGram] tokenizer name was deprecated in 7.6. "
359360
+ "Please use the tokenizer name to [edge_nGram] for indices created in versions 8 or higher instead.");
360361
} else if (indexSettings.getIndexVersionCreated().onOrAfter(org.elasticsearch.Version.V_7_6_0)) {
361-
deprecationLogger.deprecate("edgeNGram_tokenizer_deprecation",
362+
deprecationLogger.deprecate(DeprecationCategory.ANALYSIS, "edgeNGram_tokenizer_deprecation",
362363
"The [edgeNGram] tokenizer name is deprecated and will be removed in a future version. "
363364
+ "Please change the tokenizer name to [edge_ngram] instead.");
364365
}
@@ -551,7 +552,7 @@ public List<PreConfiguredTokenizer> getPreConfiguredTokenizers() {
551552
throw new IllegalArgumentException("The [nGram] tokenizer name was deprecated in 7.6. "
552553
+ "Please use the tokenizer name to [ngram] for indices created in versions 8 or higher instead.");
553554
} else if (version.onOrAfter(org.elasticsearch.Version.V_7_6_0)) {
554-
deprecationLogger.deprecate("nGram_tokenizer_deprecation",
555+
deprecationLogger.deprecate(DeprecationCategory.ANALYSIS, "nGram_tokenizer_deprecation",
555556
"The [nGram] tokenizer name is deprecated and will be removed in a future version. "
556557
+ "Please change the tokenizer name to [ngram] instead.");
557558
}
@@ -562,7 +563,7 @@ public List<PreConfiguredTokenizer> getPreConfiguredTokenizers() {
562563
throw new IllegalArgumentException("The [edgeNGram] tokenizer name was deprecated in 7.6. "
563564
+ "Please use the tokenizer name to [edge_ngram] for indices created in versions 8 or higher instead.");
564565
} else if (version.onOrAfter(org.elasticsearch.Version.V_7_6_0)) {
565-
deprecationLogger.deprecate("edgeNGram_tokenizer_deprecation",
566+
deprecationLogger.deprecate(DeprecationCategory.ANALYSIS, "edgeNGram_tokenizer_deprecation",
566567
"The [edgeNGram] tokenizer name is deprecated and will be removed in a future version. "
567568
+ "Please change the tokenizer name to [edge_ngram] instead.");
568569
}

modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/SynonymTokenFilterFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.lucene.analysis.TokenStream;
2424
import org.apache.lucene.analysis.synonym.SynonymFilter;
2525
import org.apache.lucene.analysis.synonym.SynonymMap;
26+
import org.elasticsearch.common.logging.DeprecationCategory;
2627
import org.elasticsearch.common.logging.DeprecationLogger;
2728
import org.elasticsearch.common.settings.Settings;
2829
import org.elasticsearch.env.Environment;
@@ -57,7 +58,7 @@ public class SynonymTokenFilterFactory extends AbstractTokenFilterFactory {
5758
this.settings = settings;
5859

5960
if (settings.get("ignore_case") != null) {
60-
DEPRECATION_LOGGER.deprecate("synonym_ignore_case_option",
61+
DEPRECATION_LOGGER.deprecate(DeprecationCategory.ANALYSIS, "synonym_ignore_case_option",
6162
"The ignore_case option on the synonym_graph filter is deprecated. " +
6263
"Instead, insert a lowercase filter in the filter chain before the synonym_graph filter.");
6364
}

modules/ingest-user-agent/src/main/java/org/elasticsearch/ingest/useragent/UserAgentProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.ingest.useragent;
2121

22+
import org.elasticsearch.common.logging.DeprecationCategory;
2223
import org.elasticsearch.common.logging.DeprecationLogger;
2324
import org.elasticsearch.ingest.AbstractProcessor;
2425
import org.elasticsearch.ingest.IngestDocument;
@@ -186,7 +187,7 @@ public UserAgentProcessor create(Map<String, Processor.Factory> factories, Strin
186187
boolean ignoreMissing = readBooleanProperty(TYPE, processorTag, config, "ignore_missing", false);
187188
Object ecsValue = config.remove("ecs");
188189
if (ecsValue != null) {
189-
deprecationLogger.deprecate("ingest_useragent_ecs_settings",
190+
deprecationLogger.deprecate(DeprecationCategory.SETTINGS, "ingest_useragent_ecs_settings",
190191
"setting [ecs] is deprecated as ECS format is the default and only option");
191192
}
192193

modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
3434
import org.elasticsearch.cluster.service.ClusterService;
3535
import org.elasticsearch.common.Strings;
36+
import org.elasticsearch.common.logging.DeprecationCategory;
3637
import org.elasticsearch.common.logging.DeprecationLogger;
3738
import org.elasticsearch.common.regex.Regex;
3839
import org.elasticsearch.common.settings.Settings;
@@ -66,7 +67,7 @@ void initialValidation(ReindexRequest request) {
6667
state);
6768
SearchSourceBuilder searchSource = request.getSearchRequest().source();
6869
if (searchSource != null && searchSource.sorts() != null && searchSource.sorts().isEmpty() == false) {
69-
deprecationLogger.deprecate("reindex_sort", SORT_DEPRECATED_MESSAGE);
70+
deprecationLogger.deprecate(DeprecationCategory.API, "reindex_sort", SORT_DEPRECATED_MESSAGE);
7071
}
7172
}
7273

plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.logging.log4j.Logger;
2424
import org.elasticsearch.cloud.azure.classic.management.AzureComputeService;
2525
import org.elasticsearch.cloud.azure.classic.management.AzureComputeServiceImpl;
26+
import org.elasticsearch.common.logging.DeprecationCategory;
2627
import org.elasticsearch.common.logging.DeprecationLogger;
2728
import org.elasticsearch.common.network.NetworkService;
2829
import org.elasticsearch.common.settings.Setting;
@@ -48,7 +49,7 @@ public class AzureDiscoveryPlugin extends Plugin implements DiscoveryPlugin {
4849

4950
public AzureDiscoveryPlugin(Settings settings) {
5051
this.settings = settings;
51-
deprecationLogger.deprecate("azure_discovery_plugin", "azure classic discovery plugin is deprecated.");
52+
deprecationLogger.deprecate(DeprecationCategory.PLUGINS, "azure_discovery_plugin", "azure classic discovery plugin is deprecated.");
5253
logger.trace("starting azure classic discovery plugin...");
5354
}
5455

plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2ClientSettings.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.amazonaws.auth.BasicSessionCredentials;
2727
import org.apache.logging.log4j.LogManager;
2828
import org.apache.logging.log4j.Logger;
29+
import org.elasticsearch.common.logging.DeprecationCategory;
2930
import org.elasticsearch.common.logging.DeprecationLogger;
3031
import org.elasticsearch.common.settings.SecureSetting;
3132
import org.elasticsearch.common.settings.SecureString;
@@ -135,12 +136,12 @@ static AWSCredentials loadCredentials(Settings settings) {
135136
return null;
136137
} else {
137138
if (key.length() == 0) {
138-
deprecationLogger.deprecate("ec2_invalid_settings",
139+
deprecationLogger.deprecate(DeprecationCategory.SETTINGS, "ec2_invalid_settings",
139140
"Setting [{}] is set but [{}] is not, which will be unsupported in future",
140141
SECRET_KEY_SETTING.getKey(), ACCESS_KEY_SETTING.getKey());
141142
}
142143
if (secret.length() == 0) {
143-
deprecationLogger.deprecate("ec2_invalid_settings",
144+
deprecationLogger.deprecate(DeprecationCategory.SETTINGS, "ec2_invalid_settings",
144145
"Setting [{}] is set but [{}] is not, which will be unsupported in future",
145146
ACCESS_KEY_SETTING.getKey(), SECRET_KEY_SETTING.getKey());
146147
}

qa/evil-tests/src/test/java/org/elasticsearch/common/logging/EvilLoggerTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public void testConcurrentDeprecationLogger() throws IOException, UserException,
128128
}
129129
for (int j = 0; j < iterations; j++) {
130130
for (final Integer id : ids) {
131-
deprecationLogger.deprecate(Integer.toString(id), "This is a maybe logged deprecation message" + id);
131+
deprecationLogger.deprecate(DeprecationCategory.OTHER, Integer.toString(id),
132+
"This is a maybe logged deprecation message" + id);
132133
}
133134
}
134135

qa/logging-config/src/test/java/org/elasticsearch/common/logging/JsonLoggerTests.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void tearDown() throws Exception {
8989
public void testDeprecatedMessageWithoutXOpaqueId() throws IOException {
9090
final DeprecationLogger testLogger = DeprecationLogger.getLogger("test");
9191

92-
testLogger.deprecate("a key", "deprecated message1");
92+
testLogger.deprecate(DeprecationCategory.OTHER, "a key", "deprecated message1");
9393

9494
final Path path = PathUtils.get(System.getProperty("es.logs.base_path"),
9595
System.getProperty("es.logs.cluster_name") + "_deprecated.json");
@@ -111,7 +111,8 @@ public void testDeprecatedMessageWithoutXOpaqueId() throws IOException {
111111
hasEntry("data_stream.namespace", "default"),
112112
hasEntry("ecs.version", DeprecatedMessage.ECS_VERSION),
113113
hasEntry("key", "a key"),
114-
not(hasKey("x-opaque-id"))
114+
not(hasKey("x-opaque-id")),
115+
hasEntry("elasticsearch.event.category", "other")
115116
)
116117
)
117118
);
@@ -124,7 +125,7 @@ public void testDeprecatedMessage() throws Exception {
124125
withThreadContext(threadContext -> {
125126
threadContext.putHeader(Task.X_OPAQUE_ID, "someId");
126127
final DeprecationLogger testLogger = DeprecationLogger.getLogger("test");
127-
testLogger.deprecate("someKey", "deprecated message1");
128+
testLogger.deprecate(DeprecationCategory.OTHER, "someKey", "deprecated message1");
128129

129130
final Path path = PathUtils.get(
130131
System.getProperty("es.logs.base_path"),
@@ -149,7 +150,8 @@ public void testDeprecatedMessage() throws Exception {
149150
hasEntry("data_stream.namespace", "default"),
150151
hasEntry("ecs.version", DeprecatedMessage.ECS_VERSION),
151152
hasEntry("key", "someKey"),
152-
hasEntry("x-opaque-id", "someId")
153+
hasEntry("x-opaque-id", "someId"),
154+
hasEntry("elasticsearch.event.category", "other")
153155
)
154156
)
155157
);
@@ -336,8 +338,8 @@ public void testDuplicateLogMessages() throws Exception {
336338
// For the same key and X-Opaque-ID deprecation should be once
337339
withThreadContext(threadContext -> {
338340
threadContext.putHeader(Task.X_OPAQUE_ID, "ID1");
339-
deprecationLogger.deprecate("key", "message1");
340-
deprecationLogger.deprecate("key", "message2");
341+
deprecationLogger.deprecate(DeprecationCategory.OTHER, "key", "message1");
342+
deprecationLogger.deprecate(DeprecationCategory.OTHER, "key", "message2");
341343
assertWarnings("message1", "message2");
342344

343345
final Path path = PathUtils.get(System.getProperty("es.logs.base_path"),
@@ -354,7 +356,8 @@ public void testDuplicateLogMessages() throws Exception {
354356
hasEntry("cluster.name", "elasticsearch"),
355357
hasEntry("node.name", "sample-name"),
356358
hasEntry("message", "message1"),
357-
hasEntry("x-opaque-id", "ID1"))
359+
hasEntry("x-opaque-id", "ID1"),
360+
hasEntry("elasticsearch.event.category", "other"))
358361
)
359362
);
360363
}
@@ -364,8 +367,8 @@ public void testDuplicateLogMessages() throws Exception {
364367
//continuing with message1-ID1 in logs already, adding a new deprecation log line with message2-ID2
365368
withThreadContext(threadContext -> {
366369
threadContext.putHeader(Task.X_OPAQUE_ID, "ID2");
367-
deprecationLogger.deprecate("key", "message1");
368-
deprecationLogger.deprecate("key", "message2");
370+
deprecationLogger.deprecate(DeprecationCategory.OTHER, "key", "message1");
371+
deprecationLogger.deprecate(DeprecationCategory.OTHER, "key", "message2");
369372
assertWarnings("message1", "message2");
370373

371374
final Path path = PathUtils.get(
@@ -385,7 +388,8 @@ public void testDuplicateLogMessages() throws Exception {
385388
hasEntry("cluster.name", "elasticsearch"),
386389
hasEntry("node.name", "sample-name"),
387390
hasEntry("message", "message1"),
388-
hasEntry("x-opaque-id", "ID1")
391+
hasEntry("x-opaque-id", "ID1"),
392+
hasEntry("elasticsearch.event.category", "other")
389393
),
390394
allOf(
391395
hasEntry("type", "deprecation"),
@@ -394,7 +398,8 @@ public void testDuplicateLogMessages() throws Exception {
394398
hasEntry("cluster.name", "elasticsearch"),
395399
hasEntry("node.name", "sample-name"),
396400
hasEntry("message", "message1"),
397-
hasEntry("x-opaque-id", "ID2")
401+
hasEntry("x-opaque-id", "ID2"),
402+
hasEntry("elasticsearch.event.category", "other")
398403
)
399404
)
400405
);

server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.cluster.service.ClusterService;
3131
import org.elasticsearch.common.collect.ImmutableOpenMap;
3232
import org.elasticsearch.common.inject.Inject;
33+
import org.elasticsearch.common.logging.DeprecationCategory;
3334
import org.elasticsearch.common.logging.DeprecationLogger;
3435
import org.elasticsearch.common.util.concurrent.ThreadContext;
3536
import org.elasticsearch.indices.SystemIndices;
@@ -112,7 +113,7 @@ private static void checkSystemIndexAccess(GetAliasesRequest request, SystemIndi
112113
}
113114
}
114115
if (systemIndicesNames.isEmpty() == false) {
115-
deprecationLogger.deprecate("open_system_index_access",
116+
deprecationLogger.deprecate(DeprecationCategory.API, "open_system_index_access",
116117
"this request accesses system indices: {}, but in a future major version, direct access to system " +
117118
"indices will be prevented by default", systemIndicesNames);
118119
} else {
@@ -125,7 +126,7 @@ private static void checkSystemAliasAccess(GetAliasesRequest request, SystemIndi
125126
.filter(alias -> systemIndices.isSystemIndex(alias))
126127
.collect(Collectors.toList());
127128
if (systemAliases.isEmpty() == false) {
128-
deprecationLogger.deprecate("open_system_alias_access",
129+
deprecationLogger.deprecate(DeprecationCategory.API, "open_system_alias_access",
129130
"this request accesses aliases with names reserved for system indices: {}, but in a future major version, direct" +
130131
"access to system indices and their aliases will not be allowed", systemAliases);
131132
}

server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.common.Nullable;
2929
import org.elasticsearch.common.Strings;
3030
import org.elasticsearch.common.collect.ImmutableOpenMap;
31+
import org.elasticsearch.common.logging.DeprecationCategory;
3132
import org.elasticsearch.common.logging.DeprecationLogger;
3233
import org.elasticsearch.common.regex.Regex;
3334
import org.elasticsearch.common.time.DateFormatter;
@@ -321,7 +322,7 @@ private void checkSystemIndexAccess(Context context, Metadata metadata, Set<Inde
321322
.sorted() // reliable order for testing
322323
.collect(Collectors.toList());
323324
if (resolvedSystemIndices.isEmpty() == false) {
324-
deprecationLogger.deprecate("open_system_index_access",
325+
deprecationLogger.deprecate(DeprecationCategory.API, "open_system_index_access",
325326
"this request accesses system indices: {}, but in a future major version, direct access to system " +
326327
"indices will be prevented by default", resolvedSystemIndices);
327328
}

0 commit comments

Comments
 (0)