mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-18 19:05:06 +00:00
convert all slow logs
This commit is contained in:
parent
c4a019d93d
commit
c702fbd29b
@ -36,7 +36,6 @@ import org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService;
|
|||||||
import org.elasticsearch.cluster.node.DiscoveryNodeService;
|
import org.elasticsearch.cluster.node.DiscoveryNodeService;
|
||||||
import org.elasticsearch.cluster.routing.OperationRouting;
|
import org.elasticsearch.cluster.routing.OperationRouting;
|
||||||
import org.elasticsearch.cluster.routing.RoutingService;
|
import org.elasticsearch.cluster.routing.RoutingService;
|
||||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
|
||||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
||||||
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
|
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
|
||||||
import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator;
|
import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator;
|
||||||
@ -66,16 +65,9 @@ import org.elasticsearch.common.util.ExtensionPoint;
|
|||||||
import org.elasticsearch.gateway.GatewayAllocator;
|
import org.elasticsearch.gateway.GatewayAllocator;
|
||||||
import org.elasticsearch.gateway.PrimaryShardAllocator;
|
import org.elasticsearch.gateway.PrimaryShardAllocator;
|
||||||
import org.elasticsearch.index.IndexSettings;
|
import org.elasticsearch.index.IndexSettings;
|
||||||
import org.elasticsearch.index.IndexingSlowLog;
|
import org.elasticsearch.index.SearchSlowLog;
|
||||||
import org.elasticsearch.index.search.stats.SearchSlowLog;
|
|
||||||
import org.elasticsearch.index.settings.IndexDynamicSettings;
|
import org.elasticsearch.index.settings.IndexDynamicSettings;
|
||||||
import org.elasticsearch.index.MergePolicyConfig;
|
import org.elasticsearch.index.MergePolicyConfig;
|
||||||
import org.elasticsearch.index.MergeSchedulerConfig;
|
|
||||||
import org.elasticsearch.index.store.IndexStore;
|
|
||||||
import org.elasticsearch.indices.IndicesWarmer;
|
|
||||||
import org.elasticsearch.indices.cache.request.IndicesRequestCache;
|
|
||||||
import org.elasticsearch.indices.ttl.IndicesTTLService;
|
|
||||||
import org.elasticsearch.search.internal.DefaultSearchContext;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -139,16 +131,6 @@ public class ClusterModule extends AbstractModule {
|
|||||||
registerIndexDynamicSetting(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, Validator.EMPTY);
|
registerIndexDynamicSetting(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, Validator.EMPTY);
|
||||||
registerIndexDynamicSetting(IndexMetaData.SETTING_PRIORITY, Validator.NON_NEGATIVE_INTEGER);
|
registerIndexDynamicSetting(IndexMetaData.SETTING_PRIORITY, Validator.NON_NEGATIVE_INTEGER);
|
||||||
registerIndexDynamicSetting(PrimaryShardAllocator.INDEX_RECOVERY_INITIAL_SHARDS, Validator.EMPTY);
|
registerIndexDynamicSetting(PrimaryShardAllocator.INDEX_RECOVERY_INITIAL_SHARDS, Validator.EMPTY);
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN, Validator.TIME);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO, Validator.TIME);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG, Validator.TIME);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE, Validator.TIME);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN, Validator.TIME);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO, Validator.TIME);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG, Validator.TIME);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE, Validator.TIME);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_REFORMAT, Validator.EMPTY);
|
|
||||||
registerIndexDynamicSetting(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL, Validator.EMPTY);
|
|
||||||
registerIndexDynamicSetting(MergePolicyConfig.INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED, Validator.DOUBLE);
|
registerIndexDynamicSetting(MergePolicyConfig.INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED, Validator.DOUBLE);
|
||||||
registerIndexDynamicSetting(MergePolicyConfig.INDEX_MERGE_POLICY_FLOOR_SEGMENT, Validator.BYTES_SIZE);
|
registerIndexDynamicSetting(MergePolicyConfig.INDEX_MERGE_POLICY_FLOOR_SEGMENT, Validator.BYTES_SIZE);
|
||||||
registerIndexDynamicSetting(MergePolicyConfig.INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE, Validator.INTEGER_GTE_2);
|
registerIndexDynamicSetting(MergePolicyConfig.INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE, Validator.INTEGER_GTE_2);
|
||||||
|
@ -62,7 +62,6 @@ import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
|||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.query.ParsedQuery;
|
import org.elasticsearch.index.query.ParsedQuery;
|
||||||
import org.elasticsearch.index.query.QueryShardContext;
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.index.search.stats.SearchSlowLog;
|
|
||||||
import org.elasticsearch.index.shard.IndexEventListener;
|
import org.elasticsearch.index.shard.IndexEventListener;
|
||||||
import org.elasticsearch.index.shard.IndexSearcherWrapper;
|
import org.elasticsearch.index.shard.IndexSearcherWrapper;
|
||||||
import org.elasticsearch.index.shard.IndexShard;
|
import org.elasticsearch.index.shard.IndexShard;
|
||||||
@ -154,7 +153,7 @@ public final class IndexService extends AbstractIndexComponent implements IndexC
|
|||||||
this.fsyncTask = null;
|
this.fsyncTask = null;
|
||||||
}
|
}
|
||||||
this.refreshTask = new AsyncRefreshTask(this);
|
this.refreshTask = new AsyncRefreshTask(this);
|
||||||
searchSlowLog = new SearchSlowLog(indexSettings.getSettings());
|
searchSlowLog = new SearchSlowLog(indexSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int numberOfShards() {
|
public int numberOfShards() {
|
||||||
@ -575,12 +574,6 @@ public final class IndexService extends AbstractIndexComponent implements IndexC
|
|||||||
logger.warn("[{}] failed to notify shard about setting change", e, shard.shardId().id());
|
logger.warn("[{}] failed to notify shard about setting change", e, shard.shardId().id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
searchSlowLog.onRefreshSettings(settings); // this will be refactored soon anyway so duplication is ok here
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("failed to refresh slowlog settings", e);
|
|
||||||
}
|
|
||||||
if (refreshTask.getInterval().equals(indexSettings.getRefreshInterval()) == false) {
|
if (refreshTask.getInterval().equals(indexSettings.getRefreshInterval()) == false) {
|
||||||
rescheduleRefreshTasks();
|
rescheduleRefreshTasks();
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,11 @@
|
|||||||
|
|
||||||
package org.elasticsearch.index;
|
package org.elasticsearch.index;
|
||||||
|
|
||||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
||||||
import org.elasticsearch.common.Booleans;
|
import org.elasticsearch.common.Booleans;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.index.engine.Engine;
|
import org.elasticsearch.index.engine.Engine;
|
||||||
@ -33,18 +31,16 @@ import org.elasticsearch.index.mapper.ParsedDocument;
|
|||||||
import org.elasticsearch.index.shard.IndexingOperationListener;
|
import org.elasticsearch.index.shard.IndexingOperationListener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public final class IndexingSlowLog implements IndexingOperationListener {
|
public final class IndexingSlowLog implements IndexingOperationListener {
|
||||||
private volatile boolean reformat;
|
private boolean reformat;
|
||||||
private volatile long indexWarnThreshold;
|
private long indexWarnThreshold;
|
||||||
private volatile long indexInfoThreshold;
|
private long indexInfoThreshold;
|
||||||
private volatile long indexDebugThreshold;
|
private long indexDebugThreshold;
|
||||||
private volatile long indexTraceThreshold;
|
private long indexTraceThreshold;
|
||||||
/**
|
/**
|
||||||
* How much of the source to log in the slowlog - 0 means log none and
|
* How much of the source to log in the slowlog - 0 means log none and
|
||||||
* anything greater than 0 means log at least that many <em>characters</em>
|
* anything greater than 0 means log at least that many <em>characters</em>
|
||||||
@ -52,7 +48,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
|
|||||||
*/
|
*/
|
||||||
private int maxSourceCharsToLog;
|
private int maxSourceCharsToLog;
|
||||||
|
|
||||||
private volatile Level level;
|
private SlowLogLevel level;
|
||||||
|
|
||||||
private final ESLogger indexLogger;
|
private final ESLogger indexLogger;
|
||||||
private final ESLogger deleteLogger;
|
private final ESLogger deleteLogger;
|
||||||
@ -63,7 +59,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
|
|||||||
public static final Setting<TimeValue> INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG_SETTING = Setting.timeSetting(INDEX_INDEXING_SLOWLOG_PREFIX +".threshold.index.debug", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
public static final Setting<TimeValue> INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG_SETTING = Setting.timeSetting(INDEX_INDEXING_SLOWLOG_PREFIX +".threshold.index.debug", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
public static final Setting<TimeValue> INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE_SETTING = Setting.timeSetting(INDEX_INDEXING_SLOWLOG_PREFIX +".threshold.index.trace", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
public static final Setting<TimeValue> INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE_SETTING = Setting.timeSetting(INDEX_INDEXING_SLOWLOG_PREFIX +".threshold.index.trace", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
public static final Setting<Boolean> INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING = Setting.boolSetting(INDEX_INDEXING_SLOWLOG_PREFIX +".reformat", true, true, Setting.Scope.INDEX);
|
public static final Setting<Boolean> INDEX_INDEXING_SLOWLOG_REFORMAT_SETTING = Setting.boolSetting(INDEX_INDEXING_SLOWLOG_PREFIX +".reformat", true, true, Setting.Scope.INDEX);
|
||||||
public static final Setting<Level> INDEX_INDEXING_SLOWLOG_LEVEL_SETTING = new Setting<>(INDEX_INDEXING_SLOWLOG_PREFIX +".level", Level.TRACE.name(), Level::parse, true, Setting.Scope.INDEX);
|
public static final Setting<SlowLogLevel> INDEX_INDEXING_SLOWLOG_LEVEL_SETTING = new Setting<>(INDEX_INDEXING_SLOWLOG_PREFIX +".level", SlowLogLevel.TRACE.name(), SlowLogLevel::parse, true, Setting.Scope.INDEX);
|
||||||
/**
|
/**
|
||||||
* Reads how much of the source to log. The user can specify any value they
|
* Reads how much of the source to log. The user can specify any value they
|
||||||
* like and numbers are interpreted the maximum number of characters to log
|
* like and numbers are interpreted the maximum number of characters to log
|
||||||
@ -110,7 +106,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
|
|||||||
this.maxSourceCharsToLog = maxSourceCharsToLog;
|
this.maxSourceCharsToLog = maxSourceCharsToLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLevel(Level level) {
|
private void setLevel(SlowLogLevel level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.indexLogger.setLevel(level.name());
|
this.indexLogger.setLevel(level.name());
|
||||||
this.deleteLogger.setLevel(level.name());
|
this.deleteLogger.setLevel(level.name());
|
||||||
@ -123,12 +119,15 @@ public final class IndexingSlowLog implements IndexingOperationListener {
|
|||||||
private void setInfoThreshold(TimeValue infoThreshold) {
|
private void setInfoThreshold(TimeValue infoThreshold) {
|
||||||
this.indexInfoThreshold = infoThreshold.nanos();
|
this.indexInfoThreshold = infoThreshold.nanos();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDebugThreshold(TimeValue debugThreshold) {
|
private void setDebugThreshold(TimeValue debugThreshold) {
|
||||||
this.indexDebugThreshold = debugThreshold.nanos();
|
this.indexDebugThreshold = debugThreshold.nanos();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTraceThreshold(TimeValue traceThreshold) {
|
private void setTraceThreshold(TimeValue traceThreshold) {
|
||||||
this.indexTraceThreshold = traceThreshold.nanos();
|
this.indexTraceThreshold = traceThreshold.nanos();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setReformat(boolean reformat) {
|
private void setReformat(boolean reformat) {
|
||||||
this.reformat = reformat;
|
this.reformat = reformat;
|
||||||
}
|
}
|
||||||
@ -190,14 +189,6 @@ public final class IndexingSlowLog implements IndexingOperationListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Level {
|
|
||||||
WARN, TRACE, INFO, DEBUG;
|
|
||||||
|
|
||||||
public static Level parse(String level) {
|
|
||||||
return valueOf(level.toUpperCase(Locale.ROOT));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isReformat() {
|
boolean isReformat() {
|
||||||
return reformat;
|
return reformat;
|
||||||
}
|
}
|
||||||
@ -222,7 +213,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
|
|||||||
return maxSourceCharsToLog;
|
return maxSourceCharsToLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
Level getLevel() {
|
SlowLogLevel getLevel() {
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
238
core/src/main/java/org/elasticsearch/index/SearchSlowLog.java
Normal file
238
core/src/main/java/org/elasticsearch/index/SearchSlowLog.java
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* 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
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.Strings;
|
||||||
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
|
import org.elasticsearch.common.settings.Setting;
|
||||||
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public final class SearchSlowLog {
|
||||||
|
|
||||||
|
private boolean reformat;
|
||||||
|
|
||||||
|
private long queryWarnThreshold;
|
||||||
|
private long queryInfoThreshold;
|
||||||
|
private long queryDebugThreshold;
|
||||||
|
private long queryTraceThreshold;
|
||||||
|
|
||||||
|
private long fetchWarnThreshold;
|
||||||
|
private long fetchInfoThreshold;
|
||||||
|
private long fetchDebugThreshold;
|
||||||
|
private long fetchTraceThreshold;
|
||||||
|
|
||||||
|
private SlowLogLevel level;
|
||||||
|
|
||||||
|
private final ESLogger queryLogger;
|
||||||
|
private final ESLogger fetchLogger;
|
||||||
|
|
||||||
|
private static final String INDEX_SEARCH_SLOWLOG_PREFIX = "index.search.slowlog";
|
||||||
|
public static final Setting<TimeValue> INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING = Setting.timeSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.warn", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<TimeValue> INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING = Setting.timeSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.info", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<TimeValue> INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING = Setting.timeSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.debug", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<TimeValue> INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING = Setting.timeSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.trace", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<TimeValue> INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING = Setting.timeSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.warn", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<TimeValue> INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING = Setting.timeSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.info", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<TimeValue> INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING = Setting.timeSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.debug", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<TimeValue> INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING = Setting.timeSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.trace", TimeValue.timeValueNanos(-1), TimeValue.timeValueMillis(-1), true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<Boolean> INDEX_SEARCH_SLOWLOG_REFORMAT = Setting.boolSetting(INDEX_SEARCH_SLOWLOG_PREFIX + ".reformat", true, true, Setting.Scope.INDEX);
|
||||||
|
public static final Setting<SlowLogLevel> INDEX_SEARCH_SLOWLOG_LEVEL = new Setting<>(INDEX_SEARCH_SLOWLOG_PREFIX + ".level", SlowLogLevel.TRACE.name(), SlowLogLevel::parse, true, Setting.Scope.INDEX);
|
||||||
|
|
||||||
|
public SearchSlowLog(IndexSettings indexSettings) {
|
||||||
|
|
||||||
|
this.queryLogger = Loggers.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query");
|
||||||
|
this.fetchLogger = Loggers.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch");
|
||||||
|
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_REFORMAT, this::setReformat);
|
||||||
|
this.reformat = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_REFORMAT);
|
||||||
|
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING, this::setQueryWarnThreshold);
|
||||||
|
this.queryWarnThreshold = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING).nanos();
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING, this::setQueryInfoThreshold);
|
||||||
|
this.queryInfoThreshold = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING).nanos();
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING, this::setQueryDebugThreshold);
|
||||||
|
this.queryDebugThreshold = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING).nanos();
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING, this::setQueryTraceThreshold);
|
||||||
|
this.queryTraceThreshold = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING).nanos();
|
||||||
|
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING, this::setFetchWarnThreshold);
|
||||||
|
this.fetchWarnThreshold = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING).nanos();
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING, this::setFetchInfoThreshold);
|
||||||
|
this.fetchInfoThreshold = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING).nanos();
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING, this::setFetchDebugThreshold);
|
||||||
|
this.fetchDebugThreshold = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING).nanos();
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING, this::setFetchTraceThreshold);
|
||||||
|
this.fetchTraceThreshold = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING).nanos();
|
||||||
|
|
||||||
|
indexSettings.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_LEVEL, this::setLevel);
|
||||||
|
setLevel(indexSettings.getValue(INDEX_SEARCH_SLOWLOG_LEVEL));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setLevel(SlowLogLevel level) {
|
||||||
|
this.level = level;
|
||||||
|
this.queryLogger.setLevel(level.name());
|
||||||
|
this.fetchLogger.setLevel(level.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onQueryPhase(SearchContext context, long tookInNanos) {
|
||||||
|
if (queryWarnThreshold >= 0 && tookInNanos > queryWarnThreshold) {
|
||||||
|
queryLogger.warn("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||||
|
} else if (queryInfoThreshold >= 0 && tookInNanos > queryInfoThreshold) {
|
||||||
|
queryLogger.info("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||||
|
} else if (queryDebugThreshold >= 0 && tookInNanos > queryDebugThreshold) {
|
||||||
|
queryLogger.debug("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||||
|
} else if (queryTraceThreshold >= 0 && tookInNanos > queryTraceThreshold) {
|
||||||
|
queryLogger.trace("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onFetchPhase(SearchContext context, long tookInNanos) {
|
||||||
|
if (fetchWarnThreshold >= 0 && tookInNanos > fetchWarnThreshold) {
|
||||||
|
fetchLogger.warn("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||||
|
} else if (fetchInfoThreshold >= 0 && tookInNanos > fetchInfoThreshold) {
|
||||||
|
fetchLogger.info("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||||
|
} else if (fetchDebugThreshold >= 0 && tookInNanos > fetchDebugThreshold) {
|
||||||
|
fetchLogger.debug("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||||
|
} else if (fetchTraceThreshold >= 0 && tookInNanos > fetchTraceThreshold) {
|
||||||
|
fetchLogger.trace("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SlowLogSearchContextPrinter {
|
||||||
|
private final SearchContext context;
|
||||||
|
private final long tookInNanos;
|
||||||
|
private final boolean reformat;
|
||||||
|
|
||||||
|
public SlowLogSearchContextPrinter(SearchContext context, long tookInNanos, boolean reformat) {
|
||||||
|
this.context = context;
|
||||||
|
this.tookInNanos = tookInNanos;
|
||||||
|
this.reformat = reformat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("took[").append(TimeValue.timeValueNanos(tookInNanos)).append("], took_millis[").append(TimeUnit.NANOSECONDS.toMillis(tookInNanos)).append("], ");
|
||||||
|
if (context.types() == null) {
|
||||||
|
sb.append("types[], ");
|
||||||
|
} else {
|
||||||
|
sb.append("types[");
|
||||||
|
Strings.arrayToDelimitedString(context.types(), ",", sb);
|
||||||
|
sb.append("], ");
|
||||||
|
}
|
||||||
|
if (context.groupStats() == null) {
|
||||||
|
sb.append("stats[], ");
|
||||||
|
} else {
|
||||||
|
sb.append("stats[");
|
||||||
|
Strings.collectionToDelimitedString(context.groupStats(), ",", "", "", sb);
|
||||||
|
sb.append("], ");
|
||||||
|
}
|
||||||
|
sb.append("search_type[").append(context.searchType()).append("], total_shards[").append(context.numberOfShards()).append("], ");
|
||||||
|
if (context.request().source() != null) {
|
||||||
|
sb.append("source[").append(context.request().source()).append("], ");
|
||||||
|
} else {
|
||||||
|
sb.append("source[], ");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setReformat(boolean reformat) {
|
||||||
|
this.reformat = reformat;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setQueryWarnThreshold(TimeValue warnThreshold) {
|
||||||
|
this.queryWarnThreshold = warnThreshold.nanos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setQueryInfoThreshold(TimeValue infoThreshold) {
|
||||||
|
this.queryInfoThreshold = infoThreshold.nanos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setQueryDebugThreshold(TimeValue debugThreshold) {
|
||||||
|
this.queryDebugThreshold = debugThreshold.nanos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setQueryTraceThreshold(TimeValue traceThreshold) {
|
||||||
|
this.queryTraceThreshold = traceThreshold.nanos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFetchWarnThreshold(TimeValue warnThreshold) {
|
||||||
|
this.fetchWarnThreshold = warnThreshold.nanos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFetchInfoThreshold(TimeValue infoThreshold) {
|
||||||
|
this.fetchInfoThreshold = infoThreshold.nanos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFetchDebugThreshold(TimeValue debugThreshold) {
|
||||||
|
this.fetchDebugThreshold = debugThreshold.nanos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFetchTraceThreshold(TimeValue traceThreshold) {
|
||||||
|
this.fetchTraceThreshold = traceThreshold.nanos();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isReformat() {
|
||||||
|
return reformat;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getQueryWarnThreshold() {
|
||||||
|
return queryWarnThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getQueryInfoThreshold() {
|
||||||
|
return queryInfoThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getQueryDebugThreshold() {
|
||||||
|
return queryDebugThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getQueryTraceThreshold() {
|
||||||
|
return queryTraceThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getFetchWarnThreshold() {
|
||||||
|
return fetchWarnThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getFetchInfoThreshold() {
|
||||||
|
return fetchInfoThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getFetchDebugThreshold() {
|
||||||
|
return fetchDebugThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getFetchTraceThreshold() {
|
||||||
|
return fetchTraceThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
SlowLogLevel getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
}
|
28
core/src/main/java/org/elasticsearch/index/SlowLogLevel.java
Normal file
28
core/src/main/java/org/elasticsearch/index/SlowLogLevel.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* 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
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.elasticsearch.index;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public enum SlowLogLevel {
|
||||||
|
WARN, TRACE, INFO, DEBUG;
|
||||||
|
public static SlowLogLevel parse(String level) {
|
||||||
|
return valueOf(level.toUpperCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
}
|
@ -1,198 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to Elasticsearch under one or more contributor
|
|
||||||
* license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright
|
|
||||||
* ownership. Elasticsearch licenses this file to you under
|
|
||||||
* the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
* not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* 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
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.elasticsearch.index.search.stats;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.Strings;
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public final class SearchSlowLog {
|
|
||||||
|
|
||||||
private boolean reformat;
|
|
||||||
|
|
||||||
private long queryWarnThreshold;
|
|
||||||
private long queryInfoThreshold;
|
|
||||||
private long queryDebugThreshold;
|
|
||||||
private long queryTraceThreshold;
|
|
||||||
|
|
||||||
private long fetchWarnThreshold;
|
|
||||||
private long fetchInfoThreshold;
|
|
||||||
private long fetchDebugThreshold;
|
|
||||||
private long fetchTraceThreshold;
|
|
||||||
|
|
||||||
private String level;
|
|
||||||
|
|
||||||
private final ESLogger queryLogger;
|
|
||||||
private final ESLogger fetchLogger;
|
|
||||||
|
|
||||||
private static final String INDEX_SEARCH_SLOWLOG_PREFIX = "index.search.slowlog";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN = INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.warn";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO = INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.info";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG = INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.debug";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE = INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.query.trace";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN = INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.warn";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO = INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.info";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG = INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.debug";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE = INDEX_SEARCH_SLOWLOG_PREFIX + ".threshold.fetch.trace";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_REFORMAT = INDEX_SEARCH_SLOWLOG_PREFIX + ".reformat";
|
|
||||||
public static final String INDEX_SEARCH_SLOWLOG_LEVEL = INDEX_SEARCH_SLOWLOG_PREFIX + ".level";
|
|
||||||
|
|
||||||
public SearchSlowLog(Settings indexSettings) {
|
|
||||||
|
|
||||||
this.reformat = indexSettings.getAsBoolean(INDEX_SEARCH_SLOWLOG_REFORMAT, true);
|
|
||||||
|
|
||||||
this.queryWarnThreshold = indexSettings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN, TimeValue.timeValueNanos(-1)).nanos();
|
|
||||||
this.queryInfoThreshold = indexSettings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO, TimeValue.timeValueNanos(-1)).nanos();
|
|
||||||
this.queryDebugThreshold = indexSettings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG, TimeValue.timeValueNanos(-1)).nanos();
|
|
||||||
this.queryTraceThreshold = indexSettings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE, TimeValue.timeValueNanos(-1)).nanos();
|
|
||||||
|
|
||||||
this.fetchWarnThreshold = indexSettings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN, TimeValue.timeValueNanos(-1)).nanos();
|
|
||||||
this.fetchInfoThreshold = indexSettings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO, TimeValue.timeValueNanos(-1)).nanos();
|
|
||||||
this.fetchDebugThreshold = indexSettings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG, TimeValue.timeValueNanos(-1)).nanos();
|
|
||||||
this.fetchTraceThreshold = indexSettings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE, TimeValue.timeValueNanos(-1)).nanos();
|
|
||||||
|
|
||||||
this.level = indexSettings.get(INDEX_SEARCH_SLOWLOG_LEVEL, "TRACE").toUpperCase(Locale.ROOT);
|
|
||||||
|
|
||||||
this.queryLogger = Loggers.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query");
|
|
||||||
this.fetchLogger = Loggers.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch");
|
|
||||||
|
|
||||||
queryLogger.setLevel(level);
|
|
||||||
fetchLogger.setLevel(level);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onQueryPhase(SearchContext context, long tookInNanos) {
|
|
||||||
if (queryWarnThreshold >= 0 && tookInNanos > queryWarnThreshold) {
|
|
||||||
queryLogger.warn("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
|
||||||
} else if (queryInfoThreshold >= 0 && tookInNanos > queryInfoThreshold) {
|
|
||||||
queryLogger.info("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
|
||||||
} else if (queryDebugThreshold >= 0 && tookInNanos > queryDebugThreshold) {
|
|
||||||
queryLogger.debug("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
|
||||||
} else if (queryTraceThreshold >= 0 && tookInNanos > queryTraceThreshold) {
|
|
||||||
queryLogger.trace("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onFetchPhase(SearchContext context, long tookInNanos) {
|
|
||||||
if (fetchWarnThreshold >= 0 && tookInNanos > fetchWarnThreshold) {
|
|
||||||
fetchLogger.warn("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
|
||||||
} else if (fetchInfoThreshold >= 0 && tookInNanos > fetchInfoThreshold) {
|
|
||||||
fetchLogger.info("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
|
||||||
} else if (fetchDebugThreshold >= 0 && tookInNanos > fetchDebugThreshold) {
|
|
||||||
fetchLogger.debug("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
|
||||||
} else if (fetchTraceThreshold >= 0 && tookInNanos > fetchTraceThreshold) {
|
|
||||||
fetchLogger.trace("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onRefreshSettings(Settings settings) {
|
|
||||||
long queryWarnThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN, TimeValue.timeValueNanos(this.queryWarnThreshold)).nanos();
|
|
||||||
if (queryWarnThreshold != this.queryWarnThreshold) {
|
|
||||||
this.queryWarnThreshold = queryWarnThreshold;
|
|
||||||
}
|
|
||||||
long queryInfoThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO, TimeValue.timeValueNanos(this.queryInfoThreshold)).nanos();
|
|
||||||
if (queryInfoThreshold != this.queryInfoThreshold) {
|
|
||||||
this.queryInfoThreshold = queryInfoThreshold;
|
|
||||||
}
|
|
||||||
long queryDebugThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG, TimeValue.timeValueNanos(this.queryDebugThreshold)).nanos();
|
|
||||||
if (queryDebugThreshold != this.queryDebugThreshold) {
|
|
||||||
this.queryDebugThreshold = queryDebugThreshold;
|
|
||||||
}
|
|
||||||
long queryTraceThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE, TimeValue.timeValueNanos(this.queryTraceThreshold)).nanos();
|
|
||||||
if (queryTraceThreshold != this.queryTraceThreshold) {
|
|
||||||
this.queryTraceThreshold = queryTraceThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
long fetchWarnThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN, TimeValue.timeValueNanos(this.fetchWarnThreshold)).nanos();
|
|
||||||
if (fetchWarnThreshold != this.fetchWarnThreshold) {
|
|
||||||
this.fetchWarnThreshold = fetchWarnThreshold;
|
|
||||||
}
|
|
||||||
long fetchInfoThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO, TimeValue.timeValueNanos(this.fetchInfoThreshold)).nanos();
|
|
||||||
if (fetchInfoThreshold != this.fetchInfoThreshold) {
|
|
||||||
this.fetchInfoThreshold = fetchInfoThreshold;
|
|
||||||
}
|
|
||||||
long fetchDebugThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG, TimeValue.timeValueNanos(this.fetchDebugThreshold)).nanos();
|
|
||||||
if (fetchDebugThreshold != this.fetchDebugThreshold) {
|
|
||||||
this.fetchDebugThreshold = fetchDebugThreshold;
|
|
||||||
}
|
|
||||||
long fetchTraceThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE, TimeValue.timeValueNanos(this.fetchTraceThreshold)).nanos();
|
|
||||||
if (fetchTraceThreshold != this.fetchTraceThreshold) {
|
|
||||||
this.fetchTraceThreshold = fetchTraceThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
String level = settings.get(INDEX_SEARCH_SLOWLOG_LEVEL, this.level);
|
|
||||||
if (!level.equals(this.level)) {
|
|
||||||
this.queryLogger.setLevel(level.toUpperCase(Locale.ROOT));
|
|
||||||
this.fetchLogger.setLevel(level.toUpperCase(Locale.ROOT));
|
|
||||||
this.level = level;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean reformat = settings.getAsBoolean(INDEX_SEARCH_SLOWLOG_REFORMAT, this.reformat);
|
|
||||||
if (reformat != this.reformat) {
|
|
||||||
this.reformat = reformat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SlowLogSearchContextPrinter {
|
|
||||||
private final SearchContext context;
|
|
||||||
private final long tookInNanos;
|
|
||||||
private final boolean reformat;
|
|
||||||
|
|
||||||
public SlowLogSearchContextPrinter(SearchContext context, long tookInNanos, boolean reformat) {
|
|
||||||
this.context = context;
|
|
||||||
this.tookInNanos = tookInNanos;
|
|
||||||
this.reformat = reformat;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("took[").append(TimeValue.timeValueNanos(tookInNanos)).append("], took_millis[").append(TimeUnit.NANOSECONDS.toMillis(tookInNanos)).append("], ");
|
|
||||||
if (context.types() == null) {
|
|
||||||
sb.append("types[], ");
|
|
||||||
} else {
|
|
||||||
sb.append("types[");
|
|
||||||
Strings.arrayToDelimitedString(context.types(), ",", sb);
|
|
||||||
sb.append("], ");
|
|
||||||
}
|
|
||||||
if (context.groupStats() == null) {
|
|
||||||
sb.append("stats[], ");
|
|
||||||
} else {
|
|
||||||
sb.append("stats[");
|
|
||||||
Strings.collectionToDelimitedString(context.groupStats(), ",", "", "", sb);
|
|
||||||
sb.append("], ");
|
|
||||||
}
|
|
||||||
sb.append("search_type[").append(context.searchType()).append("], total_shards[").append(context.numberOfShards()).append("], ");
|
|
||||||
if (context.request().source() != null) {
|
|
||||||
sb.append("source[").append(context.request().source()).append("], ");
|
|
||||||
} else {
|
|
||||||
sb.append("source[], ");
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.metrics.CounterMetric;
|
|||||||
import org.elasticsearch.common.metrics.MeanMetric;
|
import org.elasticsearch.common.metrics.MeanMetric;
|
||||||
import org.elasticsearch.common.regex.Regex;
|
import org.elasticsearch.common.regex.Regex;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.index.SearchSlowLog;
|
||||||
import org.elasticsearch.search.internal.SearchContext;
|
import org.elasticsearch.search.internal.SearchContext;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -179,10 +180,6 @@ public final class ShardSearchStats {
|
|||||||
totalStats.scrollMetric.inc(System.nanoTime() - context.getOriginNanoTime());
|
totalStats.scrollMetric.inc(System.nanoTime() - context.getOriginNanoTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRefreshSettings(Settings settings) {
|
|
||||||
slowLogSearchService.onRefreshSettings(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
final static class StatsHolder {
|
final static class StatsHolder {
|
||||||
public final MeanMetric queryMetric = new MeanMetric();
|
public final MeanMetric queryMetric = new MeanMetric();
|
||||||
public final MeanMetric fetchMetric = new MeanMetric();
|
public final MeanMetric fetchMetric = new MeanMetric();
|
||||||
|
@ -91,7 +91,7 @@ import org.elasticsearch.index.percolator.PercolatorQueriesRegistry;
|
|||||||
import org.elasticsearch.index.query.QueryShardContext;
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.index.recovery.RecoveryStats;
|
import org.elasticsearch.index.recovery.RecoveryStats;
|
||||||
import org.elasticsearch.index.refresh.RefreshStats;
|
import org.elasticsearch.index.refresh.RefreshStats;
|
||||||
import org.elasticsearch.index.search.stats.SearchSlowLog;
|
import org.elasticsearch.index.SearchSlowLog;
|
||||||
import org.elasticsearch.index.search.stats.SearchStats;
|
import org.elasticsearch.index.search.stats.SearchStats;
|
||||||
import org.elasticsearch.index.search.stats.ShardSearchStats;
|
import org.elasticsearch.index.search.stats.ShardSearchStats;
|
||||||
import org.elasticsearch.index.similarity.SimilarityService;
|
import org.elasticsearch.index.similarity.SimilarityService;
|
||||||
|
@ -29,7 +29,7 @@ import org.elasticsearch.index.engine.EngineFactory;
|
|||||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.merge.MergeStats;
|
import org.elasticsearch.index.merge.MergeStats;
|
||||||
import org.elasticsearch.index.search.stats.SearchSlowLog;
|
import org.elasticsearch.index.SearchSlowLog;
|
||||||
import org.elasticsearch.index.similarity.SimilarityService;
|
import org.elasticsearch.index.similarity.SimilarityService;
|
||||||
import org.elasticsearch.index.store.Store;
|
import org.elasticsearch.index.store.Store;
|
||||||
import org.elasticsearch.index.translog.TranslogStats;
|
import org.elasticsearch.index.translog.TranslogStats;
|
||||||
|
@ -25,7 +25,6 @@ import org.apache.lucene.document.StringField;
|
|||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
@ -90,7 +89,7 @@ public class IndexingSlowLogTests extends ESTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testLevelSetting() {
|
public void testLevelSetting() {
|
||||||
IndexingSlowLog.Level level = randomFrom(IndexingSlowLog.Level.values());
|
SlowLogLevel level = randomFrom(SlowLogLevel.values());
|
||||||
IndexMetaData metaData = newIndexMeta("index", Settings.settingsBuilder()
|
IndexMetaData metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
.put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), level)
|
.put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), level)
|
||||||
@ -98,10 +97,10 @@ public class IndexingSlowLogTests extends ESTestCase {
|
|||||||
IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
|
IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
IndexingSlowLog log = new IndexingSlowLog(settings);
|
IndexingSlowLog log = new IndexingSlowLog(settings);
|
||||||
assertEquals(level, log.getLevel());
|
assertEquals(level, log.getLevel());
|
||||||
level = randomFrom(IndexingSlowLog.Level.values());
|
level = randomFrom(SlowLogLevel.values());
|
||||||
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), level).build()));
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), level).build()));
|
||||||
assertEquals(level, log.getLevel());
|
assertEquals(level, log.getLevel());
|
||||||
level = randomFrom(IndexingSlowLog.Level.values());
|
level = randomFrom(SlowLogLevel.values());
|
||||||
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), level).build()));
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), level).build()));
|
||||||
assertEquals(level, log.getLevel());
|
assertEquals(level, log.getLevel());
|
||||||
|
|
||||||
@ -110,7 +109,7 @@ public class IndexingSlowLogTests extends ESTestCase {
|
|||||||
assertEquals(level, log.getLevel());
|
assertEquals(level, log.getLevel());
|
||||||
|
|
||||||
settings.updateIndexMetaData(newIndexMeta("index", Settings.EMPTY));
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.EMPTY));
|
||||||
assertEquals(IndexingSlowLog.Level.TRACE, log.getLevel());
|
assertEquals(SlowLogLevel.TRACE, log.getLevel());
|
||||||
|
|
||||||
metaData = newIndexMeta("index", Settings.settingsBuilder()
|
metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
@ -122,9 +121,9 @@ public class IndexingSlowLogTests extends ESTestCase {
|
|||||||
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), "NOT A LEVEL").build()));
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexingSlowLog.INDEX_INDEXING_SLOWLOG_LEVEL_SETTING.getKey(), "NOT A LEVEL").build()));
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
assertEquals(ex.getMessage(), "No enum constant org.elasticsearch.index.IndexingSlowLog.Level.NOT A LEVEL");
|
assertEquals(ex.getMessage(), "No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL");
|
||||||
}
|
}
|
||||||
assertEquals(IndexingSlowLog.Level.TRACE, log.getLevel());
|
assertEquals(SlowLogLevel.TRACE, log.getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetLevels() {
|
public void testSetLevels() {
|
||||||
|
@ -0,0 +1,253 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* 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
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index;
|
||||||
|
|
||||||
|
import org.elasticsearch.Version;
|
||||||
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
|
||||||
|
|
||||||
|
public class SearchSlowLogTests extends ESTestCase {
|
||||||
|
|
||||||
|
public void testReformatSetting() {
|
||||||
|
IndexMetaData metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_REFORMAT.getKey(), false)
|
||||||
|
.build());
|
||||||
|
IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
|
SearchSlowLog log = new SearchSlowLog(settings);
|
||||||
|
assertFalse(log.isReformat());
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_REFORMAT.getKey(), "true").build()));
|
||||||
|
assertTrue(log.isReformat());
|
||||||
|
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_REFORMAT.getKey(), "false").build()));
|
||||||
|
assertFalse(log.isReformat());
|
||||||
|
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.EMPTY));
|
||||||
|
assertTrue(log.isReformat());
|
||||||
|
|
||||||
|
metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.build());
|
||||||
|
settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
|
log = new SearchSlowLog(settings);
|
||||||
|
assertTrue(log.isReformat());
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_REFORMAT.getKey(), "NOT A BOOLEAN").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse value [NOT A BOOLEAN] cannot be parsed to boolean [ true/1/on/yes OR false/0/off/no ]");
|
||||||
|
}
|
||||||
|
assertTrue(log.isReformat());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLevelSetting() {
|
||||||
|
SlowLogLevel level = randomFrom(SlowLogLevel.values());
|
||||||
|
IndexMetaData metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), level)
|
||||||
|
.build());
|
||||||
|
IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
|
SearchSlowLog log = new SearchSlowLog(settings);
|
||||||
|
assertEquals(level, log.getLevel());
|
||||||
|
level = randomFrom(SlowLogLevel.values());
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), level).build()));
|
||||||
|
assertEquals(level, log.getLevel());
|
||||||
|
level = randomFrom(SlowLogLevel.values());
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), level).build()));
|
||||||
|
assertEquals(level, log.getLevel());
|
||||||
|
|
||||||
|
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), level).build()));
|
||||||
|
assertEquals(level, log.getLevel());
|
||||||
|
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.EMPTY));
|
||||||
|
assertEquals(SlowLogLevel.TRACE, log.getLevel());
|
||||||
|
|
||||||
|
metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.build());
|
||||||
|
settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
|
log = new SearchSlowLog(settings);
|
||||||
|
assertTrue(log.isReformat());
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_LEVEL.getKey(), "NOT A LEVEL").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "No enum constant org.elasticsearch.index.SlowLogLevel.NOT A LEVEL");
|
||||||
|
}
|
||||||
|
assertEquals(SlowLogLevel.TRACE, log.getLevel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSetQueryLevels() {
|
||||||
|
IndexMetaData metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING.getKey(), "100ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING.getKey(), "200ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING.getKey(), "300ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING.getKey(), "400ms")
|
||||||
|
.build());
|
||||||
|
IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
|
SearchSlowLog log = new SearchSlowLog(settings);
|
||||||
|
assertEquals(TimeValue.timeValueMillis(100).nanos(), log.getQueryTraceThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(200).nanos(), log.getQueryDebugThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(300).nanos(), log.getQueryInfoThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(400).nanos(), log.getQueryWarnThreshold());
|
||||||
|
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING.getKey(), "120ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING.getKey(), "220ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING.getKey(), "320ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING.getKey(), "420ms").build()));
|
||||||
|
|
||||||
|
|
||||||
|
assertEquals(TimeValue.timeValueMillis(120).nanos(), log.getQueryTraceThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(220).nanos(), log.getQueryDebugThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(320).nanos(), log.getQueryInfoThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(420).nanos(), log.getQueryWarnThreshold());
|
||||||
|
|
||||||
|
metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.build());
|
||||||
|
settings.updateIndexMetaData(metaData);
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryTraceThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryDebugThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryInfoThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryWarnThreshold());
|
||||||
|
|
||||||
|
settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
|
log = new SearchSlowLog(settings);
|
||||||
|
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryTraceThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryDebugThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryInfoThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getQueryWarnThreshold());
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE_SETTING.getKey(), "NOT A TIME VALUE").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse setting [index.search.slowlog.threshold.query.trace] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG_SETTING.getKey(), "NOT A TIME VALUE").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse setting [index.search.slowlog.threshold.query.debug] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO_SETTING.getKey(), "NOT A TIME VALUE").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse setting [index.search.slowlog.threshold.query.info] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING.getKey(), "NOT A TIME VALUE").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse setting [index.search.slowlog.threshold.query.warn] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSetFetchLevels() {
|
||||||
|
IndexMetaData metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING.getKey(), "100ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING.getKey(), "200ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING.getKey(), "300ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING.getKey(), "400ms")
|
||||||
|
.build());
|
||||||
|
IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
|
SearchSlowLog log = new SearchSlowLog(settings);
|
||||||
|
assertEquals(TimeValue.timeValueMillis(100).nanos(), log.getFetchTraceThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(200).nanos(), log.getFetchDebugThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(300).nanos(), log.getFetchInfoThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(400).nanos(), log.getFetchWarnThreshold());
|
||||||
|
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING.getKey(), "120ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING.getKey(), "220ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING.getKey(), "320ms")
|
||||||
|
.put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING.getKey(), "420ms").build()));
|
||||||
|
|
||||||
|
|
||||||
|
assertEquals(TimeValue.timeValueMillis(120).nanos(), log.getFetchTraceThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(220).nanos(), log.getFetchDebugThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(320).nanos(), log.getFetchInfoThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(420).nanos(), log.getFetchWarnThreshold());
|
||||||
|
|
||||||
|
metaData = newIndexMeta("index", Settings.settingsBuilder()
|
||||||
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.build());
|
||||||
|
settings.updateIndexMetaData(metaData);
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchTraceThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchDebugThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchInfoThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchWarnThreshold());
|
||||||
|
|
||||||
|
settings = new IndexSettings(metaData, Settings.EMPTY);
|
||||||
|
log = new SearchSlowLog(settings);
|
||||||
|
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchTraceThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchDebugThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchInfoThreshold());
|
||||||
|
assertEquals(TimeValue.timeValueMillis(-1).nanos(), log.getFetchWarnThreshold());
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE_SETTING.getKey(), "NOT A TIME VALUE").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse setting [index.search.slowlog.threshold.fetch.trace] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING.getKey(), "NOT A TIME VALUE").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse setting [index.search.slowlog.threshold.fetch.debug] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING.getKey(), "NOT A TIME VALUE").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse setting [index.search.slowlog.threshold.fetch.info] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING.getKey(), "NOT A TIME VALUE").build()));
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "Failed to parse setting [index.search.slowlog.threshold.fetch.warn] with value [NOT A TIME VALUE] as a time value: unit is missing or unrecognized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private IndexMetaData newIndexMeta(String name, Settings indexSettings) {
|
||||||
|
Settings build = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
|
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|
||||||
|
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||||
|
.put(indexSettings)
|
||||||
|
.build();
|
||||||
|
IndexMetaData metaData = IndexMetaData.builder(name).settings(build).build();
|
||||||
|
return metaData;
|
||||||
|
}
|
||||||
|
}
|
@ -82,7 +82,6 @@ import org.elasticsearch.index.mapper.ParseContext;
|
|||||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||||
import org.elasticsearch.index.mapper.Uid;
|
import org.elasticsearch.index.mapper.Uid;
|
||||||
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
||||||
import org.elasticsearch.index.search.stats.SearchSlowLog;
|
|
||||||
import org.elasticsearch.index.snapshots.IndexShardRepository;
|
import org.elasticsearch.index.snapshots.IndexShardRepository;
|
||||||
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
|
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
|
||||||
import org.elasticsearch.index.store.Store;
|
import org.elasticsearch.index.store.Store;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user