Skip to content

Log reason for service stop #1245

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

Open
wants to merge 1 commit into
base: v1.x.x
Choose a base branch
from

Conversation

ela-kotulska-frequenz
Copy link
Contributor

@ela-kotulska-frequenz ela-kotulska-frequenz commented Jul 14, 2025

To simplify debugging

@ela-kotulska-frequenz ela-kotulska-frequenz self-assigned this Jul 14, 2025
@Copilot Copilot AI review requested due to automatic review settings July 14, 2025 10:21
@ela-kotulska-frequenz ela-kotulska-frequenz requested a review from a team as a code owner July 14, 2025 10:21
@ela-kotulska-frequenz ela-kotulska-frequenz added the part:actor Affects an actor ot the actors utilities (decorator, etc.) label Jul 14, 2025
@ela-kotulska-frequenz ela-kotulska-frequenz added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Jul 14, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds logging of cancellation reasons for both the background service and actor components.

  • Adds a module-level logger and debug log in _background_service.py
  • Adds an info-level log in _actor.py when an actor is cancelled

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/frequenz/sdk/actor/_background_service.py Imported logging, initialized _logger, and added a debug log call in cancel()
src/frequenz/sdk/actor/_actor.py Added an info log call in cancel(), but missing logger import/definition
Comments suppressed due to low confidence (3)

src/frequenz/sdk/actor/_background_service.py:174

  • This new debug logging for cancellation isn't covered by existing tests. Consider adding unit tests to verify that the cancellation reason is logged correctly.
        _logger.debug("Service %s cancelled, reason: %s", self.name, msg)

src/frequenz/sdk/actor/_actor.py:147

  • Add tests to ensure the actor's cancellation reason is logged at info level, matching the new behavior introduced here.
        _logger.info("Actor %s cancelled, reason: %s", self.name, msg)

src/frequenz/sdk/actor/_actor.py:147

  • The _logger is used here but not defined or imported. Please add import logging and initialize _logger = logging.getLogger(__name__) at the top of this file.
        _logger.info("Actor %s cancelled, reason: %s", self.name, msg)

@ela-kotulska-frequenz ela-kotulska-frequenz force-pushed the print-reason branch 3 times, most recently from 52c78a0 to f7efde7 Compare July 14, 2025 12:33
@@ -153,5 +153,7 @@ def cancel(self, msg: str | None = None) -> None:
Args:
msg: The message to be passed to the tasks being cancelled.
"""
if msg is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this calling the super method and then its logged twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Actor has info log.
In Backgroud has debug log.

Having info log in BackgroundService will create lots of unnecessary logs (that we probably don't need).

Do you have different idea?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, well in this case it seems fine then. Didn't notice the different levels

Copy link
Contributor

Choose a reason for hiding this comment

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

Cancel sounds like a rare event, and it's useful to know. INFO doesn't trigger any alerts. It wouldn't be too bad if we just had INFO in the background service.

Copy link
Contributor

@llucax llucax Jul 17, 2025

Choose a reason for hiding this comment

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

Oh, I didn't see this comment. For me this still sounds like a debug, because I guess it is only useful when debugging, when things are working you should see an INFO for the actor stopping, and that should be enough. That said, I'm OK to merge if there is enough consensus.

Marenz
Marenz previously approved these changes Jul 15, 2025
Log `msg` argument to simplify debugging.

Signed-off-by: Elzbieta Kotulska <[email protected]>
@ela-kotulska-frequenz ela-kotulska-frequenz changed the title Log reason for actor and backgroud service stop Log reason for service stop Jul 17, 2025
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

I'm not sure if this should be info or debug also, it seems like it might be too fine grained detail for a normal run, as we are already logging when it actually stops, so cancel would only be interesting if there is a bug and the cancel is not resulting in a stop.

@@ -167,6 +170,8 @@ def cancel(self, msg: str | None = None) -> None:
Args:
msg: The message to be passed to the tasks being cancelled.
"""
_logger.info("Service %s cancelled, reason: %s", self.name, msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be a bit easier to the eyes like this?

Suggested change
_logger.info("Service %s cancelled, reason: %s", self.name, msg)
_logger.info("Service %s cancelled%s", self.name, msg, f": {msg}" if msg is not None else "")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd:skip-release-notes It is not necessary to update release notes for this PR part:actor Affects an actor ot the actors utilities (decorator, etc.)
Projects
Status: Review approved
Development

Successfully merging this pull request may close these issues.

4 participants