From 098727d962f2341e275034566f8cd1e9d6d53f51 Mon Sep 17 00:00:00 2001 From: Alexander Kazakov Date: Fri, 27 Sep 2019 19:09:05 +0300 Subject: [PATCH 1/2] Slow log must use separate underlying logger for each index --- .../main/java/org/elasticsearch/index/IndexingSlowLog.java | 2 +- .../src/main/java/org/elasticsearch/index/SearchSlowLog.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java b/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java index dc69718927bde..2fe378e82e532 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java +++ b/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java @@ -94,7 +94,7 @@ public final class IndexingSlowLog implements IndexingOperationListener { }, Property.Dynamic, Property.IndexScope); IndexingSlowLog(IndexSettings indexSettings) { - this.indexLogger = LogManager.getLogger(INDEX_INDEXING_SLOWLOG_PREFIX + ".index"); + this.indexLogger = LogManager.getLogger(INDEX_INDEXING_SLOWLOG_PREFIX + ".index." + indexSettings.getUUID()); this.index = indexSettings.getIndex(); indexSettings.getScopedSettings().addSettingsUpdateConsumer(INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING, this::setReformat); diff --git a/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java b/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java index 1e16fb7749306..77e150a93264b 100644 --- a/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java +++ b/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java @@ -87,8 +87,8 @@ public final class SearchSlowLog implements SearchOperationListener { public SearchSlowLog(IndexSettings indexSettings) { - this.queryLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query"); - this.fetchLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch"); + this.queryLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query." + indexSettings.getUUID()); + this.fetchLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch." + indexSettings.getUUID()); indexSettings.getScopedSettings().addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING, this::setQueryWarnThreshold); From 93a9e26026daad1735a6314bcb3070e19b712054 Mon Sep 17 00:00:00 2001 From: Alexander Kazakov Date: Thu, 10 Oct 2019 18:41:38 +0300 Subject: [PATCH 2/2] Add test --- .../elasticsearch/index/IndexingSlowLog.java | 5 +---- .../elasticsearch/index/SearchSlowLog.java | 6 ++---- .../index/IndexingSlowLogTests.java | 20 +++++++++++++++++++ .../index/SearchSlowLogTests.java | 20 +++++++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java b/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java index 2fe378e82e532..2059ced02177d 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java +++ b/server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java @@ -56,8 +56,6 @@ public final class IndexingSlowLog implements IndexingOperationListener { */ private int maxSourceCharsToLog; - private SlowLogLevel level; - private final Logger indexLogger; private static final String INDEX_INDEXING_SLOWLOG_PREFIX = "index.indexing.slowlog"; @@ -123,7 +121,6 @@ private void setMaxSourceCharsToLog(int maxSourceCharsToLog) { } private void setLevel(SlowLogLevel level) { - this.level = level; Loggers.setLevel(this.indexLogger, level.name()); } @@ -266,7 +263,7 @@ int getMaxSourceCharsToLog() { } SlowLogLevel getLevel() { - return level; + return SlowLogLevel.parse(indexLogger.getLevel().name()); } } diff --git a/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java b/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java index 77e150a93264b..24f55a7654813 100644 --- a/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java +++ b/server/src/main/java/org/elasticsearch/index/SearchSlowLog.java @@ -49,8 +49,6 @@ public final class SearchSlowLog implements SearchOperationListener { private long fetchDebugThreshold; private long fetchTraceThreshold; - private SlowLogLevel level; - private final Logger queryLogger; private final Logger fetchLogger; @@ -121,7 +119,6 @@ public SearchSlowLog(IndexSettings indexSettings) { } private void setLevel(SlowLogLevel level) { - this.level = level; Loggers.setLevel(queryLogger, level.name()); Loggers.setLevel(fetchLogger, level.name()); } @@ -291,6 +288,7 @@ long getFetchTraceThreshold() { } SlowLogLevel getLevel() { - return level; + assert queryLogger.getLevel().equals(fetchLogger.getLevel()); + return SlowLogLevel.parse(queryLogger.getLevel().name()); } } diff --git a/server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java b/server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java index 63f54f6d023bf..b61479b995245 100644 --- a/server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java +++ b/server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.NumericDocValuesField; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.logging.ESLogMessage; @@ -200,6 +201,25 @@ public void testLevelSetting() { assertThat(cause, hasToString(containsString("No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL"))); } assertEquals(SlowLogLevel.TRACE, log.getLevel()); + + metaData = newIndexMeta("index", Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) + .put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), SlowLogLevel.DEBUG) + .build()); + settings = new IndexSettings(metaData, Settings.EMPTY); + IndexingSlowLog debugLog = new IndexingSlowLog(settings); + + metaData = newIndexMeta("index", Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) + .put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), SlowLogLevel.INFO) + .build()); + settings = new IndexSettings(metaData, Settings.EMPTY); + IndexingSlowLog infoLog = new IndexingSlowLog(settings); + + assertEquals(SlowLogLevel.DEBUG, debugLog.getLevel()); + assertEquals(SlowLogLevel.INFO, infoLog.getLevel()); } public void testSetLevels() { diff --git a/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java b/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java index 4932cf83ce14c..e5cccd4c15c32 100644 --- a/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java +++ b/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.logging.ESLogMessage; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -169,6 +170,25 @@ public void testLevelSetting() { assertThat(cause, hasToString(containsString("No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL"))); } assertEquals(SlowLogLevel.TRACE, log.getLevel()); + + metaData = newIndexMeta("index", Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) + .put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), SlowLogLevel.DEBUG) + .build()); + settings = new IndexSettings(metaData, Settings.EMPTY); + SearchSlowLog debugLog = new SearchSlowLog(settings); + + metaData = newIndexMeta("index", Settings.builder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) + .put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), SlowLogLevel.INFO) + .build()); + settings = new IndexSettings(metaData, Settings.EMPTY); + SearchSlowLog infoLog = new SearchSlowLog(settings); + + assertEquals(SlowLogLevel.DEBUG, debugLog.getLevel()); + assertEquals(SlowLogLevel.INFO, infoLog.getLevel()); } public void testSetQueryLevels() {