-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Add parameter to make sure that log of updating IndexSetting be more detailed #49969
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02a5cdc
fix issue-49818
kkewwei f987ce0
add prefix to logger
kkewwei ec0bb37
添加单元测试
kkewwei 5a9b705
subclasses privide their own logger
kkewwei f5364d3
pass AbstractScopedSettings#logger by subclasses
kkewwei 11ef848
Merge branch 'master' into 2019-12-17-49969
DaveCTurner 52dce94
make unit test more standard
kkewwei 3ddc4e4
delete unused class
kkewwei 970b41b
Merge branch 'master' into fix_49818
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,21 @@ | |
*/ | ||
package org.elasticsearch.common.settings; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
import org.apache.logging.log4j.core.filter.RegexFilter; | ||
import org.apache.logging.log4j.core.impl.MementoMessage; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.common.collect.Tuple; | ||
import org.elasticsearch.common.logging.Loggers; | ||
import org.elasticsearch.common.settings.AbstractScopedSettings.SettingUpdater; | ||
import org.elasticsearch.common.settings.Setting.Property; | ||
import org.elasticsearch.common.unit.ByteSizeUnit; | ||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.monitor.jvm.JvmInfo; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
|
@@ -40,6 +49,7 @@ | |
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.elasticsearch.index.IndexSettingsTests.newIndexMeta; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
@@ -49,6 +59,27 @@ | |
|
||
public class SettingTests extends ESTestCase { | ||
|
||
public static class MockAppender extends AbstractAppender { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class is now unused |
||
private LogEvent lastEvent; | ||
|
||
public MockAppender(final String name) throws IllegalAccessException { | ||
super(name, RegexFilter.createFilter(".*(\n.*)*", new String[0], false, null, null), null); | ||
} | ||
|
||
@Override | ||
public void append(LogEvent event) { | ||
lastEvent = event.toImmutable(); | ||
} | ||
|
||
public MementoMessage lastMementoMessage() { | ||
return (MementoMessage) lastEvent.getMessage(); | ||
} | ||
|
||
public String getLoggerMaker() { | ||
return lastEvent.getMarker().getName(); | ||
} | ||
} | ||
|
||
public void testGet() { | ||
Setting<Boolean> booleanSetting = Setting.boolSetting("foo.bar", false, Property.Dynamic, Property.NodeScope); | ||
assertFalse(booleanSetting.get(Settings.EMPTY)); | ||
|
@@ -1092,4 +1123,22 @@ public void testNonSecureSettingInKeystore() { | |
assertThat(e.getMessage(), containsString("must be stored inside elasticsearch.yml")); | ||
} | ||
|
||
public void testLogSettingUpdate() throws Exception { | ||
IndexMetaData metaData = newIndexMeta("index1", Settings.builder() | ||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) | ||
.put(IndexSettings.INDEX_WARMER_ENABLED_SETTING.getKey(), false) | ||
.build()); | ||
IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY); | ||
Logger logger = settings.getScopedSettings().logger; | ||
|
||
MockAppender appender = new MockAppender("trace_appender"); | ||
kkewwei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
appender.start(); | ||
Loggers.addAppender(logger, appender); | ||
|
||
settings.updateIndexMetaData(newIndexMeta("index1", Settings.builder().put(IndexSettings.INDEX_WARMER_ENABLED_SETTING.getKey(), | ||
"true").build())); | ||
|
||
assertThat(appender.lastMementoMessage().getFormattedMessage(), equalTo("updating [index.warmer.enabled] from [false] to [true]")); | ||
assertThat(appender.getLoggerMaker(), equalTo("[index1]")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be better to allow subclasses to provide their own
logger
rather than just aString
, because I don't think we should be changing the behaviour for the logging of cluster-level settings.