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(jans-cedarling): Load bootstrap properties from environment variables #10692

Merged
merged 28 commits into from
Jan 22, 2025

Conversation

olehbozhok
Copy link
Contributor

Prepare


Description

Implemented load BootstrapConfig from environment variables

Target issue

link

closes #10648

Implementation Details

  • Implemented load BootstrapConfig from environment variables
  • updated python bindings
  • updated flask-sidecar

Test and Document the changes

  • Static code analysis has been run locally and issues have been fixed
  • Relevant unit and integration tests have been added/updated
  • Relevant documentation has been updated if any (i.e. user guides, installation and configuration guides, technical design docs etc)

Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with docs: to indicate documentation changes or if the below checklist is not selected.

  • I confirm that there is no impact on the docs due to the code changes in this PR.

@olehbozhok olehbozhok self-assigned this Jan 18, 2025
@mo-auto mo-auto added area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs comp-jans-cedarling Touching folder /jans-cedarling kind-feature Issue or PR is a new feature request labels Jan 18, 2025
@olehbozhok olehbozhok removed area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs labels Jan 18, 2025
@olehbozhok olehbozhok changed the title feat(jans-cedarling): Load bootsrap properties from enviroment variables feat(jans-cedarling): Load bootstrap properties from environment variables Jan 18, 2025
@mo-auto mo-auto added area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs labels Jan 18, 2025
@olehbozhok olehbozhok force-pushed the jans-cedaling-issue-10648 branch from c046d85 to b2df993 Compare January 18, 2025 00:33
Copy link
Contributor

@rmarinn rmarinn left a comment

Choose a reason for hiding this comment

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

Can we add tests that load environment variables

Comment on lines 133 to 136
// OR from environment variables
let config =
BootstrapConfig::from_raw_config_and_env(None).unwrap();

Copy link
Contributor

Choose a reason for hiding this comment

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

So if None is passed, it will just used defaults... should we also provide a function where the behavior is like passing in None?

Suggested change
// OR from environment variables
let config =
BootstrapConfig::from_raw_config_and_env(None).unwrap();
// Load the bootstrap config from the environment variables. Properties that are not defined will be assigned a default value.
let config = BootstrapConfig::from_env().unwrap();
// Load the bootstrap config from the environment variables and a given config.
let config = BootstrapConfig::from_raw_config_and_env(None).unwrap();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If passed None, will be used values from env. And if some values are not present in env it does not get values from config structure.
Ok I will add additional method from_env

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 870d869

Comment on lines 468 to 471
/// Construct `BootstrapConfig` from environment variables and `BootstrapConfigRaw` config
//
// Simple implementation that map input structure to JSON map
// and map environment variables with prefix `CEDARLING_` to JSON map. And merge it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also document which config source has a higher priority here.

Copy link
Contributor Author

@olehbozhok olehbozhok Jan 20, 2025

Choose a reason for hiding this comment

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

I don't really get. But environment variables have bigger priority. The comment was updated.

Comment on lines 9 to 10
/// Helper function to convert Python-style list strings to JSON format
fn to_json(s: &str) -> Option<Value> {
Copy link
Contributor

Choose a reason for hiding this comment

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

a better name might be parse_python_list_to_json

Suggested change
/// Helper function to convert Python-style list strings to JSON format
fn to_json(s: &str) -> Option<Value> {
/// Helper function to convert Python-style list strings to JSON format
fn parse_python_list_to_json(s: &str) -> Option<Value> {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function parse string to json. And fix some kind of string to parse correctly.
I will think about better comment.
parse_python_list_to_json doesn't look appropriate..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved comments in the 99859c7

@olehbozhok olehbozhok requested a review from rmarinn January 21, 2025 22:19
rmarinn
rmarinn previously approved these changes Jan 22, 2025
@olehbozhok olehbozhok enabled auto-merge (squash) January 22, 2025 15:41
Copy link
Contributor

@SafinWasi SafinWasi left a comment

Choose a reason for hiding this comment

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

The python changes look good to me, though I am concerned about the use of environment variables for a docker image. For docker, environment variables are used like so:

docker run -e <variable1> -e <variable2> ...

This is not feasible for a massive number of environment variables that would be needed for cedarling.
In addition docker-compose.yml needs to be updated.

exit()
with open(CEDARLING_BOOTSTRAP_CONFIG_FILE, "r") as f:
CEDARLING_BOOTSTRAP_CONFIG = f.read()
logger.warning(
Copy link
Contributor

Choose a reason for hiding this comment

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

CEDARLING_BOOTSTRAP_CONFIG may be an unbound variable here. The correct way is to initialize it to a null value before the conditional.

CEDARLING_BOOTSTRAP_CONFIG = None
#...
if CEDARLING_BOOTSTRAP_CONFIG_FILE is None:

Copy link
Contributor

@SafinWasi SafinWasi left a comment

Choose a reason for hiding this comment

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

Looks good to me

@olehbozhok olehbozhok requested a review from rmarinn January 22, 2025 20:41
@olehbozhok olehbozhok merged commit d7200cb into main Jan 22, 2025
1 check passed
@olehbozhok olehbozhok deleted the jans-cedaling-issue-10648 branch January 22, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs comp-jans-cedarling Touching folder /jans-cedarling kind-feature Issue or PR is a new feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(jans-cedarling): Load bootsrap properties from enviroment variables
4 participants