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

feat(telemetry): Implement telemetry message notification #760

Merged
merged 11 commits into from
Jul 16, 2024

Conversation

DimedS
Copy link
Contributor

@DimedS DimedS commented Jul 9, 2024

Description

This PR implements a new notification that is sent only once per Kedro command execution according to issue #727.

Changes Made

  • Removed old notifications and changed the notification type from debug to info.
  • Fixed the logger from logging.getLogger(__name__) to logging.getLogger("kedro.telemetry") because the current logger did not work, and notifications from the telemetry module were not visible.
  • Implemented the new notification to be sent only once inside the before_command_run() hook, which will be executed before any Kedro command.
  • Left the message unchanged for cases when consent is not provided but changed its type from debug to info.
  • Added tests to check that the messages are logged correctly.

Checklist

  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • [] Updated the documentation to reflect the code changes
  • Added a description of this change in the relevant RELEASE.md file
  • Added tests to cover my changes

Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
@DimedS DimedS linked an issue Jul 9, 2024 that may be closed by this pull request
@DimedS DimedS marked this pull request as ready for review July 10, 2024 10:37
Copy link
Contributor

@ElenaKhaustova ElenaKhaustova left a comment

Choose a reason for hiding this comment

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

Thank you, @DimedS, LGTM!

I have one question regarding catching general exception inside before_command_run but not in after_catalog_created. Do we need it since we're catching RequestException inside _send_heap_event? Maybe we can replace it to more specific exceptions instead?

Copy link
Contributor

@noklam noklam left a comment

Choose a reason for hiding this comment

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

Fixed the logger from logging.getLogger(name) to logging.getLogger("kedro.telemetry") because the current logger did not work, and notifications from the telemetry module were not visible.

I wonder is there a better solution for this. This feels hacky as it only works because kedro's logging.yml expose the kedro logger and thus kedro.telemetry would work. Can we set the logging level at a pacakge level instead?

For example: https://github.com/Galileo-Galilei/kedro-mlflow/blob/64b8e94e1dafa02d979e7753dab9b9dfd4d7341c/kedro_mlflow/__init__.py#L7C1-L7C51

@@ -219,15 +226,10 @@ def after_context_created(self, context):

@hook_impl
def after_catalog_created(self, catalog):
# The user notification message is sent only once per command during the before_command_run hook
Copy link
Contributor

Choose a reason for hiding this comment

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

What about runs that does not go through CLI, i.e. session.run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @noklam, good point. As I understand it, in the current PR, telemetry will be sent in the after_catalog_created() hook without user notification. I propose addressing this issue here: GitHub Issue #730.

In that PR, we can modify the logic to send one heap event per user command and update user notifications accordingly:

  • If it's a CLI command and the catalog is created, send one heap event in the after_catalog_created() hook along with a user notification message.
  • If it's a CLI command and the catalog is not created, send one heap event in the before_command_run() hook along with a user notification message.
  • If it's not a CLI command and the catalog is created, send one heap event in the after_catalog_created() hook along with a user notification message.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, let's address this in #730

Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
@DimedS
Copy link
Contributor Author

DimedS commented Jul 10, 2024

Fixed the logger from logging.getLogger(name) to logging.getLogger("kedro.telemetry") because the current logger did not work, and notifications from the telemetry module were not visible.

I wonder is there a better solution for this. This feels hacky as it only works because kedro's logging.yml expose the kedro logger and thus kedro.telemetry would work. Can we set the logging level at a pacakge level instead?

For example: https://github.com/Galileo-Galilei/kedro-mlflow/blob/64b8e94e1dafa02d979e7753dab9b9dfd4d7341c/kedro_mlflow/__init__.py#L7C1-L7C51

Thanks, @noklam. I made that change. Originally I intended to inherit the logging configuration from Kedro settings. Do you think that's not a good approach?

@DimedS
Copy link
Contributor Author

DimedS commented Jul 10, 2024

Thank you, @DimedS, LGTM!

I have one question regarding catching general exception inside before_command_run but not in after_catalog_created. Do we need it since we're catching RequestException inside _send_heap_event? Maybe we can replace it to more specific exceptions instead?

Thank you for the comment, @ElenaKhaustova. I agree that the current try-except blocks might be excessive. I propose addressing this in the final step of the telemetry code refactoring, in issue #730.

@DimedS DimedS requested a review from noklam July 12, 2024 08:12
@noklam
Copy link
Contributor

noklam commented Jul 12, 2024

Thanks, @noklam. I made that change. Originally I intended to inherit the logging configuration from Kedro settings. Do you think that's not a good approach?

As logging.yml is nothing but Python's logging, I prefer stick to the convention as the logger usually name after the modue/file. This isn't too important as we migrate telemetry back to kedro, this will become an actual kedro module and it should work automatically with the current kedro logger.

DimedS and others added 2 commits July 15, 2024 11:13
@DimedS DimedS force-pushed the 727-implement-telemetry-message-notification branch 2 times, most recently from 2a69763 to 19f55ba Compare July 15, 2024 16:00
@astrojuanlu
Copy link
Member

sphinx.errors.SphinxWarning: Summarised items should not include the current module. Replace 'kedro_datasets.api.APIDataset' with 'api.APIDataset'.

Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
Copy link
Member

@astrojuanlu astrojuanlu left a comment

Choose a reason for hiding this comment

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

LGTM!

Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
@DimedS DimedS merged commit 7299bf0 into main Jul 16, 2024
20 checks passed
@DimedS DimedS deleted the 727-implement-telemetry-message-notification branch July 16, 2024 14:56
@DimedS DimedS restored the 727-implement-telemetry-message-notification branch July 18, 2024 16:21
merelcht pushed a commit to galenseilis/kedro-plugins that referenced this pull request Aug 27, 2024
)

* Implement telemetry message notification

Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>

* Fix docs build

Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>

---------

Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kedro-telemetry: Implement telemetry message notification
5 participants