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

Configure AWS SDK logging at runtime to hide ~/.aws/config WARN messages #88133

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tlrx
Copy link
Member

@tlrx tlrx commented Jun 28, 2022

We used to hide some noisy WARN log messages emitted by
the AWS SDK by setting them to ERROR level in log4j2.properties.
Since the repository plugins have been converted to modules, the
log4j2.properties files are not always updated during if users
have modified the log4j2.properties.

This pull request configures the logging level of some specific
AWS classes in order to hide the noisy messages even in the case
the log4j2.properties files have been modified.

Relates #56346, #62522, #20313

We used to hide some noisy WARN log messages emitted by
the AWS SDK by setting them to ERROR level in log4j2.properties.
Since the repository plugins have been converted to modules, the
log4j2.properties files are not always updated during if users
have modified the log4j2.properties.

This pull request configures the logging level of some specific
AWS classes in order to hide the noisy messages even in the case
the log4j2.properties files have been modified.
@tlrx tlrx added >non-issue :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs :Distributed Coordination/Discovery-Plugins Anything related to our integration plugins with EC2, GCP and Azure v8.4.0 v8.3.1 labels Jun 28, 2022
@elasticmachine elasticmachine added the Team:Distributed Meta label for distributed team (obsolete) label Jun 28, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

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.

👍 certainly works.

Could we have something in the relevant test suites to assert that we don't emit any warning logs from com.amazonaws.*? As well as testing this specific change, that'd make sure we proactively address any future bogus warnings too.

).stream().map(LogManager::getLogger).collect(Collectors.toUnmodifiableMap(logger -> logger, Logger::getLevel));
try {
awsConfigLoggers.forEach((logger, level) -> {
if (level.isLessSpecificThan(Level.ERROR)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm actually I'm not sure about this bit. This means we can't override this behaviour at runtime even if we wanted to see these messages. Is that the intention? I guess we have to override INFO and WARN since these are the possible defaults, but maybe if the level is DEBUG or TRACE we shouldn't override it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at my change and your comment, I think I should address this differently. What I did here hides the noisy warning messages during ClientConfiguration class initialization only. This is still possible that BasicProfileConfigFileLoader et al emit more warning messages after that.

I pushed f193c2f to change a bit this logic: it now detects if the AWS loggers are explicitly configured in log4j2.properties and in case they aren't, their levels are set to ERROR. This way we don't override any existing file configuration (if a user really wants to see debug or warn messages) during the startup and until the cluster settings are applied (in which case a different logging level might override the ERROR level we configured). I also added tests.

Let me know what you think.

BasicProfileConfigFileLoader.class,
SdkMBeanRegistrySupport.class,
UseArnRegionResolver.class
).stream().map(LogManager::getLogger).collect(Collectors.toUnmodifiableMap(logger -> logger, Logger::getLevel));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: List.of(...).stream() is just Stream.of(...).

@arteam arteam self-requested a review July 1, 2022 10:59
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.

I think this is a reasonable approach too but it does mean that users have to set the level on these specific loggers, and not their ancestors. For instance, we explicitly set com.amazonaws to level WARN in the config file, but changing that isn't going to change these specific loggers.

I think that's ok for the sake of implementation simplicity but feel it deserves a mention in the docs to spell out exactly which classes are affected by this.

@pugnascotia pugnascotia added v8.3.3 and removed v8.3.2 labels Jul 7, 2022
@elasticsearchmachine elasticsearchmachine changed the base branch from master to main July 22, 2022 23:06
@mark-vieira mark-vieira added v8.5.0 and removed v8.4.0 labels Jul 27, 2022
Copy link
Contributor

@arteam arteam left a comment

Choose a reason for hiding this comment

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

LGTM! I think this should prevent noisy AWS logging for users with a custom log4j configu

@arteam
Copy link
Contributor

arteam commented Jul 27, 2022

@elasticmachine update branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Discovery-Plugins Anything related to our integration plugins with EC2, GCP and Azure :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >non-issue Team:Distributed Meta label for distributed team (obsolete) v8.3.4 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.