FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Log reason for service stop by ela-kotulska-frequenz · Pull Request #1245 · frequenz-floss/frequenz-sdk-python · GitHub

Repository navigation

Log reason for service stop - #1245

Open
ela-kotulska-frequenz wants to merge 1 commit into
frequenz-floss:v1.x.xfrom
ela-kotulska-frequenz:print-reason
Open

ela-kotulska-frequenz wants to merge 1 commit into
frequenz-floss:v1.x.xfrom
ela-kotulska-frequenz:print-reason

Conversation

ela-kotulska-frequenz commented Jul 14, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor

Actor has info log because this log is important to see workflow. Log is printed only if msg is not None, to avoid log duplication (actor prints that it is cancelled in run method - and this log was useful many times.)

Background service has debug log, because info would log many misleading logs during normal runtime, which might be confusing. And those logs are only useful during debugging.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 force-pushed the print-reason branch 3 times, most recently from 52c78a0 to f7efde7 Compare July 14, 2025 12:33
Args:
msg: The message to be passed to the tasks being cancelled.
"""
if msg is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

llucax Jul 17, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 previously approved these changes Jul 15, 2025
github-project-automation Bot moved this from To do to Review approved in Python SDK Roadmap Jul 15, 2025
ela-kotulska-frequenz force-pushed the print-reason branch 2 times, most recently from 0fb0b03 to 1796206 Compare July 17, 2025 08:00
ela-kotulska-frequenz changed the title Log reason for actor and backgroud service stop Log reason for service stop Jul 17, 2025

llucax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Args:
msg: The message to be passed to the tasks being cancelled.
"""
_logger.info("Service %s cancelled, reason: %s", self.name, msg)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 "")

Log `msg` argument to simplify debugging.

Signed-off-by: Elzbieta Kotulska <elzbieta.kotulska@frequenz.com>
msg: The message to be passed to the tasks being cancelled.
"""
if msg is not None:
_logger.info("Actor %s cancelled, reason: %s", self, msg)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

looks like this came back somehow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actor has info log because this log is important to see workflow. Log is printed only if msg is not None, to avoid log duplication (actor prints that it is cancelled in run method - and this log was useful many times.)

Background service has debug log, because info would log many misleading logs during normal runtime, which might be confusing. And those logs are only useful during debugging.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I wouldn't put the if, I think it might be more confusing, as one might expect seeing a log entry for all cancelled operations once you saw one in the logs, you would have to be very involved in the code to know it is only logged if there is a message.

I feel pretty strongly about this one as I think it could do real harm, so for me it is either always or never.

Then again, I would prefer not to have a special case in actor with info, but I can live with that one.

Copy link
Copy Markdown
Contributor Author

Actor has info log because this log is important to see workflow. Log is printed only if msg is not None, to avoid log duplication (actor prints that it is cancelled in run method - and this log was useful many times.)

Background service has debug log, because info would log many misleading logs during normal runtime, which might be confusing. And those logs are only useful during debugging.

llucax commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

Actor has info log because this log is important to see workflow. Log is printed only if msg is not None, to avoid log duplication (actor prints that it is cancelled in run method - and this log was useful many times.)

Can you give some examples? I'm still very doubtful of adding a conditional log (only logging if there is a message) as it could be misleading, specially during a stressful debugging session. Is it really a pattern we use that we cancel without a message when we want stop something but use a message when something else happens? I can hardly remember any case where we use a cancellation message (unless it is passed automatically by stop() for example).

This branch has not been deployed

No deployments
This file contains hidden or 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
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.

5 participants


Back | FazBrowse Home | New Git URL