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

Add parameter to make sure that log of updating IndexSetting be more detailed #49969

Merged
merged 9 commits into from
Jan 3, 2020
Merged

Conversation

kkewwei
Copy link
Contributor

@kkewwei kkewwei commented Dec 8, 2019

Relates #49818
Add the parameter: target, meaning whose setting will be changed

@kkewwei kkewwei changed the title Add parameter to make sure that printing the log of updating IndexSetting be more detailed Add parameter to make sure that log of updating IndexSetting be more detailed Dec 9, 2019
Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kkewwei, I think a better approach would be to adjust the logger that this AbstractScopedSettings uses. See e.g.

this.logger = Loggers.getLogger(getClass(), indexSettings.getIndex());

for the pattern we usually use to create a per-index logger.

You will also need to supply a test that demonstrates that the messages logged now include the index name.

@DaveCTurner DaveCTurner added the :Core/Infra/Settings Settings infrastructure and APIs label Dec 9, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Settings)

@kkewwei
Copy link
Contributor Author

kkewwei commented Dec 10, 2019

@DaveCTurner, your suggestion is very helpful. TBR

final Setting.Property scope) {
final Setting.Property scope,
final String prefix) {
this.logger = Loggers.getLogger(this.getClass(), prefix);
Copy link
Contributor

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 a String, because I don't think we should be changing the behaviour for the logging of cluster-level settings.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @kkewwei, I still think this is not quite the right approach. I don't think applySettings should take a Logger, I think we should be using the AbstractScopedSettings#logger field. Something like the following.

diff --git a/server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java b/server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java
index 81b3b92844d..54a272e0715 100644
--- a/server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java
+++ b/server/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java
@@ -57,3 +57,3 @@ public abstract class AbstractScopedSettings {

-    protected final Logger logger = LogManager.getLogger(this.getClass());
+    private final Logger logger;

@@ -72,2 +72,3 @@ public abstract class AbstractScopedSettings {
             final Setting.Property scope) {
+        this.logger = LogManager.getLogger(getClass());
         this.settings = settings;
@@ -112,3 +113,4 @@ public abstract class AbstractScopedSettings {

-    protected AbstractScopedSettings(Settings nodeSettings, Settings scopeSettings, AbstractScopedSettings other) {
+    protected AbstractScopedSettings(Settings nodeSettings, Settings scopeSettings, AbstractScopedSettings other, Logger logger) {
+        this.logger = logger;
         this.settings = nodeSettings;
diff --git a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java
index f83012f2db3..29e78f53fc6 100644
--- a/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java
+++ b/server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java
@@ -20,2 +20,3 @@ package org.elasticsearch.common.settings;

+import org.apache.logging.log4j.LogManager;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
@@ -26,2 +27,3 @@ import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDe
 import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider;
+import org.elasticsearch.common.logging.Loggers;
 import org.elasticsearch.common.settings.Setting.Property;
@@ -188,3 +190,3 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
     private IndexScopedSettings(Settings settings, IndexScopedSettings other, IndexMetaData metaData) {
-        super(settings, metaData.getSettings(), other);
+        super(settings, metaData.getSettings(), other, Loggers.getLogger(IndexScopedSettings.class, metaData.getIndex()));
     }

@kkewwei
Copy link
Contributor Author

kkewwei commented Dec 11, 2019

Thank you very much for sharing code, It‘ simpler and more reasonable.

@kkewwei
Copy link
Contributor Author

kkewwei commented Dec 24, 2019

It's very kind of your suggestion.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kkewwei, one final comment about a now-unused class.

@@ -49,6 +62,27 @@

public class SettingTests extends ESTestCase {

public static class MockAppender extends AbstractAppender {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is now unused

@DaveCTurner
Copy link
Contributor

@elasticmachine test this please

@DaveCTurner
Copy link
Contributor

@elasticmachine update branch

@DaveCTurner
Copy link
Contributor

@elasticmachine test this please

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DaveCTurner DaveCTurner merged commit 902e6f6 into elastic:master Jan 3, 2020
DaveCTurner pushed a commit that referenced this pull request Jan 3, 2020
Today we log changes to index settings like this:

    updating [index.setting.blah] from [A] to [B]

The identity of the index whose settings were updated is conspicuously absent
from this message. This commit addresses this by adding the index name to these
messages.

Fixes #49818.
@kkewwei kkewwei deleted the fix_49818 branch January 3, 2020 11:31
SivagurunathanV pushed a commit to SivagurunathanV/elasticsearch that referenced this pull request Jan 23, 2020
Today we log changes to index settings like this:

    updating [index.setting.blah] from [A] to [B]

The identity of the index whose settings were updated is conspicuously absent
from this message. This commit addresses this by adding the index name to these
messages.

Fixes elastic#49818.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants