Skip to content

Commit 64be825

Browse files
alexshadow007pgomulka
authored andcommitted
Slow log must use separate underlying logger for each index (elastic#47234)
SlowLog instances should not share the same underlying logger, as it would cause different indexes override each other levels. When creating underlying logger, unique per index identifier should be used. Name + IndexSettings.UUID Closes elastic#42432
1 parent fa50377 commit 64be825

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

server/src/main/java/org/elasticsearch/index/IndexingSlowLog.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public final class IndexingSlowLog implements IndexingOperationListener {
5656
*/
5757
private int maxSourceCharsToLog;
5858

59-
private SlowLogLevel level;
60-
6159
private final Logger indexLogger;
6260

6361
private static final String INDEX_INDEXING_SLOWLOG_PREFIX = "index.indexing.slowlog";
@@ -94,7 +92,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
9492
}, Property.Dynamic, Property.IndexScope);
9593

9694
IndexingSlowLog(IndexSettings indexSettings) {
97-
this.indexLogger = LogManager.getLogger(INDEX_INDEXING_SLOWLOG_PREFIX + ".index");
95+
this.indexLogger = LogManager.getLogger(INDEX_INDEXING_SLOWLOG_PREFIX + ".index." + indexSettings.getUUID());
9896
this.index = indexSettings.getIndex();
9997

10098
indexSettings.getScopedSettings().addSettingsUpdateConsumer(INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING, this::setReformat);
@@ -123,7 +121,6 @@ private void setMaxSourceCharsToLog(int maxSourceCharsToLog) {
123121
}
124122

125123
private void setLevel(SlowLogLevel level) {
126-
this.level = level;
127124
Loggers.setLevel(this.indexLogger, level.name());
128125
}
129126

@@ -261,7 +258,7 @@ int getMaxSourceCharsToLog() {
261258
}
262259

263260
SlowLogLevel getLevel() {
264-
return level;
261+
return SlowLogLevel.parse(indexLogger.getLevel().name());
265262
}
266263

267264
}

server/src/main/java/org/elasticsearch/index/SearchSlowLog.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public final class SearchSlowLog implements SearchOperationListener {
5050
private long fetchDebugThreshold;
5151
private long fetchTraceThreshold;
5252

53-
private SlowLogLevel level;
54-
5553
private final Logger queryLogger;
5654
private final Logger fetchLogger;
5755

@@ -88,8 +86,8 @@ public final class SearchSlowLog implements SearchOperationListener {
8886

8987
public SearchSlowLog(IndexSettings indexSettings) {
9088

91-
this.queryLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query");
92-
this.fetchLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch");
89+
this.queryLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query." + indexSettings.getUUID());
90+
this.fetchLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch." + indexSettings.getUUID());
9391

9492
indexSettings.getScopedSettings().addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING,
9593
this::setQueryWarnThreshold);
@@ -122,7 +120,6 @@ public SearchSlowLog(IndexSettings indexSettings) {
122120
}
123121

124122
private void setLevel(SlowLogLevel level) {
125-
this.level = level;
126123
Loggers.setLevel(queryLogger, level.name());
127124
Loggers.setLevel(fetchLogger, level.name());
128125
}
@@ -297,6 +294,7 @@ long getFetchTraceThreshold() {
297294
}
298295

299296
SlowLogLevel getLevel() {
300-
return level;
297+
assert queryLogger.getLevel().equals(fetchLogger.getLevel());
298+
return SlowLogLevel.parse(queryLogger.getLevel().name());
301299
}
302300
}

server/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.lucene.document.NumericDocValuesField;
2424
import org.elasticsearch.Version;
2525
import org.elasticsearch.cluster.metadata.IndexMetaData;
26+
import org.elasticsearch.common.UUIDs;
2627
import org.elasticsearch.common.bytes.BytesArray;
2728
import org.elasticsearch.common.bytes.BytesReference;
2829
import org.elasticsearch.common.settings.Settings;
@@ -199,6 +200,25 @@ public void testLevelSetting() {
199200
assertThat(cause, hasToString(containsString("No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL")));
200201
}
201202
assertEquals(SlowLogLevel.TRACE, log.getLevel());
203+
204+
metaData = newIndexMeta("index", Settings.builder()
205+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
206+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
207+
.put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), SlowLogLevel.DEBUG)
208+
.build());
209+
settings = new IndexSettings(metaData, Settings.EMPTY);
210+
IndexingSlowLog debugLog = new IndexingSlowLog(settings);
211+
212+
metaData = newIndexMeta("index", Settings.builder()
213+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
214+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
215+
.put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), SlowLogLevel.INFO)
216+
.build());
217+
settings = new IndexSettings(metaData, Settings.EMPTY);
218+
IndexingSlowLog infoLog = new IndexingSlowLog(settings);
219+
220+
assertEquals(SlowLogLevel.DEBUG, debugLog.getLevel());
221+
assertEquals(SlowLogLevel.INFO, infoLog.getLevel());
202222
}
203223

204224
public void testSetLevels() {

server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.elasticsearch.Version;
2323
import org.elasticsearch.action.search.SearchTask;
2424
import org.elasticsearch.cluster.metadata.IndexMetaData;
25+
import org.elasticsearch.common.UUIDs;
26+
import org.elasticsearch.common.logging.ESLogMessage;
2527
import org.elasticsearch.common.settings.Settings;
2628
import org.elasticsearch.common.unit.TimeValue;
2729
import org.elasticsearch.common.util.BigArrays;
@@ -190,6 +192,25 @@ public void testLevelSetting() {
190192
assertThat(cause, hasToString(containsString("No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL")));
191193
}
192194
assertEquals(SlowLogLevel.TRACE, log.getLevel());
195+
196+
metaData = newIndexMeta("index", Settings.builder()
197+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
198+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
199+
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), SlowLogLevel.DEBUG)
200+
.build());
201+
settings = new IndexSettings(metaData, Settings.EMPTY);
202+
SearchSlowLog debugLog = new SearchSlowLog(settings);
203+
204+
metaData = newIndexMeta("index", Settings.builder()
205+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
206+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
207+
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), SlowLogLevel.INFO)
208+
.build());
209+
settings = new IndexSettings(metaData, Settings.EMPTY);
210+
SearchSlowLog infoLog = new SearchSlowLog(settings);
211+
212+
assertEquals(SlowLogLevel.DEBUG, debugLog.getLevel());
213+
assertEquals(SlowLogLevel.INFO, infoLog.getLevel());
193214
}
194215

195216
public void testSetQueryLevels() {

0 commit comments

Comments
 (0)