-
Notifications
You must be signed in to change notification settings - Fork 82
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
RHCLOUD-4283 - Enabling stdout logs #650
Merged
Merged
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f150695
rebasing
tahmidefaz 4d83a84
using logconfig as default log_config_file
tahmidefaz f4d5bc2
Merge branch 'master' into stdout-logging
tahmidefaz afca122
Merge remote-tracking branch 'origin' into stdout-logging
tahmidefaz c983e0c
resolving conflicts
tahmidefaz e693f88
applying suggestions
tahmidefaz 8e61d98
fixing cloudwatch logs
tahmidefaz 188767e
Merge branch 'master' into stdout-logging
shdunning 5a794b3
cloudwatch working without global vars :tada:
tahmidefaz 9292e45
Merge branch 'master' into stdout-logging
tahmidefaz 8a9a754
Merge branch 'master' into stdout-logging
Glutexo dfc53ba
Merge branch 'master' into stdout-logging
Glutexo 3f29d5f
Stdout logging (#673)
tahmidefaz adc7f91
remove cw handler if creds not present
tahmidefaz 6a0bd5b
freaking lint :man_facepalming:
tahmidefaz 4dee8cb
reverting
tahmidefaz c7bda5e
reverting
tahmidefaz 36895ea
fix
tahmidefaz 060c8a5
Merge branch 'master' into stdout-logging
tahmidefaz 68dd40a
deleting logconfig.ini
tahmidefaz a824ae5
Merge branch 'stdout-logging' of github.com:RedHatInsights/insights-h…
tahmidefaz 213a10e
addressing suggestions
tahmidefaz 270d3fe
Remove redundant logging
Glutexo 9628b91
Remove config file variable from Makefile
Glutexo 8ad446c
update README
jharting File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,10 +13,12 @@ | |||||||||
|
||||||||||
threadctx = local() | ||||||||||
|
||||||||||
session_boto3 = None | ||||||||||
|
||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
def configure_logging(config_name): | ||||||||||
env_var_name = "INVENTORY_LOGGING_CONFIG_FILE" | ||||||||||
log_config_file = os.getenv(env_var_name) | ||||||||||
log_config_file = os.getenv(env_var_name, "logconfig.ini") | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
if log_config_file is not None: | ||||||||||
# The logging module throws an odd error (KeyError) if the | ||||||||||
# config file is not found. Hopefully, this makes it more clear. | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
@@ -43,7 +45,6 @@ def _configure_watchtower_logging_handler(): | |||||||||
aws_region_name = os.getenv("AWS_REGION_NAME", None) | ||||||||||
log_group = os.getenv("AWS_LOG_GROUP", "platform") | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
stream_name = os.getenv("AWS_LOG_STREAM", _get_hostname()) # default to hostname | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
create_log_group = str(os.getenv("AWS_CREATE_LOG_GROUP")).lower() == "true" | ||||||||||
|
||||||||||
if all([aws_access_key_id, aws_secret_access_key, aws_region_name, stream_name]): | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
print(f"Configuring watchtower logging (log_group={log_group}, stream_name={stream_name})") | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
@@ -53,19 +54,24 @@ def _configure_watchtower_logging_handler(): | |||||||||
region_name=aws_region_name, | ||||||||||
) | ||||||||||
|
||||||||||
root = logging.getLogger() | ||||||||||
handler = watchtower.CloudWatchLogHandler( | ||||||||||
boto3_session=boto3_session, | ||||||||||
log_group=log_group, | ||||||||||
stream_name=stream_name, | ||||||||||
create_log_group=create_log_group, | ||||||||||
) | ||||||||||
handler.setFormatter(logstash_formatter.LogstashFormatterV1()) | ||||||||||
root.addHandler(handler) | ||||||||||
global session_boto3 | ||||||||||
session_boto3 = boto3_session | ||||||||||
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.
Suggested change
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. see my comment below |
||||||||||
else: | ||||||||||
print("Unable to configure watchtower logging. Please verify watchtower logging configuration!") | ||||||||||
|
||||||||||
|
||||||||||
def _get_cloudwatch_handler(): | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
global session_boto3 | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
group = os.getenv("AWS_LOG_GROUP", "platform") | ||||||||||
stream = os.getenv("AWS_LOG_STREAM", _get_hostname()) | ||||||||||
create_log_group = str(os.getenv("AWS_CREATE_LOG_GROUP")).lower() == "true" | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
handler = watchtower.CloudWatchLogHandler( | ||||||||||
boto3_session=session_boto3, log_group=group, stream_name=stream, create_log_group=create_log_group | ||||||||||
) | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
handler.setFormatter(logstash_formatter.LogstashFormatterV1()) | ||||||||||
return handler | ||||||||||
|
||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
def _get_hostname(): | ||||||||||
return os.uname()[1] | ||||||||||
|
||||||||||
|
@@ -122,5 +128,10 @@ def get_logger(name): | |||||||||
log_level = os.getenv("INVENTORY_LOG_LEVEL", "INFO").upper() | ||||||||||
logger = logging.getLogger(LOGGER_PREFIX + name) | ||||||||||
logger.addFilter(ContextualFilter()) | ||||||||||
|
||||||||||
global session_boto3 | ||||||||||
if session_boto3 is not None: | ||||||||||
logger.addHandler(_get_cloudwatch_handler()) | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
logger.setLevel(log_level) | ||||||||||
return logger | ||||||||||
tahmidefaz marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Is the comment actually true? Even if we get the logger before the configuration, its configuration still gets updated. It makes perfect sense to get the logger after the configuration, but technically it’s not necessary.
To reproduce, swap these two lines and see the logging still works the same. Compare to how it doesn’t work if you try to log something before the configuration.
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 believe the reason I moved this line around was that due to the way logging was setup earlier, some of the logs weren't being produced. However, after the logging refactoring, that seems to be fixed. I will move it back to where it was earlier. 👍