-
Notifications
You must be signed in to change notification settings - Fork 50
add logger messages to activation-worker log #1235
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
Conversation
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## main #1235 +/- ##
==========================================
- Coverage 93.90% 93.88% -0.03%
==========================================
Files 290 291 +1
Lines 16123 16161 +38
==========================================
+ Hits 15141 15172 +31
- Misses 982 989 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
||
if "ERROR" in message: | ||
LOGGER.error(message) | ||
else: |
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.
we should also check for WARN, DEBUG, FATAL, and DEBUG. It's not good to log them as INFO level.
@ShaiahWren Can you add a pytest for it? |
ad329df
to
0aff4a1
Compare
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.
Can you add a test?
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class TeeLogger(DBLogger): |
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.
Can you add a docstring clarifying the purpose of the class? Maybe use a more self descriptive name like "TeeSystemLogger" too ?
|
||
|
||
class TeeLogger(DBLogger): | ||
def __init__(self, activation_instance_id: int): |
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.
If you don't need to override or extend the initialization of the object there is no need to define __init__
here
BUT, using the LOGGER of this module probably is wrong since all the records would be tracked by this logger and we would be losing the track of the real module that is calling it.
Instead I think it is better to pass the logger in the constructor in a more dependency injector pattern and allow to be used by different implementers, We consume the DBLogger from the engines and from the manager but this new logger I guess is intent to be called only from the engine.
thoughts @hsong-rh @ShaiahWren
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 you are right @Alex-Izquierdo . I'm updating the pr now, and then I'll work on the test.
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.
Are you going to implement this new logger in this PR or in a separate PR?
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 will implement it in this pr, if that's alright with you. I also need to write the test this afternoon.
a37bb19
to
e33b011
Compare
else: | ||
log_level = logging.INFO | ||
|
||
self.logger.log(log_level, line) |
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.
We need to pass in the date times from ansible rulebook
We need to define a formatter for the TeeLogger which has a placeholder for rulebook_timestamp and we can pass that thru using extra args in the log call. The log format should align with the other formatters we have for activation worker but swap out the asctime with the rulebook_timestamp
A sample would look something like this
import logging
this would all be done in settings/post_load.py
the format should align with the rest of our formatters please check with @hsong-rh for more details
Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(rulebook_timestamp)s - %(levelname)s - %(message)s'
)
Create a logger in the teesystemlogger file
logger = logging.getLogger(name)
Log a message with extra parameters
extra_data = {'rulebook_timestamp': 'convert log_timestamp to asctime format in UTC'}
logger.log(log_level,'container id in', extra=extra_data)
I am doing this from the phone so I apologize for any typos
Also in the settings/post_load.py we need to add a settings for the TeeSystemLogger which might look something like this
"aap_eda.services.activation.tee_log_handler": {
"handlers": ["teeloggerhandler"],
the log level should always be DEBUG here since it's controlled by the activation ui screen please don't set this to the default app log level like other settings. This is purely controlled by the user running the activation they might run it with any of the three log levels DEBUG INFO or ERROR and we need to pick the lowest of these 3 for our default
"level": logging.DEBUG,
"propagate": False,
},
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.
We need to add there as well a field for the rulebook process id, we can not have in the log all those records without the rulebook process context.
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.
@mkanoor do you want to replace the existing timestamp or add new one from the rulebook one?
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.
@Alex-Izquierdo we need to preserve the timestamp from ansible-rulebook and it is present in the log_timestamp argument being passed into this function we can use that except we need to convert it to the asctime format to be consistent. The log_timestamp is in UTC and like other log lines it should get displayed in utc in our logs. This is for our debugging and support engineers coming via SOS reports the user's are not going to see it directly. We can't have 2 time stamps in the log lines it skews the visual perspective as we are debugging. In the formatter we remove the asctime with rulebook_timestamp and pass that in as extra args
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.
Agree
@@ -0,0 +1,60 @@ | |||
# Copyright 2023 Red Hat, Inc. |
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.
2025
|
||
def __init__(self, activation_instance_id: int, logger: logging.Logger): | ||
super().__init__(activation_instance_id) | ||
self.logger = logger |
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 the logger should be retrieved from the file name using
'''
import logging
LOGGER = logging.getLogger(name)
'''
This allows us to make custom settings just for this file
69c2e10
to
e1f9672
Compare
log_level = logging.INFO | ||
|
||
extra_data = {"rulebook_timestamp": rulebook_timestamp} | ||
LOGGER.log(log_level, f"{self.prefix} {line}", extra=extra_data) |
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.
if you are going to create a teelogger formater, the prefix should be part of the format
src/aap_eda/settings/post_load.py
Outdated
logging.basicConfig(level=logging.DEBUG, format=log_format) | ||
|
||
|
||
def get_logging_settings(): |
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.
how you will use this function?
@@ -203,7 +203,9 @@ def _start_activation_instance(self): | |||
self._create_activation_instance() | |||
|
|||
self.db_instance.refresh_from_db() | |||
log_handler = self.container_logger_class(self.latest_instance.id) | |||
log_handler = self.container_logger_class( | |||
self.latest_instance.id, LOGGER |
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.
Either, with a logger instance or a logger name, now we have two arguments for the constructor and one of them is the same in all the calls, only activation_instance_id
is dynamic. There is no need no repeat the same argument in all the calls, you can be more concise with a factory
def get_log_handler(self, activation_instance_id, logger=LOGGER):
return self.container_logger_class(activation_instance_id, LOGGER)
So the lines like:
log_handler = self.container_logger_class(self.latest_instance.id)
become
log_handler = self.get_log_handler(self.latest_instance.id)
e1f9672
to
f4b353f
Compare
f4b353f
to
eca9439
Compare
|
Closing the pr and replacing with #1253 |
Ensure error and info logs are written to the activation-worker logs, as well as the DB/UI logs.
AAP-41782