From 6b2620979b7130bb1f68f168bf77176e03c2bdb5 Mon Sep 17 00:00:00 2001 From: Rory Hunter Date: Thu, 16 Apr 2020 16:19:45 +0100 Subject: [PATCH] Always use deprecateAndMaybeLog for deprecation warnings (#55115) Backport of #55115. Closes #53137. Replace calls to deprecate(String,Object...) with deprecateAndMaybeLog(...), with an appropriate key, so that all messages can potentially be deduplicated. --- .../common/SynonymTokenFilterFactory.java | 3 +- .../index/reindex/ReindexValidator.java | 2 +- .../azure/classic/AzureDiscoveryPlugin.java | 2 +- .../discovery/ec2/Ec2ClientSettings.java | 6 ++-- .../common/logging/EvilLoggerTests.java | 27 ----------------- .../http/TestDeprecatedQueryBuilder.java | 2 +- .../http/TestDeprecationHeaderRestAction.java | 2 +- .../metadata/MetadataCreateIndexService.java | 3 +- .../MetadataIndexTemplateService.java | 4 +-- .../common/logging/DeprecationLogger.java | 22 +++++--------- .../common/unit/ByteSizeValue.java | 3 +- .../xcontent/LoggingDeprecationHandler.java | 8 ++--- .../analysis/ShingleTokenFilterFactory.java | 3 +- .../index/mapper/CompletionFieldMapper.java | 3 +- .../index/mapper/FieldNamesFieldMapper.java | 3 +- .../mapper/LegacyGeoShapeFieldMapper.java | 4 +-- .../index/mapper/ObjectMapper.java | 3 +- .../RandomScoreFunctionBuilder.java | 2 +- .../index/similarity/SimilarityProviders.java | 7 +++-- .../index/similarity/SimilarityService.java | 3 +- .../rest/DeprecationRestHandler.java | 2 +- .../elasticsearch/script/ScriptMetadata.java | 4 +-- .../script/StoredScriptSource.java | 10 +++---- .../SignificantTermsAggregatorFactory.java | 3 +- .../fetch/subphase/FetchDocValuesPhase.java | 3 +- .../transport/TransportInfo.java | 2 +- .../indices/TransportAnalyzeActionTests.java | 6 ++-- .../logging/DeprecationLoggerTests.java | 6 ++-- .../index/analysis/AnalysisRegistryTests.java | 29 ++++++++++--------- .../rest/DeprecationRestHandlerTests.java | 2 +- .../query/DeprecatedQueryBuilder.java | 2 +- .../elasticsearch/xpack/core/XPackPlugin.java | 3 +- .../transform/action/GetTransformAction.java | 6 +++- .../xpack/ml/job/JobManager.java | 3 +- .../action/TransportPutRollupJobAction.java | 3 +- .../xpack/security/authc/ApiKeyService.java | 8 +++-- .../ldap/ActiveDirectorySessionFactory.java | 7 +++-- .../authc/ldap/support/SessionFactory.java | 12 +++++--- .../DeprecationRoleDescriptorConsumer.java | 2 +- ...eprecationRoleDescriptorConsumerTests.java | 3 +- .../rest/action/RestWatcherStatsAction.java | 3 +- 41 files changed, 115 insertions(+), 116 deletions(-) diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/SynonymTokenFilterFactory.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/SynonymTokenFilterFactory.java index 0d7dd672b5afe..681b2785116fb 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/SynonymTokenFilterFactory.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/SynonymTokenFilterFactory.java @@ -59,7 +59,8 @@ public class SynonymTokenFilterFactory extends AbstractTokenFilterFactory { this.settings = settings; if (settings.get("ignore_case") != null) { - DEPRECATION_LOGGER.deprecated( + DEPRECATION_LOGGER.deprecatedAndMaybeLog( + "synonym_ignore_case_option", "The ignore_case option on the synonym_graph filter is deprecated. " + "Instead, insert a lowercase filter in the filter chain before the synonym_graph filter."); } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java index fffd79e861ade..64e7fd3194456 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java @@ -67,7 +67,7 @@ void initialValidation(ReindexRequest request) { state); SearchSourceBuilder searchSource = request.getSearchRequest().source(); if (searchSource != null && searchSource.sorts() != null && searchSource.sorts().isEmpty() == false) { - deprecationLogger.deprecated(SORT_DEPRECATED_MESSAGE); + deprecationLogger.deprecatedAndMaybeLog("reindex_sort", SORT_DEPRECATED_MESSAGE); } } diff --git a/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java b/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java index 9e080af0ed565..af30a0b378ebd 100644 --- a/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java +++ b/plugins/discovery-azure-classic/src/main/java/org/elasticsearch/plugin/discovery/azure/classic/AzureDiscoveryPlugin.java @@ -48,7 +48,7 @@ public class AzureDiscoveryPlugin extends Plugin implements DiscoveryPlugin { public AzureDiscoveryPlugin(Settings settings) { this.settings = settings; - deprecationLogger.deprecated("azure classic discovery plugin is deprecated."); + deprecationLogger.deprecatedAndMaybeLog("azure_discovery_plugin", "azure classic discovery plugin is deprecated."); logger.trace("starting azure classic discovery plugin..."); } diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2ClientSettings.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2ClientSettings.java index 3de5b2ccaf913..494e564937d07 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2ClientSettings.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2ClientSettings.java @@ -135,11 +135,13 @@ static AWSCredentials loadCredentials(Settings settings) { return null; } else { if (key.length() == 0) { - deprecationLogger.deprecated("Setting [{}] is set but [{}] is not, which will be unsupported in future", + deprecationLogger.deprecatedAndMaybeLog("ec2_invalid_settings", + "Setting [{}] is set but [{}] is not, which will be unsupported in future", SECRET_KEY_SETTING.getKey(), ACCESS_KEY_SETTING.getKey()); } if (secret.length() == 0) { - deprecationLogger.deprecated("Setting [{}] is set but [{}] is not, which will be unsupported in future", + deprecationLogger.deprecatedAndMaybeLog("ec2_invalid_settings", + "Setting [{}] is set but [{}] is not, which will be unsupported in future", ACCESS_KEY_SETTING.getKey(), SECRET_KEY_SETTING.getKey()); } diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/common/logging/EvilLoggerTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/common/logging/EvilLoggerTests.java index 2e35ac9581f9a..537f91c050e9c 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/common/logging/EvilLoggerTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/common/logging/EvilLoggerTests.java @@ -104,33 +104,6 @@ public void testLocationInfoTest() throws IOException, UserException { assertLogLine(events.get(4), Level.TRACE, location, "This is a trace message"); } - public void testDeprecationLogger() throws IOException, UserException { - setupLogging("deprecation"); - - final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger("deprecation")); - - final int deprecatedIterations = randomIntBetween(0, 256); - for (int i = 0; i < deprecatedIterations; i++) { - deprecationLogger.deprecated("This is a deprecation message"); - assertWarnings("This is a deprecation message"); - } - - final String deprecationPath = - System.getProperty("es.logs.base_path") + - System.getProperty("file.separator") + - System.getProperty("es.logs.cluster_name") + - "_deprecation.log"; - final List deprecationEvents = Files.readAllLines(PathUtils.get(deprecationPath)); - assertThat(deprecationEvents.size(), equalTo(deprecatedIterations)); - for (int i = 0; i < deprecatedIterations; i++) { - assertLogLine( - deprecationEvents.get(i), - Level.WARN, - "org.elasticsearch.common.logging.DeprecationLogger\\$2\\.run", - "This is a deprecation message"); - } - } - public void testConcurrentDeprecationLogger() throws IOException, UserException, BrokenBarrierException, InterruptedException { setupLogging("deprecation"); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecatedQueryBuilder.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecatedQueryBuilder.java index 7d8115a20c9e9..7296874087459 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecatedQueryBuilder.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecatedQueryBuilder.java @@ -80,7 +80,7 @@ public String getWriteableName() { @Override protected Query doToQuery(QueryShardContext context) throws IOException { - deprecationLogger.deprecated("[{}] query is deprecated, but used on [{}] index", NAME, context.index().getName()); + deprecationLogger.deprecatedAndMaybeLog(NAME, "[{}] query is deprecated, but used on [{}] index", NAME, context.index().getName()); return Queries.newMatchAllQuery(); } diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java index c2055e060a508..d517c1134b9d5 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java @@ -106,7 +106,7 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client final Map source = parser.map(); if (source.containsKey("deprecated_settings")) { - deprecationLogger.deprecated(DEPRECATED_USAGE); + deprecationLogger.deprecatedAndMaybeLog("deprecated_settings", DEPRECATED_USAGE); settings = (List)source.get("deprecated_settings"); } else { diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java index bcfb3c7446d72..3cb72c313ca05 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java @@ -186,7 +186,8 @@ public void validateDotIndex(String index, ClusterState state, @Nullable Boolean .filter(descriptor -> descriptor.matchesIndexPattern(index)) .collect(toList()); if (matchingDescriptors.isEmpty() && (isHidden == null || isHidden == Boolean.FALSE)) { - DEPRECATION_LOGGER.deprecated("index name [{}] starts with a dot '.', in the next major version, index names " + + DEPRECATION_LOGGER.deprecatedAndMaybeLog("index_name_starts_with_dot", + "index name [{}] starts with a dot '.', in the next major version, index names " + "starting with a dot are reserved for hidden indices and system indices", index); } else if (matchingDescriptors.size() > 1) { // This should be prevented by erroring on overlapping patterns at startup time, but is here just in case. diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java index 063e9f8bed493..bdd28bf2012c5 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java @@ -333,7 +333,7 @@ ClusterState addIndexTemplateV2(final ClusterState currentState, final boolean c .collect(Collectors.joining(",")), name); logger.warn(warning); - deprecationLogger.deprecated(warning); + deprecationLogger.deprecatedAndMaybeLog("index_template_pattern_overlap", warning); } IndexTemplateV2 finalIndexTemplate = template; @@ -558,7 +558,7 @@ static ClusterState innerPutTemplate(final ClusterState currentState, PutRequest .collect(Collectors.joining(",")), request.name); logger.warn(warning); - deprecationLogger.deprecated(warning); + deprecationLogger.deprecatedAndMaybeLog("index_template_pattern_overlap", warning); } else { // Otherwise, this is a hard error, the user should use V2 index templates instead String error = String.format(Locale.ROOT, "template [%s] has index patterns %s matching patterns" + diff --git a/server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java b/server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java index fcc537e94aa43..4d21f8160385d 100644 --- a/server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java +++ b/server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java @@ -28,6 +28,7 @@ import org.elasticsearch.tasks.Task; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.BitSet; @@ -110,15 +111,8 @@ public DeprecationLogger(Logger parentLogger) { this.logger = LogManager.getLogger(name); } - /** - * Logs a deprecation message, adding a formatted warning message as a response header on the thread context. - */ - public void deprecated(String msg, Object... params) { - deprecated(THREAD_CONTEXT, msg, params); - } - // LRU set of keys used to determine if a deprecation message should be emitted to the deprecation logs - private Set keys = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap() { + private final Set keys = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>() { @Override protected boolean removeEldestEntry(final Map.Entry eldest) { return size() > 128; @@ -135,8 +129,8 @@ protected boolean removeEldestEntry(final Map.Entry eldest) { */ public void deprecatedAndMaybeLog(final String key, final String msg, final Object... params) { String xOpaqueId = getXOpaqueId(THREAD_CONTEXT); - boolean log = keys.add(xOpaqueId + key); - deprecated(THREAD_CONTEXT, msg, log, params); + boolean shouldLog = keys.add(xOpaqueId + key); + deprecated(THREAD_CONTEXT, msg, shouldLog, params); } /* @@ -234,7 +228,7 @@ void deprecated(final Set threadContexts, final String message, f deprecated(threadContexts, message, true, params); } - void deprecated(final Set threadContexts, final String message, final boolean log, final Object... params) { + void deprecated(final Set threadContexts, final String message, final boolean shouldLog, final Object... params) { final Iterator iterator = threadContexts.iterator(); if (iterator.hasNext()) { final String formattedMessage = LoggerMessageFormat.format(message, params); @@ -251,12 +245,12 @@ void deprecated(final Set threadContexts, final String message, f } } - if (log) { + if (shouldLog) { AccessController.doPrivileged(new PrivilegedAction() { @SuppressLoggerChecks(reason = "safely delegates to logger") @Override public Void run() { - /** + /* * There should be only one threadContext (in prod env), @see DeprecationLogger#setThreadContext */ String opaqueId = getXOpaqueId(threadContexts); @@ -360,7 +354,7 @@ static String escapeBackslashesAndQuotes(final String s) { assert doesNotNeedEncoding.get('%') == false : doesNotNeedEncoding; } - private static final Charset UTF_8 = Charset.forName("UTF-8"); + private static final Charset UTF_8 = StandardCharsets.UTF_8; /** * Encode a string containing characters outside of the legal characters for an RFC 7230 quoted-string. diff --git a/server/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java b/server/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java index b9cc727c64cc4..6248ca83cbe4f 100644 --- a/server/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java +++ b/server/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java @@ -245,7 +245,8 @@ private static ByteSizeValue parse(final String initialInput, final String norma } catch (final NumberFormatException e) { try { final double doubleValue = Double.parseDouble(s); - DeprecationLoggerHolder.deprecationLogger.deprecated( + DeprecationLoggerHolder.deprecationLogger.deprecatedAndMaybeLog( + "fractional_byte_values", "Fractional bytes values are deprecated. Use non-fractional bytes values instead: [{}] found for setting [{}]", initialInput, settingName); return new ByteSizeValue((long) (doubleValue * unit.toBytes(1))); diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/LoggingDeprecationHandler.java b/server/src/main/java/org/elasticsearch/common/xcontent/LoggingDeprecationHandler.java index 5feca4bfaab5a..57ef66456e8ee 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/LoggingDeprecationHandler.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/LoggingDeprecationHandler.java @@ -53,21 +53,21 @@ private LoggingDeprecationHandler() { @Override public void usedDeprecatedName(String parserName, Supplier location, String usedName, String modernName) { String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] "; - deprecationLogger.deprecated("{}Deprecated field [{}] used, expected [{}] instead", + deprecationLogger.deprecatedAndMaybeLog("deprecated_field", "{}Deprecated field [{}] used, expected [{}] instead", prefix, usedName, modernName); } @Override public void usedDeprecatedField(String parserName, Supplier location, String usedName, String replacedWith) { String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] "; - deprecationLogger.deprecated("{}Deprecated field [{}] used, replaced by [{}]", + deprecationLogger.deprecatedAndMaybeLog("deprecated_field", "{}Deprecated field [{}] used, replaced by [{}]", prefix, usedName, replacedWith); } @Override public void usedDeprecatedField(String parserName, Supplier location, String usedName) { String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] "; - deprecationLogger.deprecated("{}Deprecated field [{}] used, this field is unused and will be removed entirely", - prefix, usedName); + deprecationLogger.deprecatedAndMaybeLog("deprecated_field", + "{}Deprecated field [{}] used, this field is unused and will be removed entirely", prefix, usedName); } } diff --git a/server/src/main/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactory.java b/server/src/main/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactory.java index 37a163eac978f..6ff289f7f79ed 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactory.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactory.java @@ -51,7 +51,8 @@ public ShingleTokenFilterFactory(IndexSettings indexSettings, Environment enviro + " must be less than or equal to: [" + maxAllowedShingleDiff + "] but was [" + shingleDiff + "]. This limit" + " can be set by changing the [" + IndexSettings.MAX_SHINGLE_DIFF_SETTING.getKey() + "] index level setting."); } else { - deprecationLogger.deprecated("Deprecated big difference between maxShingleSize and minShingleSize" + + deprecationLogger.deprecatedAndMaybeLog("excessive_shingle_diff", + "Deprecated big difference between maxShingleSize and minShingleSize" + " in Shingle TokenFilter, expected difference must be less than or equal to: [" + maxAllowedShingleDiff + "]"); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java index fed93898dd006..a9a9e8fbeeb8f 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java @@ -419,7 +419,8 @@ public CompletionFieldMapper build(BuilderContext context) { private void checkCompletionContextsLimit(BuilderContext context) { if (this.contextMappings != null && this.contextMappings.size() > COMPLETION_CONTEXTS_LIMIT) { - deprecationLogger.deprecated("You have defined more than [" + COMPLETION_CONTEXTS_LIMIT + "] completion contexts" + + deprecationLogger.deprecatedAndMaybeLog("excessive_completion_contexts", + "You have defined more than [" + COMPLETION_CONTEXTS_LIMIT + "] completion contexts" + " in the mapping for index [" + context.indexSettings().get(IndexMetadata.SETTING_INDEX_PROVIDED_NAME) + "]. " + "The maximum allowed number of completion contexts in a mapping will be limited to " + "[" + COMPLETION_CONTEXTS_LIMIT + "] starting in version [8.0]."); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java index 3c1adf259ff58..9a1b7faf69c5b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java @@ -185,7 +185,8 @@ public Query termQuery(Object value, QueryShardContext context) { if (isEnabled() == false) { throw new IllegalStateException("Cannot run [exists] queries if the [_field_names] field is disabled"); } - deprecationLogger.deprecated( + deprecationLogger.deprecatedAndMaybeLog( + "terms_query_on_field_names", "terms query on the _field_names field is deprecated and will be removed, use exists query instead"); return super.termQuery(value, context); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java index 907a7b2e901b3..8764033f2b8f8 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapper.java @@ -170,8 +170,8 @@ private static void checkPrefixTreeSupport(String fieldName) { throw new ElasticsearchParseException("Field parameter [{}] is not supported for [{}] field type", fieldName, CONTENT_TYPE); } - DEPRECATION_LOGGER.deprecated("Field parameter [{}] is deprecated and will be removed in a future version.", - fieldName); + DEPRECATION_LOGGER.deprecatedAndMaybeLog("geo_mapper_field_parameter", + "Field parameter [{}] is deprecated and will be removed in a future version.", fieldName); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java index fd4f21b194b35..9e50a9dfb39c3 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java @@ -197,7 +197,8 @@ protected static boolean parseObjectOrDocumentTypeProperties(String fieldName, O } return true; } else if (fieldName.equals("include_in_all")) { - deprecationLogger.deprecated("[include_in_all] is deprecated, the _all field have been removed in this version"); + deprecationLogger.deprecatedAndMaybeLog("include_in_all", + "[include_in_all] is deprecated, the _all field have been removed in this version"); return true; } return false; diff --git a/server/src/main/java/org/elasticsearch/index/query/functionscore/RandomScoreFunctionBuilder.java b/server/src/main/java/org/elasticsearch/index/query/functionscore/RandomScoreFunctionBuilder.java index 3c1ab7dae42ae..f49984a15f54f 100644 --- a/server/src/main/java/org/elasticsearch/index/query/functionscore/RandomScoreFunctionBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/functionscore/RandomScoreFunctionBuilder.java @@ -168,7 +168,7 @@ protected ScoreFunction doToFunction(QueryShardContext context) { if (field != null) { fieldType = context.getMapperService().fieldType(field); } else { - deprecationLogger.deprecated( + deprecationLogger.deprecatedAndMaybeLog("seed_requires_field", "As of version 7.0 Elasticsearch will require that a [field] parameter is provided when a [seed] is set"); fieldType = context.getMapperService().fieldType(IdFieldMapper.NAME); } diff --git a/server/src/main/java/org/elasticsearch/index/similarity/SimilarityProviders.java b/server/src/main/java/org/elasticsearch/index/similarity/SimilarityProviders.java index 04970a38bd99d..3140841f1643b 100644 --- a/server/src/main/java/org/elasticsearch/index/similarity/SimilarityProviders.java +++ b/server/src/main/java/org/elasticsearch/index/similarity/SimilarityProviders.java @@ -143,7 +143,7 @@ private static BasicModel parseBasicModel(Version indexCreatedVersion, Settings throw new IllegalArgumentException("Basic model [" + basicModel + "] isn't supported anymore, " + "please use another model."); } else { - deprecationLogger.deprecated("Basic model [" + basicModel + + deprecationLogger.deprecatedAndMaybeLog(basicModel + "_similarity_model_replaced", "Basic model [" + basicModel + "] isn't supported anymore and has arbitrarily been replaced with [" + replacement + "]."); model = BASIC_MODELS.get(replacement); assert model != null; @@ -174,7 +174,7 @@ private static AfterEffect parseAfterEffect(Version indexCreatedVersion, Setting throw new IllegalArgumentException("After effect [" + afterEffect + "] isn't supported anymore, please use another effect."); } else { - deprecationLogger.deprecated("After effect [" + afterEffect + + deprecationLogger.deprecatedAndMaybeLog(afterEffect + "_after_effect_replaced", "After effect [" + afterEffect + "] isn't supported anymore and has arbitrarily been replaced with [" + replacement + "]."); effect = AFTER_EFFECTS.get(replacement); assert effect != null; @@ -264,7 +264,8 @@ static void assertSettingsIsSubsetOf(String type, Version version, Settings sett if (version.onOrAfter(Version.V_7_0_0)) { throw new IllegalArgumentException("Unknown settings for similarity of type [" + type + "]: " + unknownSettings); } else { - deprecationLogger.deprecated("Unknown settings for similarity of type [" + type + "]: " + unknownSettings); + deprecationLogger.deprecatedAndMaybeLog("unknown_similarity_setting", + "Unknown settings for similarity of type [" + type + "]: " + unknownSettings); } } } diff --git a/server/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java b/server/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java index db14fe15cc113..3d16e56f91611 100644 --- a/server/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java +++ b/server/src/main/java/org/elasticsearch/index/similarity/SimilarityService.java @@ -154,7 +154,8 @@ public SimilarityService(IndexSettings indexSettings, ScriptService scriptServic defaultSimilarity = (providers.get("default") != null) ? providers.get("default").get() : providers.get(SimilarityService.DEFAULT_SIMILARITY).get(); if (providers.get("base") != null) { - deprecationLogger.deprecated("The [base] similarity is ignored since query normalization and coords have been removed"); + deprecationLogger.deprecatedAndMaybeLog("base_similarity_ignored", + "The [base] similarity is ignored since query normalization and coords have been removed"); } } diff --git a/server/src/main/java/org/elasticsearch/rest/DeprecationRestHandler.java b/server/src/main/java/org/elasticsearch/rest/DeprecationRestHandler.java index 2408f83d2b54e..c88fbef28a1a3 100644 --- a/server/src/main/java/org/elasticsearch/rest/DeprecationRestHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/DeprecationRestHandler.java @@ -57,7 +57,7 @@ public DeprecationRestHandler(RestHandler handler, String deprecationMessage, De */ @Override public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { - deprecationLogger.deprecated(deprecationMessage); + deprecationLogger.deprecatedAndMaybeLog("deprecated_route", deprecationMessage); handler.handleRequest(request, channel, client); } diff --git a/server/src/main/java/org/elasticsearch/script/ScriptMetadata.java b/server/src/main/java/org/elasticsearch/script/ScriptMetadata.java index 7558ca72d0cd5..3a61494d42709 100644 --- a/server/src/main/java/org/elasticsearch/script/ScriptMetadata.java +++ b/server/src/main/java/org/elasticsearch/script/ScriptMetadata.java @@ -219,9 +219,9 @@ public static ScriptMetadata fromXContent(XContentParser parser) throws IOExcept if (source.getSource().isEmpty()) { if (source.getLang().equals(Script.DEFAULT_TEMPLATE_LANG)) { - deprecationLogger.deprecated("empty templates should no longer be used"); + deprecationLogger.deprecatedAndMaybeLog("empty_templates","empty templates should no longer be used"); } else { - deprecationLogger.deprecated("empty scripts should no longer be used"); + deprecationLogger.deprecatedAndMaybeLog("empty_scripts", "empty scripts should no longer be used"); } } } diff --git a/server/src/main/java/org/elasticsearch/script/StoredScriptSource.java b/server/src/main/java/org/elasticsearch/script/StoredScriptSource.java index e730446f10982..e6de5ac2d3136 100644 --- a/server/src/main/java/org/elasticsearch/script/StoredScriptSource.java +++ b/server/src/main/java/org/elasticsearch/script/StoredScriptSource.java @@ -145,9 +145,9 @@ private StoredScriptSource build(boolean ignoreEmpty) { if (source == null) { if (ignoreEmpty || Script.DEFAULT_TEMPLATE_LANG.equals(lang)) { if (Script.DEFAULT_TEMPLATE_LANG.equals(lang)) { - deprecationLogger.deprecated("empty templates should no longer be used"); + deprecationLogger.deprecatedAndMaybeLog("empty_templates", "empty templates should no longer be used"); } else { - deprecationLogger.deprecated("empty scripts should no longer be used"); + deprecationLogger.deprecatedAndMaybeLog("empty_scripts", "empty scripts should no longer be used"); } } else { throw new IllegalArgumentException("must specify source for stored script"); @@ -155,9 +155,9 @@ private StoredScriptSource build(boolean ignoreEmpty) { } else if (source.isEmpty()) { if (ignoreEmpty || Script.DEFAULT_TEMPLATE_LANG.equals(lang)) { if (Script.DEFAULT_TEMPLATE_LANG.equals(lang)) { - deprecationLogger.deprecated("empty templates should no longer be used"); + deprecationLogger.deprecatedAndMaybeLog("empty_templates", "empty templates should no longer be used"); } else { - deprecationLogger.deprecated("empty scripts should no longer be used"); + deprecationLogger.deprecatedAndMaybeLog("empty_scripts", "empty scripts should no longer be used"); } } else { throw new IllegalArgumentException("source cannot be empty"); @@ -257,7 +257,7 @@ public static StoredScriptSource parse(BytesReference content, XContentType xCon token = parser.nextToken(); if (token == Token.END_OBJECT) { - deprecationLogger.deprecated("empty templates should no longer be used"); + deprecationLogger.deprecatedAndMaybeLog("empty_templates", "empty templates should no longer be used"); return new StoredScriptSource(Script.DEFAULT_TEMPLATE_LANG, "", Collections.emptyMap()); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java index d0171e56bc142..7e42f170f30f4 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java @@ -311,7 +311,8 @@ public static ExecutionMode fromString(String value, final DeprecationLogger dep if ("global_ordinals".equals(value)) { return GLOBAL_ORDINALS; } else if ("global_ordinals_hash".equals(value)) { - deprecationLogger.deprecated("global_ordinals_hash is deprecated. Please use [global_ordinals] instead."); + deprecationLogger.deprecatedAndMaybeLog("global_ordinals_hash", + "global_ordinals_hash is deprecated. Please use [global_ordinals] instead."); return GLOBAL_ORDINALS; } else if ("map".equals(value)) { return MAP; diff --git a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java index f0b26a468db93..3d734e2471986 100644 --- a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java +++ b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java @@ -87,7 +87,8 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept .filter(USE_DEFAULT_FORMAT::equals) .findAny() .isPresent()) { - DEPRECATION_LOGGER.deprecated("[" + USE_DEFAULT_FORMAT + "] is a special format that was only used to " + + DEPRECATION_LOGGER.deprecatedAndMaybeLog("explicit_default_format", + "[" + USE_DEFAULT_FORMAT + "] is a special format that was only used to " + "ease the transition to 7.x. It has become the default and shouldn't be set explicitly anymore."); } diff --git a/server/src/main/java/org/elasticsearch/transport/TransportInfo.java b/server/src/main/java/org/elasticsearch/transport/TransportInfo.java index 607321fc95492..66eeb5e8cda20 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportInfo.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportInfo.java @@ -103,7 +103,7 @@ private String formatPublishAddressString(String propertyName, TransportAddress if (cnameInPublishAddress) { publishAddressString = hostString + '/' + publishAddress.toString(); } else { - deprecationLogger.deprecated( + deprecationLogger.deprecatedAndMaybeLog("cname_in_publish_address" propertyName + " was printed as [ip:port] instead of [hostname/ip:port]. " + "This format is deprecated and will change to [hostname/ip:port] in a future version. " + "Use -Des.transport.cname_in_publish_address=true to enforce non-deprecated formatting." diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java index 57d2dc689aaf2..857836a7f009e 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java @@ -118,13 +118,15 @@ class DeprecatedTokenFilterFactory extends AbstractTokenFilterFactory implements @Override public TokenStream create(TokenStream tokenStream) { - deprecationLogger.deprecated("Using deprecated token filter [deprecated]"); + deprecationLogger.deprecatedAndMaybeLog("deprecated_token_filter_create", + "Using deprecated token filter [deprecated]"); return tokenStream; } @Override public TokenStream normalize(TokenStream tokenStream) { - deprecationLogger.deprecated("Using deprecated token filter [deprecated]"); + deprecationLogger.deprecatedAndMaybeLog("deprecated_token_filter_normalize", + "Using deprecated token filter [deprecated]"); return tokenStream; } } diff --git a/server/src/test/java/org/elasticsearch/common/logging/DeprecationLoggerTests.java b/server/src/test/java/org/elasticsearch/common/logging/DeprecationLoggerTests.java index 70bbe93fdce4a..6d1e350bdf72b 100644 --- a/server/src/test/java/org/elasticsearch/common/logging/DeprecationLoggerTests.java +++ b/server/src/test/java/org/elasticsearch/common/logging/DeprecationLoggerTests.java @@ -166,7 +166,7 @@ public void testCanRemoveThreadContext() throws IOException { ThreadContext threadContext = new ThreadContext(Settings.EMPTY); DeprecationLogger.setThreadContext(threadContext); - logger.deprecated(expected); + logger.deprecatedAndMaybeLog("testCanRemoveThreadContext_key1", expected); { final Map> responseHeaders = threadContext.getResponseHeaders(); @@ -178,7 +178,7 @@ public void testCanRemoveThreadContext() throws IOException { } DeprecationLogger.removeThreadContext(threadContext); - logger.deprecated(unexpected); + logger.deprecatedAndMaybeLog("testCanRemoveThreadContext_key2", unexpected); { final Map> responseHeaders = threadContext.getResponseHeaders(); @@ -340,7 +340,7 @@ public LoggerContext getContext(String fqcn, ClassLoader loader, Object external new ProtectionDomain[]{new ProtectionDomain(null, new Permissions())} ); AccessController.doPrivileged((PrivilegedAction) () -> { - deprecationLogger.deprecated("foo", "bar"); + deprecationLogger.deprecatedAndMaybeLog("testLogPermissions_key", "foo", "bar"); return null; }, noPermissionsAcc); assertThat("supplier called", supplierCalled.get(), is(true)); diff --git a/server/src/test/java/org/elasticsearch/index/analysis/AnalysisRegistryTests.java b/server/src/test/java/org/elasticsearch/index/analysis/AnalysisRegistryTests.java index 34b219c28a6e5..bcdb8b6682e38 100644 --- a/server/src/test/java/org/elasticsearch/index/analysis/AnalysisRegistryTests.java +++ b/server/src/test/java/org/elasticsearch/index/analysis/AnalysisRegistryTests.java @@ -81,8 +81,8 @@ public static class MockAnalysisPlugin extends Plugin implements AnalysisPlugin public List getPreConfiguredTokenFilters() { return singletonList(PreConfiguredTokenFilter.singleton("reverse", true, ReverseStringFilter::new)); } - } - + } + private static IndexSettings indexSettingsOfCurrentVersion(Settings.Builder settings) { return IndexSettingsModule.newIndexSettings("index", settings .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) @@ -154,29 +154,29 @@ public Tokenizer create() { emptyMap(), emptyMap(), emptyMap())); assertEquals("analyzer [default] contains filters [my_filter] that are not allowed to run in all mode.", ex.getMessage()); } - - + + public void testNameClashNormalizer() throws IOException { - + // Test out-of-the-box normalizer works OK. IndexAnalyzers indexAnalyzers = nonEmptyRegistry.build(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY)); assertNotNull(indexAnalyzers.getNormalizer("lowercase")); assertThat(indexAnalyzers.getNormalizer("lowercase").normalize("field", "AbC").utf8ToString(), equalTo("abc")); - - // Test that a name clash with a custom normalizer will favour the index's normalizer rather than the out-of-the-box - // one of the same name. (However this "feature" will be removed with https://github.com/elastic/elasticsearch/issues/22263 ) + + // Test that a name clash with a custom normalizer will favour the index's normalizer rather than the out-of-the-box + // one of the same name. (However this "feature" will be removed with https://github.com/elastic/elasticsearch/issues/22263 ) Settings settings = Settings.builder() // Deliberately bad choice of normalizer name for the job it does. .put("index.analysis.normalizer.lowercase.type", "custom") .putList("index.analysis.normalizer.lowercase.filter", "reverse") .build(); - + indexAnalyzers = nonEmptyRegistry.build(IndexSettingsModule.newIndexSettings("index", settings)); assertNotNull(indexAnalyzers.getNormalizer("lowercase")); assertThat(indexAnalyzers.getNormalizer("lowercase").normalize("field","AbC").utf8ToString(), equalTo("CbA")); - } + } + - public void testOverrideDefaultIndexAnalyzerIsUnsupported() { Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0_alpha1, Version.CURRENT); Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); @@ -326,7 +326,7 @@ class MockFactory extends AbstractTokenFilterFactory { @Override public TokenStream create(TokenStream tokenStream) { if (indexSettings.getIndexVersionCreated().equals(Version.CURRENT)) { - deprecationLogger.deprecated("Using deprecated token filter [deprecated]"); + deprecationLogger.deprecatedAndMaybeLog("deprecated_token_filter", "Using deprecated token filter [deprecated]"); } return tokenStream; } @@ -354,7 +354,7 @@ class UnusedMockFactory extends AbstractTokenFilterFactory { @Override public TokenStream create(TokenStream tokenStream) { - deprecationLogger.deprecated("Using deprecated token filter [unused]"); + deprecationLogger.deprecatedAndMaybeLog("unused_token_filter", "Using deprecated token filter [unused]"); return tokenStream; } } @@ -367,7 +367,8 @@ class NormalizerFactory extends AbstractTokenFilterFactory implements Normalizin @Override public TokenStream create(TokenStream tokenStream) { - deprecationLogger.deprecated("Using deprecated token filter [deprecated_normalizer]"); + deprecationLogger.deprecatedAndMaybeLog("deprecated_normalizer", + "Using deprecated token filter [deprecated_normalizer]"); return tokenStream; } diff --git a/server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java b/server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java index 0dc108ff587cd..cbce81f7d2f40 100644 --- a/server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java @@ -77,7 +77,7 @@ public void testHandleRequestLogsWarningThenForwards() throws Exception { InOrder inOrder = inOrder(handler, request, channel, deprecationLogger); // log, then forward - inOrder.verify(deprecationLogger).deprecated(deprecationMessage); + inOrder.verify(deprecationLogger).deprecatedAndMaybeLog("deprecated_route", deprecationMessage); inOrder.verify(handler).handleRequest(request, channel, client); inOrder.verifyNoMoreInteractions(); } diff --git a/x-pack/plugin/async-search/qa/rest/src/main/java/org/elasticsearch/query/DeprecatedQueryBuilder.java b/x-pack/plugin/async-search/qa/rest/src/main/java/org/elasticsearch/query/DeprecatedQueryBuilder.java index 7b4d1ed0ebfa9..db5ec14dcbd91 100644 --- a/x-pack/plugin/async-search/qa/rest/src/main/java/org/elasticsearch/query/DeprecatedQueryBuilder.java +++ b/x-pack/plugin/async-search/qa/rest/src/main/java/org/elasticsearch/query/DeprecatedQueryBuilder.java @@ -54,7 +54,7 @@ public static DeprecatedQueryBuilder fromXContent(XContentParser parser) { @Override protected Query doToQuery(QueryShardContext context) { - deprecationLogger.deprecated("[deprecated] query"); + deprecationLogger.deprecatedAndMaybeLog("to_query", "[deprecated] query"); return new MatchAllDocsQuery(); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 16522caf6120b..6f83ffc9a51d7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -332,7 +332,8 @@ public static Path resolveConfigFile(Environment env, String name) { if (Files.exists(config) == false) { Path legacyConfig = env.configFile().resolve("x-pack").resolve(name); if (Files.exists(legacyConfig)) { - deprecationLogger.deprecated("Config file [" + name + "] is in a deprecated location. Move from " + + deprecationLogger.deprecatedAndMaybeLog("config_file_path", + "Config file [" + name + "] is in a deprecated location. Move from " + legacyConfig.toString() + " to " + config.toString()); return legacyConfig; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/GetTransformAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/GetTransformAction.java index b3f4626f1de2a..b16b0adec9d15 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/GetTransformAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/GetTransformAction.java @@ -117,7 +117,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(TransformField.COUNT.getPreferredName(), invalidTransforms.size()); builder.field(TransformField.TRANSFORMS.getPreferredName(), invalidTransforms); builder.endObject(); - deprecationLogger.deprecated(INVALID_TRANSFORMS_DEPRECATION_WARNING, invalidTransforms.size()); + deprecationLogger.deprecatedAndMaybeLog( + "invalid_transforms", + INVALID_TRANSFORMS_DEPRECATION_WARNING, + invalidTransforms.size() + ); } builder.endObject(); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java index b7e235b780625..b810815e21e6b 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java @@ -246,7 +246,8 @@ public void putJob(PutJobAction.Request request, AnalysisRegistry analysisRegist Job job = request.getJobBuilder().build(new Date()); if (job.getDataDescription() != null && job.getDataDescription().getFormat() == DataDescription.DataFormat.DELIMITED) { - deprecationLogger.deprecated("Creating jobs with delimited data format is deprecated. Please use xcontent instead."); + deprecationLogger.deprecatedAndMaybeLog("ml_create_job_delimited_data", + "Creating jobs with delimited data format is deprecated. Please use xcontent instead."); } // Check for the job in the cluster state first diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java index 57a048487a8c8..c9453e178e63f 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java @@ -132,7 +132,8 @@ static void checkForDeprecatedTZ(PutRollupJobAction.Request request) { String timeZone = request.getConfig().getGroupConfig().getDateHistogram().getTimeZone(); String modernTZ = DateUtils.DEPRECATED_LONG_TIMEZONES.get(timeZone); if (modernTZ != null) { - deprecationLogger.deprecated("Creating Rollup job [" + request.getConfig().getId() + "] with timezone [" + deprecationLogger.deprecatedAndMaybeLog("deprecated_timezone", + "Creating Rollup job [" + request.getConfig().getId() + "] with timezone [" + timeZone + "], but [" + timeZone + "] has been deprecated by the IANA. Use [" + modernTZ +"] instead."); } } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java index 980235f3e3005..26de0811c14ae 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java @@ -630,21 +630,23 @@ private ApiKeyLoggingDeprecationHandler(DeprecationLogger logger, String apiKeyI @Override public void usedDeprecatedName(String parserName, Supplier location, String usedName, String modernName) { String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] "; - deprecationLogger.deprecated("{}Deprecated field [{}] used in api key [{}], expected [{}] instead", + deprecationLogger.deprecatedAndMaybeLog("api_key_field", + "{}Deprecated field [{}] used in api key [{}], expected [{}] instead", prefix, usedName, apiKeyId, modernName); } @Override public void usedDeprecatedField(String parserName, Supplier location, String usedName, String replacedWith) { String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] "; - deprecationLogger.deprecated("{}Deprecated field [{}] used in api key [{}], replaced by [{}]", + deprecationLogger.deprecatedAndMaybeLog("api_key_field", + "{}Deprecated field [{}] used in api key [{}], replaced by [{}]", prefix, usedName, apiKeyId, replacedWith); } @Override public void usedDeprecatedField(String parserName, Supplier location, String usedName) { String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] "; - deprecationLogger.deprecated( + deprecationLogger.deprecatedAndMaybeLog("api_key_field", "{}Deprecated field [{}] used in api key [{}], which is unused and will be removed entirely", prefix, usedName); } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectorySessionFactory.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectorySessionFactory.java index d1f11ca65c402..7aa1491e8ce93 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectorySessionFactory.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectorySessionFactory.java @@ -523,9 +523,10 @@ static class UpnADAuthenticator extends ADAuthenticator { super(config, timeout, ignoreReferralErrors, logger, groupsResolver, metadataResolver, domainDN, ActiveDirectorySessionFactorySettings.AD_UPN_USER_SEARCH_FILTER_SETTING, UPN_USER_FILTER, threadPool); if (userSearchFilter.contains("{0}")) { - new DeprecationLogger(logger).deprecated("The use of the account name variable {0} in the setting [" - + RealmSettings.getFullSettingKey(config, ActiveDirectorySessionFactorySettings.AD_UPN_USER_SEARCH_FILTER_SETTING) + - "] has been deprecated and will be removed in a future version!"); + new DeprecationLogger(logger).deprecatedAndMaybeLog("ldap_settings", + "The use of the account name variable {0} in the setting [" + + RealmSettings.getFullSettingKey(config, ActiveDirectorySessionFactorySettings.AD_UPN_USER_SEARCH_FILTER_SETTING) + + "] has been deprecated and will be removed in a future version!"); } } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/support/SessionFactory.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/support/SessionFactory.java index 2df8cf18b60ed..31affff20dd24 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/support/SessionFactory.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/support/SessionFactory.java @@ -157,10 +157,14 @@ protected static LDAPConnectionOptions connectionOptions(RealmConfig config, options.setSSLSocketVerifier(new HostNameSSLSocketVerifier(true)); } } else if (hostnameVerificationExists) { - new DeprecationLogger(logger).deprecated("the setting [{}] has been deprecated and " + - "will be removed in a future version. use [{}] instead", - RealmSettings.getFullSettingKey(config, SessionFactorySettings.HOSTNAME_VERIFICATION_SETTING), - RealmSettings.getFullSettingKey(config, SSLConfigurationSettings.VERIFICATION_MODE_SETTING_REALM)); + final String fullSettingKey = RealmSettings.getFullSettingKey(config, SessionFactorySettings.HOSTNAME_VERIFICATION_SETTING); + final String deprecationKey = "deprecated_setting_" + fullSettingKey.replace('.', '_'); + new DeprecationLogger(logger).deprecatedAndMaybeLog( + deprecationKey, + "the setting [{}] has been deprecated and " + "will be removed in a future version. use [{}] instead", + fullSettingKey, + RealmSettings.getFullSettingKey(config, SSLConfigurationSettings.VERIFICATION_MODE_SETTING_REALM) + ); if (config.getSetting(SessionFactorySettings.HOSTNAME_VERIFICATION_SETTING)) { options.setSSLSocketVerifier(new HostNameSSLSocketVerifier(true)); } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumer.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumer.java index 86e4fb22b2787..04925984017ce 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumer.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumer.java @@ -206,7 +206,7 @@ private void logDeprecatedPermission(RoleDescriptor roleDescriptor) { if (false == inferiorIndexNames.isEmpty()) { final String logMessage = String.format(Locale.ROOT, ROLE_PERMISSION_DEPRECATION_STANZA, roleDescriptor.getName(), aliasName, String.join(", ", inferiorIndexNames)); - deprecationLogger.deprecated(logMessage); + deprecationLogger.deprecatedAndMaybeLog("index_permissions_on_alias", logMessage); } } } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumerTests.java index 148fd7121a7d3..8fa4db6bcc09c 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/DeprecationRoleDescriptorConsumerTests.java @@ -296,7 +296,8 @@ private RoleDescriptor.IndicesPrivileges indexPrivileges(String priv, String... } private void verifyLogger(DeprecationLogger deprecationLogger, String roleName, String aliasName, String indexNames) { - verify(deprecationLogger).deprecated("Role [" + roleName + "] contains index privileges covering the [" + aliasName + verify(deprecationLogger).deprecatedAndMaybeLog("index_permissions_on_alias", + "Role [" + roleName + "] contains index privileges covering the [" + aliasName + "] alias but which do not cover some of the indices that it points to [" + indexNames + "]. Granting privileges over an" + " alias and hence granting privileges over all the indices that the alias points to is deprecated and will be removed" + " in a future version of Elasticsearch. Instead define permissions exclusively on index names or index name patterns."); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java index a5574a5dba3c6..b5b8ec68c804d 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java @@ -60,7 +60,8 @@ protected RestChannelConsumer doPrepareRequest(final RestRequest restRequest, Wa } if (metrics.contains("pending_watches")) { - deprecationLogger.deprecated("The pending_watches parameter is deprecated, use queued_watches instead"); + deprecationLogger.deprecatedAndMaybeLog("pending_watches", + "The pending_watches parameter is deprecated, use queued_watches instead"); }