-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
pinot-spi/src/main/java/org/apache/pinot/spi/env/Environment.java
Outdated
Show resolved
Hide resolved
pinot-spi/src/main/java/org/apache/pinot/spi/env/SystemEnvironment.java
Outdated
Show resolved
Hide resolved
pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
Outdated
Show resolved
Hide resolved
...ller/src/main/java/org/apache/pinot/controller/api/access/BasicAuthAccessControlFactory.java
Outdated
Show resolved
Hide resolved
pinot-minion/src/main/java/org/apache/pinot/minion/BaseMinionStarter.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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?
Please also add a section for release notes and documentation in the PR description. |
Thanks for your contribution! |
Doc added |
…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
Release Notes: Adding support for Pinot configuration through ENV variables with Dynamic mapping.
From issue: #10651
-------------------- Config from CLI or Config Path ------------------------
----------------------- final result in memory ----------------------------
Note:
No backward compatibility issues, ENV wasn't loaded until now.