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

Enable/Disable hook with runtime config #1935

Closed
foxale opened this issue Oct 15, 2022 · 9 comments
Closed

Enable/Disable hook with runtime config #1935

foxale opened this issue Oct 15, 2022 · 9 comments
Labels
Community Issue/PR opened by the open-source community Issue: Feature Request New feature or improvement to existing feature

Comments

@foxale
Copy link

foxale commented Oct 15, 2022

Description

It may be useful to turn off certain hooks for specific kedro runs.

Context

Let's say I have a hook, that when kedro run is invoked, automatically profiles all outputs for me and stores HTML reports somewhere in the project dir. Of course, this is time consuming and I don't want to do have this feature enabled on each run but on demand. What's the best way to turn in on and off?

Possible Implementation / Alternatives

Should I use --params and implement some switch on the hook side? Or maybe we should have a way to just decide which hooks to activate per run?

Inspired by #435

@foxale foxale added the Issue: Feature Request New feature or improvement to existing feature label Oct 15, 2022
@merelcht merelcht added the Community Issue/PR opened by the open-source community label Oct 17, 2022
@noklam
Copy link
Contributor

noklam commented Oct 17, 2022

You can disable installed hooks via settings.py via

# settings.py
# DISABLE_HOOKS_FOR_PLUGINS = ("kedro-viz",)`

Or are you specifically requesting this for the Kedro CLI?

@foxale
Copy link
Author

foxale commented Oct 17, 2022

I would want to adjust project source code only if that's a change that should be version controlled down the line (on project level), and leave all single-run-related config to Kedro CLI and yaml run configs.

@noklam
Copy link
Contributor

noklam commented Oct 17, 2022

I assume this is similar to [Allow extra hooks to be passed via the Kedro CLI, update the title slightly.

Quick question:
Since we follow a pytest opt-out model, plugin hooks are installed automatically. Do you need to disable a hook at runtime? This may work by using some kind of environment variable in the hook implementation?

@noklam noklam changed the title Turning hooks on and off Enable/Disable hook with runtime config Oct 17, 2022
@foxale
Copy link
Author

foxale commented Oct 17, 2022

Correct. The best combo though, would be a CLI parameter + env variable. In the ideal world that would work like so:

kedro run --with-profiling

where --with-profiling would be passed to my custom ProfilingHook() class indicating user preference.

@noklam
Copy link
Contributor

noklam commented Oct 18, 2022

Added some relevant notes from Discord today.

ToniMaroni — Today at 8:57 AM
Hi, is there a way to have the configurations in settings.py configurable based on the kedro environment. For example, I want the hooks for kedro-viz and kedro-neptune disabled in production environment. Thanks
datajoely — Today at 8:59 AM
Interesting usecase - best solution off the top of my head is to use the KEDRO_ENV environment variable and just include an if statement in settings.py
ToniMaroni — Today at 9:00 AM
I was also thinking of a using an ENV var, glad to hear that there is one already defined for the KEDRO_ENV! Thanks
datajoely — Today at 9:01 AM
The other option, which is probably preferable, is to do the logic in the hooks themselves which do have the env name as a parameter
This isn't possible if you're using 3rd party hooks

@noklam
Copy link
Contributor

noklam commented Oct 18, 2022

Correct. The best combo though, would be a CLI parameter + env variable. In the ideal world that would work like so:

kedro run --with-profiling

where --with-profiling would be passed to my custom ProfilingHook() class indicating user preference.

@foxale I think supporting arbitrary CLI arguments in the official Kedro CLI is unlikely.

To achieve that, you can actually override Kedro CLI in your project easily. The cli.py is actually part of Kedro Project Template in the older version - but we remove it since most people don't need to customize it.

I think you can achieve this by doing the following

  1. Override the CLI with cli.py , add your new CLI arguments
  2. Inject the argument as an environment variable
  3. In your hooks/plugin - it should read this environment variable and behave accordingly.

See an example here:
https://github.com/noklam/kedro_gallery/blob/master/kedro_cli_extension/src/kedro_cli_extension/cli.py

@foxale
Copy link
Author

foxale commented Oct 18, 2022

Awesome. And my assumption is you can implement such changes to CLI via kedro plugins as well?

@merelcht merelcht added the Stage: Technical Design 🎨 Ticket needs to undergo technical design before implementation label Nov 14, 2022
@merelcht
Copy link
Member

@foxale You could also point DISABLE_HOOKS_FOR_PLUGINS in settings.py to read from an environment variable.

@merelcht merelcht removed the Stage: Technical Design 🎨 Ticket needs to undergo technical design before implementation label Dec 12, 2022
@merelcht
Copy link
Member

merelcht commented Jan 3, 2023

I'm closing this issue since there hasn't been any recent activity. Feel free to re-open this if you're still facing problems!

@merelcht merelcht closed this as completed Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Issue/PR opened by the open-source community Issue: Feature Request New feature or improvement to existing feature
Projects
None yet
Development

No branches or pull requests

3 participants