Revert Ignore slow log configuration on shard creation
This reverts commit 10810f00d4
as this introduces an exception to the rule when parsing settings.
This commit is contained in:
parent
10810f00d4
commit
dab841d4ec
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.search.slowlog;
|
||||
|
||||
import org.elasticsearch.ElasticSearchParseException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
|
@ -126,15 +125,15 @@ public class ShardSlowLogSearchService extends AbstractIndexShardComponent {
|
|||
|
||||
this.reformat = componentSettings.getAsBoolean("reformat", true);
|
||||
|
||||
this.queryWarnThreshold = parseTimeSetting("threshold.query.warn", -1);
|
||||
this.queryInfoThreshold = parseTimeSetting("threshold.query.info", -1);
|
||||
this.queryDebugThreshold = parseTimeSetting("threshold.query.debug", -1);
|
||||
this.queryTraceThreshold = parseTimeSetting("threshold.query.trace", -1);
|
||||
this.queryWarnThreshold = componentSettings.getAsTime("threshold.query.warn", TimeValue.timeValueNanos(-1)).nanos();
|
||||
this.queryInfoThreshold = componentSettings.getAsTime("threshold.query.info", TimeValue.timeValueNanos(-1)).nanos();
|
||||
this.queryDebugThreshold = componentSettings.getAsTime("threshold.query.debug", TimeValue.timeValueNanos(-1)).nanos();
|
||||
this.queryTraceThreshold = componentSettings.getAsTime("threshold.query.trace", TimeValue.timeValueNanos(-1)).nanos();
|
||||
|
||||
this.fetchWarnThreshold = parseTimeSetting("threshold.fetch.warn", -1);
|
||||
this.fetchInfoThreshold = parseTimeSetting("threshold.fetch.info", -1);
|
||||
this.fetchDebugThreshold = parseTimeSetting("threshold.fetch.debug", -1);
|
||||
this.fetchTraceThreshold = parseTimeSetting("threshold.fetch.trace", -1);
|
||||
this.fetchWarnThreshold = componentSettings.getAsTime("threshold.fetch.warn", TimeValue.timeValueNanos(-1)).nanos();
|
||||
this.fetchInfoThreshold = componentSettings.getAsTime("threshold.fetch.info", TimeValue.timeValueNanos(-1)).nanos();
|
||||
this.fetchDebugThreshold = componentSettings.getAsTime("threshold.fetch.debug", TimeValue.timeValueNanos(-1)).nanos();
|
||||
this.fetchTraceThreshold = componentSettings.getAsTime("threshold.fetch.trace", TimeValue.timeValueNanos(-1)).nanos();
|
||||
|
||||
this.level = componentSettings.get("level", "TRACE").toUpperCase(Locale.ROOT);
|
||||
|
||||
|
@ -147,15 +146,6 @@ public class ShardSlowLogSearchService extends AbstractIndexShardComponent {
|
|||
indexSettingsService.addListener(new ApplySettings());
|
||||
}
|
||||
|
||||
private long parseTimeSetting(String name, long defaultNanos) {
|
||||
try {
|
||||
return componentSettings.getAsTime(name, TimeValue.timeValueNanos(defaultNanos)).nanos();
|
||||
} catch (ElasticSearchParseException e) {
|
||||
logger.error("Could not parse setting for [{}], disabling", name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void onQueryPhase(SearchContext context, long tookInNanos) {
|
||||
if (queryWarnThreshold >= 0 && tookInNanos > queryWarnThreshold) {
|
||||
queryLogger.warn("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat));
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon 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.slowlog;
|
||||
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.settings.IndexSettingsService;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ShardSlowLogSearchServiceTests extends ElasticsearchTestCase {
|
||||
|
||||
private Index index = new Index("test");
|
||||
private ShardId shardId = new ShardId(index, 0);
|
||||
|
||||
|
||||
@Test
|
||||
public void creatingShardSlowLogSearchServiceWithBrokenSettingsShouldWork() throws Exception {
|
||||
Settings brokenIndexSettings = ImmutableSettings.builder()
|
||||
.put("index.search.slowlog.threshold.query.warn", "s")
|
||||
.build();
|
||||
|
||||
IndexSettingsService indexSettingsService = new IndexSettingsService(shardId.index(), brokenIndexSettings);
|
||||
new ShardSlowLogSearchService(shardId, brokenIndexSettings, indexSettingsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatingViaListenerWithBrokenSettingsLeavesSettingsAsIs() throws Exception {
|
||||
Settings indexSettings = ImmutableSettings.builder()
|
||||
.put("index.search.slowlog.threshold.query.warn", "1s")
|
||||
.build();
|
||||
|
||||
IndexSettingsService indexSettingsService = new IndexSettingsService(shardId.index(), indexSettings);
|
||||
ShardSlowLogSearchService shardSlowLogSearchService = new ShardSlowLogSearchService(shardId, indexSettings, indexSettingsService);
|
||||
|
||||
Settings updatedSettings = ImmutableSettings.builder()
|
||||
.put("index.search.slowlog.threshold.query.warn", "s")
|
||||
.build();
|
||||
indexSettingsService.refreshSettings(updatedSettings);
|
||||
|
||||
// this is still the time from the indexSettings above, but was not overriden from the settings update
|
||||
// this basically ensures that the parsing exception was caught in the refreshSettings() methods
|
||||
String configuredTime = shardSlowLogSearchService.indexSettings().get("index.search.slowlog.threshold.query.warn");
|
||||
assertThat(configuredTime, is("1s"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue