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

reload properties of remotely activated profile fixes gh-1834 #1835

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator

private ConfigClientProperties defaultProperties;

private final String ACTIVE_PROFILES_PROPERTY_NAME = "spring.profiles.active";

public ConfigServicePropertySourceLocator(ConfigClientProperties defaultProperties) {
this.defaultProperties = defaultProperties;
}

@Override
@Retryable(interceptor = "configServerRetryInterceptor")
Copy link
Member

Choose a reason for hiding this comment

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

I think it needs to stay here for some rare backwards compatibility issues since the call to locate(properties) wouldn't be retryable.

public org.springframework.core.env.PropertySource<?> locate(org.springframework.core.env.Environment environment) {
ConfigClientProperties properties = this.defaultProperties.override(environment);
return locate(properties);
}

@Retryable(interceptor = "configServerRetryInterceptor")
public org.springframework.core.env.PropertySource<?> locate(ConfigClientProperties properties) {
Copy link
Member

Choose a reason for hiding this comment

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

Is the only usage of this the method above?

CompositePropertySource composite = new OriginTrackedCompositePropertySource("configService");
ConfigClientRequestTemplateFactory requestTemplateFactory = new ConfigClientRequestTemplateFactory(logger,
properties);
Expand All @@ -101,6 +107,17 @@ public org.springframework.core.env.PropertySource<?> locate(org.springframework
@SuppressWarnings("unchecked")
Map<String, Object> map = translateOrigins(source.getName(),
(Map<String, Object>) source.getSource());

// if different profile is activated within the default
// profile
boolean relocate = checkIfProfileIsActivatedInDefault(result.getProfiles(), map);
if (relocate) {
OriginTrackedValue newProfiles = (OriginTrackedValue) map
.get(ACTIVE_PROFILES_PROPERTY_NAME);
properties.setProfile(newProfiles.getValue().toString());
return this.locate(properties); // relocate again
}

composite.addPropertySource(new OriginTrackedMapPropertySource(source.getName(), map));
}
}
Expand Down Expand Up @@ -138,6 +155,15 @@ public org.springframework.core.env.PropertySource<?> locate(org.springframework

}

// to check if different profile is activated within the default profile
private boolean checkIfProfileIsActivatedInDefault(String[] profiles, Map<String, Object> map) {
List<String> profilesList = Arrays.asList(profiles);
return (profilesList.size() == 1 && profilesList.get(0).equalsIgnoreCase("default")
Copy link
Contributor

Choose a reason for hiding this comment

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

@spencergibb do you recall why this would only need to be done for the default profile? What if the default profile contains spring.profiles.active and then subsequent configuration properties which get activated based on that profile also contain spring.profiles.activate? In that case we would not also activate those profiles.

&& map.containsKey(ACTIVE_PROFILES_PROPERTY_NAME)
&& !(((OriginTrackedValue) map.get(ACTIVE_PROFILES_PROPERTY_NAME))).getValue().toString()
.equalsIgnoreCase("default"));
}

@Override
@Retryable(interceptor = "configServerRetryInterceptor")
public Collection<org.springframework.core.env.PropertySource<?>> locateCollection(
Expand Down