[improve][fn] support reading config options from file in Function Python Runner #18669
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #18533
Master Issue: #18533
Motivation
The Pulsar functions have the ability to provide the number of instances of the called function (see, for example, "Get num instances" ), but the data that this function currently relies on needs to be passed in via command line arguments and cannot be easily changed dynamically. Therefore we need to provide a more dynamic way of accessing data (mainly FunctionDetails) for functions, and this way can also serve to pass the function's other parameters.
This mechanism is aimed at allowing the function to dynamically fetch the required parameters and data without having to restart the function in order to load the latest parameters or data.
A more appropriate approach is to provide the function with a local config file where the data and parameters are stored. The provider of the data and parameters (usually the initiator of the function, e.g. function-worker) writes the contents of the parameters and the data (FunctionDetails) to a fixed local config file, and passes the path of this config file to the function.
The function determines the value of
--config-file
and determines if the target config file exists, and parses its contents if it does.The rules for applying parameters or data to the function are as follows.
Modifications
enable_live_update
, default is False, which means that python-function will listen for changes to the configuration file and update the configuration of the running function instance when it has listened for an eventconfig_file
, default is None, which means you need to get the configuration content fromconfig_file
args.config_file
andargs.enable_live_update
are enabled, add a new thread and use thewatchdog
library to listen toargs.config_file
and update the relevant configuration after listening to theon_modified
eventVerifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: