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): Combine Telemetry hook to send heap event once #766

Merged
merged 15 commits into from
Jul 19, 2024

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Jul 12, 2024

Description

Fix #730

Development notes

The test isn't quite working yet, as some test is passing when run individually but fail when I run in a batch. The change is quite big already so I want to get some review:

  • KedroTelemetryCLIHooks and KedroTelemetryProjectHooks are combined to avoid cross hook communication and make it possible to send event ONCE only by storing some intermediate states (handle entrypoint for both kedro command or just session.run()
  • Added Integration test as I think it's important to make sure the event is only sent once, mocking wouldn't work so I need a real project here. For the effort I just create a minimal kedro project. I don't think we should spend too much effort as we moved kedro-telemetry back to kedro then we can share the same starter project. It's a temporary structure as I don't think adding it to the current test_plugin.py fits as the test is more high level.
  • I created a fake telemetry ID in case something isn't working we would still capture the fake telemetry from ourselves.
[tool.kedro_telemetry]
project_id = "KEDRO_TELEMETRY_TEST"

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

noklam added 7 commits July 11, 2024 17:02
Signed-off-by: Nok Lam Chan <[email protected]>
Signed-off-by: Nok Lam Chan <[email protected]>
Signed-off-by: Nok Lam Chan <[email protected]>
Signed-off-by: Nok Lam Chan <[email protected]>
Signed-off-by: Nok Lam Chan <[email protected]>
Signed-off-by: Nok Lam Chan <[email protected]>
@noklam noklam requested review from DimedS, merelcht and ankatiyar July 12, 2024 14:04
Copy link
Member

@DimedS DimedS 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 for the PR, @noklam. Great job! I appreciate the approach to merge the two classes into one to facilitate data exchange, and the integration tests are really useful. I mostly agree with the new logic; it's excellent that we can now send only one event! I left a small comment and would like to propose removing the before_command_run() hook entirely. I believe it's not necessary, and all the logic can be placed inside the other two hooks with the same result. Is that correct?

)
self.event_properties = enriched_properties
if not self._sent:
Copy link
Member

Choose a reason for hiding this comment

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

I believe we don't need that check here. The logic should be that enriched_properties should be sent in any case. It is our responsibility to ensure the event is not sent again in the after_command_run() hook later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think you are right, since we only have two hooks after_catalog_created and after_command_run that will send event, and this is the earliest one so in reality there shouldn't be case this is set True.

@ankatiyar
Copy link
Contributor

Generally, the approach makes sense but I think it would be good to wait to switch to after_command_run till @lrcouto's analysis on the Kedro side is complete (re #709) - i.e. if the hook is executed even if there's an exception during the command execution. Otherwise we miss out on data about commands run with failures.

@DimedS
Copy link
Member

DimedS commented Jul 17, 2024

Generally, the approach makes sense but I think it would be good to wait to switch to before_command_run till @lrcouto's analysis on the Kedro side is complete (re #709) - i.e. if the hook is executed even if there's an exception during the command execution. Otherwise we miss out on data about commands run with failures.

My opinion is that it would be better to proceed with current approach, but first completely remove the before_command_run() hook for clarity. The logic will be clear: if a step includes catalog creation, enhanced data will be sent in the after_catalog_creation() hook; otherwise, a simple set of telemetry data will be sent at the last step.

I think it's acceptable to lose information about failed runs for now because we are not currently analysing it properly. I believe it makes sense to implement a special flow for failed runs later, such as collecting error types and analysing them for some insights.

@noklam
Copy link
Contributor Author

noklam commented Jul 17, 2024

@ankatiyar
The after_command_run change is slightly tricky.

There may be conflicts between the two requirements:

  1. Send event even if command fails
  2. Make sure event is not sent at the beginning and only sent it after the metadata is enriched

DimedS and others added 3 commits July 18, 2024 10:57
@DimedS DimedS changed the title Combine Telemetry hook to send heap event once feat(telemetry): Combine Telemetry hook to send heap event once Jul 18, 2024
DimedS added 2 commits July 19, 2024 10:55
Signed-off-by: Dmitry Sorokin <[email protected]>
Signed-off-by: Dmitry Sorokin <[email protected]>
Signed-off-by: Dmitry Sorokin <[email protected]>
@noklam
Copy link
Contributor Author

noklam commented Jul 19, 2024

I can't approve my own PR, but it looks good to me now :)

@DimedS
Copy link
Member

DimedS commented Jul 19, 2024

As agreed, we have merged KedroTelemetryCLIHooks and KedroTelemetryProjectHooks into KedroTelemetryHook. I refactored the code to improve clarity and reduce repetition by consolidating relevant parts into the new class. Additionally, I updated the tests to reflect this merge.

The current logic is as follows:

  1. We collect information about the CLI command and basic project details in the before_command_run hook.
  2. If the after_catalog_created hook is triggered, we add information about nodes and pipelines and then send the event.
  3. If step 2 does not occur, we send the event in the after_command_run hook.

I attempted to fix the integration tests but was unsuccessful. After discussing with @noklam, I have moved the integration tests to a separate issue and PR (#771).

Please re-review the PR.

@DimedS DimedS requested a review from merelcht July 19, 2024 13:15
@DimedS DimedS marked this pull request as ready for review July 19, 2024 13:36
Signed-off-by: Dmitry Sorokin <[email protected]>
Copy link
Contributor

@ankatiyar ankatiyar left a comment

Choose a reason for hiding this comment

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

LGTM! I think this partially resolves #709 too then!

kedro-telemetry/kedro_telemetry/plugin.py Show resolved Hide resolved
Signed-off-by: Dmitry Sorokin <[email protected]>
@DimedS DimedS merged commit 142342d into main Jul 19, 2024
10 checks passed
@DimedS DimedS deleted the noklam/kedro-telemetry-spike-to-730 branch July 19, 2024 16:05
merelcht pushed a commit to galenseilis/kedro-plugins that referenced this pull request Aug 27, 2024
…o-org#766)

---------

Signed-off-by: Nok Lam Chan <[email protected]>
Signed-off-by: Dmitry Sorokin <[email protected]>
Signed-off-by: Dmitry Sorokin <[email protected]>
Signed-off-by: Merel Theisen <[email protected]>
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: Spike to reduce redundant telemetry events
4 participants