Skip to content

Commit

Permalink
Log AffixSetting update when using addAffixMapUpdateConsumer (elastic…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rassyan authored Mar 21, 2024
1 parent 26f7269 commit dff4fd4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/97072.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 97072
summary: Log when update AffixSetting using addAffixMapUpdateConsumer
area: Infra/Logging
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,13 @@ String innerGetRaw(final Settings settings) {
return defaultValue.apply(settings);
}

/**
* Returns the raw (string) settings value, which is for logging use
*/
String getLogString(final Settings settings) {
return getRaw(settings);
}

/** Logs a deprecation warning if the setting is deprecated and used. */
void checkDeprecation(Settings settings) {
// They're using the setting, so we need to tell them to stop
Expand Down Expand Up @@ -989,6 +996,7 @@ public Map<String, T> getValue(Settings current, Settings previous) {

@Override
public void apply(Map<String, T> value, Settings current, Settings previous) {
Setting.logSettingUpdate(AffixSetting.this, current, previous, logger);
consumer.accept(value);
}
};
Expand All @@ -1008,6 +1016,20 @@ public String innerGetRaw(final Settings settings) {
);
}

@Override
String getLogString(final Settings settings) {
Settings filteredAffixSetting = settings.filter(this::match);
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
filteredAffixSetting.toXContent(builder, new MapParams(Collections.singletonMap("flat_settings", "true")));
builder.endObject();
return Strings.toString(builder);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public Setting<T> getConcreteSetting(String key) {
if (match(key)) {
Expand Down Expand Up @@ -1811,7 +1833,7 @@ static void logSettingUpdate(Setting<?> setting, Settings current, Settings prev
if (setting.isFiltered()) {
logger.info("updating [{}]", setting.key);
} else {
logger.info("updating [{}] from [{}] to [{}]", setting.key, setting.getRaw(previous), setting.getRaw(current));
logger.info("updating [{}] from [{}] to [{}]", setting.key, setting.getLogString(previous), setting.getLogString(current));
}
}
}
Expand Down

0 comments on commit dff4fd4

Please sign in to comment.