-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Control Apache HttpComponents' protocol upgrades w/ a property #4399
base: 4.2.x
Are you sure you want to change the base?
Control Apache HttpComponents' protocol upgrades w/ a property #4399
Conversation
8263e69
to
e9faf7f
Compare
@Test | ||
void TODO_shouldOverrideProtocolUpgrades() { | ||
TestPropertyValues.of("eureka.client.http-components.enable-protocol-upgrades=false").applyTo(context); | ||
context.register(TestEmptyRequestCustomizerConfiguration.class); | ||
setupContext(RefreshAutoConfiguration.class, AutoServiceRegistrationConfiguration.class); | ||
|
||
assertThat(context.getBeansOfType(EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer.class)) | ||
.hasSize(1); | ||
EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer testRequestCustomizer = context | ||
.getBean(EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer.class); | ||
|
||
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setProtocolUpgradeEnabled(true); | ||
testRequestCustomizer.customize(requestConfigBuilder); | ||
assertThat(requestConfigBuilder.build().isProtocolUpgradeEnabled()).isFalse(); | ||
} | ||
|
||
@Configuration | ||
protected static class TestEmptyRequestCustomizerConfiguration { | ||
|
||
@Bean | ||
EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer emptyRequestCustomizer() { | ||
return builder -> {}; | ||
} | ||
|
||
} |
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.
[thought]:
As suggested by you, @OlgaMaciaszek, in #4396 (comment) user-provided request customizers override HTTP components configuration by way of @ConditionalOnMissingBean
.
(for simplicity I am referring to EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer
as plain ærequest customizer")
Assuming if I have understood your remarks correctly, then I see the following issues. When user-provided request customizers override HTTP components configuration, ...
-
Then any request customizer - regardless of whether it controls protocol upgrades or not - will override
eureka.client.http-components.enable-protocol-upgrades
. That's because request customizers are opaque. We can't easily tell what they customize. The testTODO_shouldOverrideProtocolUpgrades
demonstrates the issue with an empty request customizer which overrides. -
Then it seems as if it's breaking the priority order respective externalized configuration. Conventionally, I would expect a configuration property to have the last word, not a bean. Arguably, at a lower level the two become beans all the same. But I find it unintuitive. It is making the mental model more involved, doesn't it? Furthermore, if there are users who have - knowingly or not - have a request customizer, then they may set
eureka.client.http-components.enable-protocol-upgrades
and wonder why its not working as expected.
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 see your point. Actually, given that it's a customizer type bean, we may want to change it so that we expect >= 1 customiser beans, then we'd add ours, but also pick the user's beans, and we should ensure ours have lower order of precedence than the user-created ones (so possibly should be applied first and then overwritten by user changes where appropriate); wdyt? CC @spencergibb
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 have consulted with @spencergibb and he's approved the ordered list approach.
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.
Thanks @mamachanko. Have added some comments.
...-client/src/main/java/org/springframework/cloud/netflix/eureka/HttpComponentsProperties.java
Outdated
Show resolved
Hide resolved
...-client/src/main/java/org/springframework/cloud/netflix/eureka/HttpComponentsProperties.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
void TODO_shouldOverrideProtocolUpgrades() { |
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 remove TODO
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.
@OlgaMaciaszek I'd like to keep it until we resolve https://github.com/spring-cloud/spring-cloud-netflix/pull/4399/files#r1937493242, because it's exemplifying the problem.
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.
Sure, the review is done with the final version in thought.
...c/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java
Outdated
Show resolved
Hide resolved
@Test | ||
void TODO_shouldOverrideProtocolUpgrades() { | ||
TestPropertyValues.of("eureka.client.http-components.enable-protocol-upgrades=false").applyTo(context); | ||
context.register(TestEmptyRequestCustomizerConfiguration.class); | ||
setupContext(RefreshAutoConfiguration.class, AutoServiceRegistrationConfiguration.class); | ||
|
||
assertThat(context.getBeansOfType(EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer.class)) | ||
.hasSize(1); | ||
EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer testRequestCustomizer = context | ||
.getBean(EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer.class); | ||
|
||
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setProtocolUpgradeEnabled(true); | ||
testRequestCustomizer.customize(requestConfigBuilder); | ||
assertThat(requestConfigBuilder.build().isProtocolUpgradeEnabled()).isFalse(); | ||
} | ||
|
||
@Configuration | ||
protected static class TestEmptyRequestCustomizerConfiguration { | ||
|
||
@Bean | ||
EurekaClientHttpRequestFactorySupplier.RequestConfigCustomizer emptyRequestCustomizer() { | ||
return builder -> {}; | ||
} | ||
|
||
} |
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 see your point. Actually, given that it's a customizer type bean, we may want to change it so that we expect >= 1 customiser beans, then we'd add ours, but also pick the user's beans, and we should ensure ours have lower order of precedence than the user-created ones (so possibly should be applied first and then overwritten by user changes where appropriate); wdyt? CC @spencergibb
e9faf7f
to
b4e392e
Compare
Signed-off-by: Max Brauer <[email protected]>
Signed-off-by: Max Brauer <[email protected]>
b4e392e
to
f650158
Compare
Provides a configuration property
to make #4391 even easier building on top of #4394