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

Adding support for configuration through environment variables #12307

Merged
merged 15 commits into from
Feb 8, 2024

Conversation

t0mpere
Copy link
Contributor

@t0mpere t0mpere commented Jan 22, 2024

Release Notes: Adding support for Pinot configuration through ENV variables with Dynamic mapping.

From issue: #10651

export PINOT_CONTROLLER_HOST=host
export PINOT_SERVER_PROPERTY_WHATEVER=whatever_property
export ANOTHER_VARIABLE=random

-------------------- Config from CLI or Config Path ------------------------

dynamic.env.config=pinot.controller.host,pinot.server.property,other.var
pinot.controller.host=PINOT_CONTROLLER_HOST
pinot.server.property=PINOT_SERVER_PROPERTY_WHATEVER
other.var=ANOTHER_VARIABLE

----------------------- final result in memory ----------------------------

dynamic.env.config=pinot.controller.host,pinot.server.property,other.var
pinot.controller.host=host
pinot.server.property=whatever_property
other.var=random

Note:
No backward compatibility issues, ENV wasn't loaded until now.

@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (21f3d28) 61.59% compared to head (c87042d) 61.74%.
Report is 55 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #12307      +/-   ##
============================================
+ Coverage     61.59%   61.74%   +0.14%     
+ Complexity     1153      207     -946     
============================================
  Files          2417     2426       +9     
  Lines        131379   132781    +1402     
  Branches      20266    20541     +275     
============================================
+ Hits          80919    81980    +1061     
- Misses        44556    44780     +224     
- Partials       5904     6021     +117     
Flag Coverage Δ
custom-integration1 <0.01% <0.00%> (-0.01%) ⬇️
integration <0.01% <0.00%> (-0.01%) ⬇️
integration1 <0.01% <0.00%> (-0.01%) ⬇️
integration2 0.00% <0.00%> (ø)
java-11 61.68% <100.00%> (+0.13%) ⬆️
java-21 61.62% <100.00%> (+0.16%) ⬆️
skip-bytebuffers-false 61.73% <100.00%> (+0.15%) ⬆️
skip-bytebuffers-true 61.56% <100.00%> (+0.13%) ⬆️
temurin 61.74% <100.00%> (+0.14%) ⬆️
unittests 61.73% <100.00%> (+0.14%) ⬆️
unittests1 46.87% <100.00%> (+0.29%) ⬆️
unittests2 27.75% <0.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}

private static Map<String, String> relaxEnvironmentVariables(Map<String, String> environmentVariables) {
return environmentVariables.entrySet().stream().filter(entry -> entry.getKey().startsWith("PINOT_"))
return environmentVariables.entrySet().stream().filter(entry -> entry.getKey().startsWith(ENV_PREFIX))
Copy link
Contributor

@xiangfu0 xiangfu0 Jan 22, 2024

Choose a reason for hiding this comment

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

This will break all existing changes right? Are env var like PINOT_SERVER_xxxx loaded to pinot.server.xxx?

I would suggest to keep current code rename it to legacy, so current user won't fail for using PINOT_ prefix.

Then add new code to override based on the new prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment (before and after my changes) <PREFIX>_SERVER_xxx is mapped to server.xxx. I've just changed the prefix to avoid confusion since pinot.server.property will be loaded from PINOT_PINOT_SERVER_PROPERTY. Considering that env wasn't loaded until now I think there's no worries about backward compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moreover I think it would be quite hard to enforce an identical prefix to all properties. I'm for having a custom self-explanatory prefix like PINOT_ENV_. But I'm open to better ideas.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the backward compatible perspective, I think the issue here is that for whoever currently using PINOT_CONTROLLER_HOST will see the unexpected behavior the override won't happen.

Suggest to rename existing relaxEnvVarName to legacyRelaxEnvVarName, and have your new relaxEnvVarName to override.

E.g. existing code:
PINOT_CONTROLLER_HOST should be added as controller.host;
PINOT_PINOT_CONTROLLER_HOST should be added as pinot.controller.host;

PINOT_ENV_SERVER_XXX should be added as server.xxx;
PINOT_ENV_PINOT_SERVER_XXX should be added as pinot.server.xxx;

From the ease of use perspective, actually I would love to have the direct mapping from env variable to configs, e.g.
pinot.server.xxx should be override by PINOT_SERVER_XXX.
But due to some legacy issue that not all configs are start with pinot. that's why we introduce this PINOT_ prefix.

IMO, I would love to map env var PINOT_XXX_YYY to both xxx.yyy and pinot.xxx.yyy.

So that we can cover both.

Just for xxx.yyy may override existing configs but pinot.xxx.yyy will be added if not existed.

cc: @Jackie-Jiang @snleee @siddharthteotia @chenboat would love your best practice of config override.

Copy link
Contributor Author

@t0mpere t0mpere Jan 24, 2024

Choose a reason for hiding this comment

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

Implemented 1.
I'm worried that by doing 2. we could incur in conflicts with existing env vars. Prefix avoids this issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After catching up, number two was implemented following:

export PINOT_CONTROLLER_HOST=host
export PINOT_SERVER_PROPERTY_WHATEVER=whatever_property
export ANOTHER_VARIABLE=random

-------------------- Config from CLI or Config Path ------------------------

dynamic.env.config=pinot.controller.host,pinot.server.property,other.var
pinot.controller.host=PINOT_CONTROLLER_HOST
pinot.server.property=PINOT_SERVER_PROPERTY_WHATEVER
other.var=ANOTHER_VARIABLE

---------------------------------------------------------------------------

config gets templated at runtime with the content of the env vars.

----------------------- final result in memory ----------------------------

dynamic.env.config=pinot.controller.host,pinot.server.property,other.var
pinot.controller.host=host
pinot.server.property=whatever_property
other.var=random

@t0mpere t0mpere requested a review from xiangfu0 January 24, 2024 16:38
walterddr
walterddr previously approved these changes Jan 31, 2024
Copy link
Contributor

@walterddr walterddr 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. could you add more backward compatibility testing?

@walterddr walterddr dismissed their stale review January 31, 2024 20:46

accidental click on approval

@xiangfu0 xiangfu0 added Configuration Config changes (addition/deletion/change in behavior) documentation labels Feb 6, 2024
@xiangfu0
Copy link
Contributor

xiangfu0 commented Feb 6, 2024

Please also add a section for release notes and documentation in the PR description.

@xiangfu0
Copy link
Contributor

xiangfu0 commented Feb 6, 2024

Thanks for your contribution!

@xiangfu0 xiangfu0 added the release-notes Referenced by PRs that need attention when compiling the next release notes label Feb 6, 2024
@t0mpere
Copy link
Contributor Author

t0mpere commented Feb 7, 2024

Doc added

@xiangfu0 xiangfu0 merged commit 7c9bf8c into apache:master Feb 8, 2024
19 checks passed
suyashpatel98 pushed a commit to suyashpatel98/pinot that referenced this pull request Feb 28, 2024
…e#12307)

* init

* Added support for env vars

* Revert removal of SystemEnvironment and Environment classes

* Fix tests

* Fix formatting

* Revert unnecessary changes

* Revert unnecessary changes

* Formatting

* Comments

* Tests fix

* Added back legacy prefix

* Fix test

* Implementing dynamic templating for env config

* Fix typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Configuration Config changes (addition/deletion/change in behavior) documentation release-notes Referenced by PRs that need attention when compiling the next release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants