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

Use Systemd Journal API for all logs endpoints in API #4972

Merged
merged 5 commits into from
Apr 4, 2024

Conversation

sairon
Copy link
Member

@sairon sairon commented Mar 20, 2024

Proposed change

Replace all logs endpoints using container logs with wrapped advanced_logs function, adding possibility to get logs from previous boots and following the logs. Supervisor logs are an excetion where Docker logs are still used - in case an exception is raised while accessing the Systemd logs, they're used as fallback - otherwise we wouldn't have an easy way to see what went wrong.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints of add-on configuration are added/changed:

@sairon sairon added API new-feature A new feature labels Mar 20, 2024
@sairon sairon force-pushed the use-advanced-logs-in-api branch 4 times, most recently from 4aed656 to e68ef3c Compare March 20, 2024 17:17
@sairon sairon force-pushed the use-advanced-logs-in-api branch from e68ef3c to c2f40c5 Compare March 25, 2024 12:38
Copy link
Contributor

@mdegat01 mdegat01 left a comment

Choose a reason for hiding this comment

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

Mostly minor comments although there is an issue with the addon logs one that requires some tweaks, see the comment below.

supervisor/api/__init__.py Outdated Show resolved Hide resolved
supervisor/api/__init__.py Outdated Show resolved Hide resolved
supervisor/api/__init__.py Outdated Show resolved Hide resolved
tests/api/test_addons.py Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft March 25, 2024 18:44
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@sairon sairon force-pushed the use-advanced-logs-in-api branch from 90c31c1 to afeea5b Compare March 26, 2024 16:53
@sairon sairon requested a review from mdegat01 March 26, 2024 16:55
@sairon sairon marked this pull request as ready for review March 26, 2024 16:55
@sairon
Copy link
Member Author

sairon commented Apr 2, 2024

This PR should also address this older RFC: #3309

supervisor/api/utils.py Outdated Show resolved Hide resolved
supervisor/api/utils.py Outdated Show resolved Hide resolved
supervisor/api/utils.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft April 2, 2024 18:57
sairon added 4 commits April 3, 2024 09:17
Replace all logs endpoints using container logs with wrapped
advanced_logs function, adding possibility to get logs from previous
boots and following the logs. Supervisor logs are an excetion where
Docker logs are still used - in case an exception is raised while
accessing the Systemd logs, they're used as fallback - otherwise we
wouldn't have an easy way to see what went wrong.
@sairon sairon force-pushed the use-advanced-logs-in-api branch from afeea5b to 8f1515c Compare April 3, 2024 07:50
@sairon sairon requested a review from mdegat01 April 3, 2024 07:51
@sairon sairon marked this pull request as ready for review April 3, 2024 07:51
Copy link
Contributor

@mdegat01 mdegat01 left a comment

Choose a reason for hiding this comment

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

Looks great 👍

Copy link
Member

@agners agners left a comment

Choose a reason for hiding this comment

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

This is changing the content type from binary to text. Are the current users (probably only frontend?) able to handle this?

Supervisor logs are an excetion where Docker logs are still used - in case an exception is raised while accessing the Systemd logs, they're used as fallback - otherwise we wouldn't have an easy way to see what went wrong.

I guess the reverse can be true to. But yeah, since we try journald logs first, it will just not be noticeable in this case.

@sairon
Copy link
Member Author

sairon commented Apr 3, 2024

This is changing the content type from binary to text. Are the current users (probably only frontend?) able to handle this?

Yes, frontend doesn't really care about the content type. Host logs used text in the previous version as well, now it's consistent for all .../logs endpoints.

I guess the reverse can be true to. But yeah, since we try journald logs first, it will just not be noticeable in this case.

I expect the journald erros to be rather persistent (until a reboot, etc.) than intermittent. And Docker logs are used only as the fallback, so if it also fails, you're done :)

@agners agners merged commit a894c45 into main Apr 4, 2024
19 checks passed
@agners agners deleted the use-advanced-logs-in-api branch April 4, 2024 10:09
@github-actions github-actions bot locked and limited conversation to collaborators Apr 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Extend Logging to allow Selecting/Limiting entries and Follow mode
3 participants