Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow log must use separate underlying logger for each index #47234

Merged
merged 3 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -94,7 +92,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);
Expand Down Expand Up @@ -123,7 +121,6 @@ private void setMaxSourceCharsToLog(int maxSourceCharsToLog) {
}

private void setLevel(SlowLogLevel level) {
this.level = level;
Loggers.setLevel(this.indexLogger, level.name());
}

Expand Down Expand Up @@ -264,7 +261,7 @@ int getMaxSourceCharsToLog() {
}

SlowLogLevel getLevel() {
return level;
return SlowLogLevel.parse(indexLogger.getLevel().name());
}

}
10 changes: 4 additions & 6 deletions server/src/main/java/org/elasticsearch/index/SearchSlowLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -87,8 +85,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);
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -291,6 +288,7 @@ long getFetchTraceThreshold() {
}

SlowLogLevel getLevel() {
return level;
assert queryLogger.getLevel().equals(fetchLogger.getLevel());
return SlowLogLevel.parse(queryLogger.getLevel().name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -197,6 +198,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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down