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 logger rotation for python services #1512

Merged
merged 5 commits into from
Mar 10, 2023

Conversation

patrickelectric
Copy link
Member

No description provided.

@patrickelectric patrickelectric force-pushed the rotate_loggert branch 8 times, most recently from bd747b8 to 75e9d29 Compare February 23, 2023 18:47
@patrickelectric patrickelectric marked this pull request as ready for review February 23, 2023 19:11
@patrickelectric
Copy link
Member Author

It does not zip logs from the camera manager since the extension is a date and not a .log file, we should fix on the camera manager, but for everything else it's working.

Comment on lines 20 to 27
for file in files:
try:
os.remove(file)
logger.debug(f"Deleted file: {file}")
except OSError as e:
logger.debug(f"Error deleting file: {file} - {e}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I said in the other PR, we should check if the file is opened (by some other service) before removing it, otherwise, we would lose all the next log lines until the service creates another log file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any suggestion of how to do it ?
I did try the following approach but was unable to make it work:
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I'm not sure why your code is not working, makes sense to me. My only concern is if using attrs parameter to create the info dict is populating correctly the open_files. Have you tried calling Process.open_files() instead? I believe it might skip some processes when an exception happens when it tries to access the process information, and by calling Process.open_files() you'd get the exception.

As an alternative, from the terminal it's usually done with lsof <filename>, maybe you could just call it from Python and check its return?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use delete_everything here instead of os.remove?

Copy link
Member Author

Choose a reason for hiding this comment

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

@joaoantoniocardoso check the latest version

@patrickelectric patrickelectric force-pushed the rotate_loggert branch 2 times, most recently from 68f334a to 927ab66 Compare March 2, 2023 13:44
Copy link
Collaborator

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

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

Now I can't click on 'remove' 👀

@patrickelectric
Copy link
Member Author

patrickelectric commented Mar 2, 2023

Now I can't click on 'remove' 👀

Remove is disabled if the size is under 100MB.

@joaoantoniocardoso
Copy link
Collaborator

Now I can't click on 'remove' eyes

Remove is disabled if the size is under 100MB.

Makes sense. I'll let it run for a while here to see the rotation. Anything specific you want me to pay attention to?

@patrickelectric
Copy link
Member Author

Now I can't click on 'remove' eyes

Remove is disabled if the size is under 100MB.

Makes sense. I'll let it run for a while here to see the rotation. Anything specific you want me to pay attention to?

Keep in mind that the PR is zipping things in a higher frequency to help with the test.

@joaoantoniocardoso
Copy link
Collaborator

joaoantoniocardoso commented Mar 2, 2023

I'm still waiting for the zip to happen, but Kraken seems to be generating doubled logs:
image

edit: Yeah, there are two init_logs calls in kraken.py

core/services/log_zipper/main.py Outdated Show resolved Hide resolved
core/services/kraken/main.py Outdated Show resolved Hide resolved
setuptools.setup(
name="log_zipper",
version="0.1.0",
description="logrotate but better",
Copy link
Collaborator

Choose a reason for hiding this comment

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

that's a bold statement isn't it 😆

Comment on lines 38 to 41
try:
logger.add(get_new_log_path(SERVICE_NAME))
init_logger(SERVICE_NAME)
except Exception as e:
print(f"unable to set logging path: {e}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the logger can fail, we should check everywhere if we want the services to be prevented or not running without logs.

Copy link
Member Author

Choose a reason for hiding this comment

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

If the logger can fail, we should check everywhere if we want the services to be prevented or not running without logs.

That's not related to this PR.

@patrickelectric
Copy link
Member Author

I'm still waiting for the zip to happen, but Kraken seems to be generating doubled logs: image

edit: Yeah, there are two init_logs calls in kraken.py

Fixed.

Copy link
Collaborator

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

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

Zipped file names are not that consistent, but I'm okay with that

image

@patrickelectric
Copy link
Member Author

Zipped file names are not that consistent, but I'm okay with that

image

They are rotated and not rotated logs

@joaoantoniocardoso
Copy link
Collaborator

Zipped file names are not that consistent, but I'm okay with that
image

They are rotated and not rotated logs

it makes sense, thanks

@ES-Alexander ES-Alexander added the docs-needed Change needs to be documented label Mar 8, 2023
…minutes

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@patrickelectric
Copy link
Member Author

@ES-Alexander where should this be documented ?

@ES-Alexander
Copy link
Collaborator

@ES-Alexander where should this be documented ?

What's the most relevant UI element?
As initial thoughts:

I feel like the behaviour change is most noticeable in the file browser, so maybe we should

  1. document it in the file browser section
    • add a main point about services creating logs, and
      • a sub-point saying that logs are rotated (at x rate) to avoid filling up space
  2. add a "see the File Browser (link) to access log files for individual services" note/dot-point to the BlueOS Settings section

I'm unsure whether it's relevant to change the Available Services docs, and it's also possible we want to rename the Log Browser section to Autopilot Log Browser, or at least clarify the text in it to make it explicit that that's for autopilot logs, not BlueOS service logs.

@patrickelectric patrickelectric merged commit f6e74bb into bluerobotics:master Mar 10, 2023
@ES-Alexander ES-Alexander added docs-complete Change documentation has been completed and removed docs-needed Change needs to be documented labels Mar 10, 2023
@joaoantoniocardoso
Copy link
Collaborator

@ES-Alexander where should this be documented ?

What's the most relevant UI element? As initial thoughts:

* the service logs are mentioned in the [BlueOS Settings](https://github.com/bluerobotics/ardusub-zola/blob/BlueOS-devel-temp/advanced-usage/index.md#blueos-settings) section

* the log files are individually accessible from the [File Browser](https://github.com/bluerobotics/ardusub-zola/blob/BlueOS-devel-temp/advanced-usage/index.md#file-browser)

* the log files are created by the [Available Services](https://github.com/bluerobotics/ardusub-zola/blob/BlueOS-devel-temp/advanced-usage/index.md#available-services)

I feel like the behaviour change is most noticeable in the file browser, so maybe we should

1. document it in the file browser section
   
   * add a main point about services creating logs, and
     
     * a sub-point saying that logs are rotated (at x rate) to avoid filling up space

2. add a "see the File Browser (link) to access log files for individual services" note/dot-point to the BlueOS Settings section

I'm unsure whether it's relevant to change the Available Services docs, and it's also possible we want to rename the Log Browser section to Autopilot Log Browser, or at least clarify the text in it to make it explicit that that's for autopilot logs, not BlueOS service logs.

I'd vote to change to Autopilot Log Browser as I've found myself entering the wrong page a few times when searching for our services logs. 😆

@ES-Alexander
Copy link
Collaborator

I'd vote to change to Autopilot Log Browser as I've found myself entering the wrong page a few times when searching for our services logs. 😆

@joaoantoniocardoso fair enough - I also think it would be helpful to clarify, although on reflection it might be preferable to have a shorter name like "Autopilot Logs" instead. Regardless, the documentation follows the implementation, so this is a BlueOS issue. Maybe we can discuss preferences in the next BlueOS meeting :-)

We could also consider having separated "Autopilot" and "BlueOS" sections in the menu-bar :-P

@Williangalvani
Copy link
Member

Williangalvani commented Mar 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-complete Change documentation has been completed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants