-
Notifications
You must be signed in to change notification settings - Fork 122
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
Allow configuring the initialization timeout of CentralDogma
client for Spring integration.
#692
Conversation
… for Spring integration. Motivation: 3.2 seconds is used for the default timeout if a endpoint is not determined while executing a request. While a server is starting up, a resolution of endpoints may take longer than 3.2 seconds because the server could be busy initializing the application context. To solve the problem, `CentralDogma.whenEndpointReady()` was introduced to wait for the initial endpoints before starting a request. However, users found it easy to forget to call the API and use directly a `CentralDogma` client without waiting it. It is difficult to call `whenEndpointReady().get()` because it is to block the current thread. But a `CentralDogma` bean is a managed instance created in the main thread when a Spring application context is initialized. So we can safely call `CentralDogma.whenEndpointReady().get()` before returing a client. Modifications: - Add `initializationTimeoutMillis` to `CentralDogmaSettings` so as to to let users configure the timeout - If unspecifed, 15 seconds is used by default. - 0 disables the waiting for initialization. Result: - You can not configure the initialization timeout for a `CentralDogma` client when using Spring integration module. ```yml centraldogma: hosts: - ... initialization-timeout-millis: 15000 ``` - Fixes line#691
...c/main/java/com/linecorp/centraldogma/client/spring/CentralDogmaClientAutoConfiguration.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #692 +/- ##
============================================
- Coverage 70.19% 70.15% -0.05%
+ Complexity 3419 3416 -3
============================================
Files 349 349
Lines 13468 13482 +14
Branches 1454 1456 +2
============================================
+ Hits 9454 9458 +4
- Misses 3133 3139 +6
- Partials 881 885 +4
Continue to review full report at Codecov.
|
…rp/centraldogma/client/spring/CentralDogmaClientAutoConfiguration.java Co-authored-by: Klemen Košir <klemen.kosir@kream.io>
…ma into initialization-timeout
|
||
// TODO(ikhoon): Randomize the port number to avoid flakiness. | ||
private static final Lock lock = new ReentrantLock(); | ||
private static final int TEST_SERVER_PORT = 56463; |
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.
Why do we need this fixed port?
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.
Because CentralDogma
client bean needs a pre-known hostname (host:port
) to access a server.
https://github.com/line/centraldogma/pull/692/files#diff-4264d927674e9eb11e891891fce0d0305d917df8904caff14930b7df456b2a7f
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.
Ah, thanks for the explanation.
I'm a bit worried about the flakiness but we can fix it later if this causes 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.
Thanks, @ikhoon!
|
||
// TODO(ikhoon): Randomize the port number to avoid flakiness. | ||
private static final Lock lock = new ReentrantLock(); | ||
private static final int TEST_SERVER_PORT = 56463; |
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.
Ah, thanks for the explanation.
I'm a bit worried about the flakiness but we can fix it later if this causes 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.
Overall looks good! Left a minor question 🙇
* @return {@code null} if not specified. | ||
*/ | ||
@Nullable | ||
public Long initializationTimeoutMillis() { |
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.
Not strong on this, but initialization sounds a little general (vs. endpointReadyTimeoutMillis
or endpointInitializationTimeoutMillis
)
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.
Because 1) I didn't want to expose the implementation detail and 2) we might add another logic later to warm up CentralDogma
somehow.
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 👍 Makes sense
...test/java/com/linecorp/centraldogma/client/spring/CentralDogmaInitializationTimeoutTest.java
Show resolved
Hide resolved
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 @ikhoon 👍 🙇 👍
Thanks! |
Motivation:
3.2 seconds is used for the default timeout if an endpoint is not
determined while executing a request.
While a server is starting up, a resolution of endpoints may take
longer than 3.2 seconds because the server could be busy initializing
the application context.
To solve the problem,
CentralDogma.whenEndpointReady()
was introducedto wait for the initial endpoints before starting a request.
However, users found it easy to forget to call the API and use directly a
CentralDogma
client without waiting for it. It is difficult to callwhenEndpointReady().get()
because it is to block the current thread.But a
CentralDogma
bean is a managed instance created in the mainthread when a Spring application context is initialized. So we can
safely call
CentralDogma.whenEndpointReady().get()
before returning aclient.
Modifications:
initializationTimeoutMillis
toCentralDogmaSettings
so as toto let users configure the timeout
Result:
CentralDogma
client when using Spring integration modules.
CentralDogma
client for Spring integrations #691