-
-
Notifications
You must be signed in to change notification settings - Fork 10.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
Dynamic environment for apollo-portal #2867
Dynamic environment for apollo-portal #2867
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2867 +/- ##
=========================================
Coverage 51.05% 51.05%
Complexity 2197 2197
=========================================
Files 429 429
Lines 13235 13235
Branches 1360 1360
=========================================
Hits 6757 6757
Misses 6005 6005
Partials 473 473
Continue to review full report at Codecov.
|
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 feature looks great! I think this will greatly reduce the complexitiy to add a customized environment.
.../main/java/com/ctrip/framework/apollo/portal/environment/PortalLegacyMetaServerProvider.java
Outdated
Show resolved
Hide resolved
...rtal/src/main/java/com/ctrip/framework/apollo/portal/environment/PortalMetaDomainConsts.java
Outdated
Show resolved
Hide resolved
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java
Outdated
Show resolved
Hide resolved
.../main/java/com/ctrip/framework/apollo/portal/environment/PortalLegacyMetaServerProvider.java
Outdated
Show resolved
Hide resolved
...rtal/src/main/java/com/ctrip/framework/apollo/portal/environment/PortalMetaDomainConsts.java
Outdated
Show resolved
Hide resolved
…llo-portal. Initialize it without lazy.
for (String env : envArray) { | ||
if (Strings.isNullOrEmpty(env)) { | ||
continue; | ||
} else { |
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.
I think this else {
statement is unnecessary?
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.
From the git history. The code is merged from other branch.
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.
the else {
statement was removed in pr #2864 , so I guess it was brought back to this branch when you resolved the merging conflicts.
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.
Change back already.
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.
Is the whole file rolled back? I think we still need to change the import statement import com.ctrip.framework.apollo.portal.environment.Env;
?
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.
I've changed it by accident. A new commit has pushed.
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.
There is also some conflict with master branch, please help to solve it, thx.
.../main/java/com/ctrip/framework/apollo/portal/environment/PortalLegacyMetaServerProvider.java
Outdated
Show resolved
Hide resolved
.../main/java/com/ctrip/framework/apollo/portal/environment/PortalLegacyMetaServerProvider.java
Outdated
Show resolved
Hide resolved
* @see com.ctrip.framework.apollo.core.MetaDomainConsts | ||
* @author wxq | ||
*/ | ||
public class PortalMetaDomainConsts { |
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.
Please add unit test for PortalMetaDomainConsts
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.
In apollo-core
, there is a test for MetaDomain
, i.e com.ctrip.framework.apollo.core.MetaDomainTest
. It seems that implements com.ctrip.framework.apollo.BaseIntegrationTest
, and start a internal server to test.
If i want to write the unit test of com.ctrip.framework.apollo.portal.environment.PortalMetaDomainConsts
, should i use the same way?
A little Challenge to do this. (hard)
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.
I think we need to do it and it looks like you have done that part
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.
The unit test is done.
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.
Most code is copied from apollo-core
…-apollo-core' into dynamic-portal-env-nochange-with-apollo-core
metaServerAddressesFromSystemProperty = KeyValueUtils.removeKeySuffix(metaServerAddressesFromSystemProperty, "_meta".length()); | ||
|
||
// find key-value from OS environment variable which key ends with "_meta" | ||
Map<String, String> metaServerAddressesFromOSEnvironment = KeyValueUtils.filterWithKeyEndswith(System.getenv(), "_meta"); |
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.
OS Environment variables are normally in UPPER CASE, so it might be better to check with _META
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.
I've change the rule of match suffix to case insensitive.
metaServerAddressesFromOSEnvironment = KeyValueUtils.removeKeySuffix(metaServerAddressesFromOSEnvironment, "_meta".length()); | ||
|
||
// find key-value from properties file which key ends with ".meta" | ||
Properties properties = new Properties(); |
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.
I think it might be better to also support setting meta server address from PortalDB.ServerConfig, which is the same place to store apollo.portal.envs
and is therefore more intuitive, e.g. user can set env and env meta server address in System Configuration
page. How do you think?
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.
You mean the meta server addresses are save in apollo.portal.envs
which type is a map
?
the config like follow:
apollo:
portal:
envs:
dev: http://ip:port
other: http://ip:port
self-define: http://ip:port
And in PortalDB.ServerConfig
's apollo.portal.envs
, there is a json object
{
"dev"" : "http://ip:port"
"other" : "http://ip:port"
"self-define" : "http://ip:port"
}
So then portal conbine those config to get the meta server addresses?
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.
I think this feature (add environment in portal when running) will consume more code to implement.
How about when this feature (add environment in portal when start up) finished, next plan to do it?
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.
I think we can keep it as add environment in portal when start up
, but we support configuring it via System Configuration
page, e.g. we add a new configuration item like apollo.portal.meta.servers
to store the mapping between env and meta server address.
We will still keep the apollo.portal.envs
as it indicates the active environments so that there may be 3 environment mappings in apollo.portal.meta.servers
but only 2 active envs in apollo.portal.envs
.
If this involves much more effort, then it's okay to leave it when we support add environment in portal when running
.
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.
Get it.
It involves the Database operations. Add new key apollo.portal.meta.servers
, and refresh it in runtime.
I feel that the database operation is a bit difficult.
I don't know how to add this feature now.
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.
LGTM for now
What's the purpose of this PR
Add a feature, make portal support self-define environment without change 1 line code.
Only config will be changed.
Brief changelog
Dynamic environment setting when portal service start.
A new way to forbidden changing hard code to add new environment.
Just change 2 configuration properties.
Suppose that you want to add a new environment beta, and you have been add dev, just do like follow step.
apollo.portal.envs
.Just change its value todev,beta
in db or add VM option-Dapollo.portal.envs=dev,beta
beta.meta=your-meta-address
or add VM option-Dbeta_meta=your-meta-address
There are 4 fake classes added under package
com.ctrip.framework.apollo.portal.environment
,the purpose is using them to replace the classes in
apollo-core
.But only 1 fake class exists testing, the rest 3 classes lack the unit testing.
Could I cancel the function
3rd party MetaServerProvider could be injected by typical Java Service Loader pattern.
incom.ctrip.framework.apollo.portal.environment.PortalMetaDomainConsts
, and make its loading to be not lazy ?Follow this checklist to help us incorporate your contribution quickly and easily:
mvn clean test
to make sure this pull request doesn't break anything.