Skip to content

Commit

Permalink
Slow log must use separate underlying logger for each index (elastic#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
alexshadow007 authored and pgomulka committed Oct 17, 2019
1 parent 269e9ba commit 582ee12
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,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 @@ -90,7 +88,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 @@ -119,7 +117,6 @@ private void setMaxSourceCharsToLog(int maxSourceCharsToLog) {
}

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

Expand Down Expand Up @@ -233,7 +230,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 @@ -45,8 +45,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 @@ -83,8 +81,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 @@ -117,7 +115,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 @@ -259,6 +256,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.settings.Settings;
Expand Down Expand Up @@ -189,6 +190,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 @@ -13,7 +13,7 @@
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
git status * specific language governing permissions and limitations
* under the License.
*/

Expand All @@ -24,6 +24,8 @@
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.logging.ESLogMessage;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.BigArrays;
Expand Down Expand Up @@ -223,6 +225,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

0 comments on commit 582ee12

Please sign in to comment.