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

Wait for the initial endpoints of a CentralDogma client for Spring integrations #691

Closed
ikhoon opened this issue May 11, 2022 · 0 comments · Fixed by #692
Closed

Wait for the initial endpoints of a CentralDogma client for Spring integrations #691

ikhoon opened this issue May 11, 2022 · 0 comments · Fixed by #692
Milestone

Comments

@ikhoon
Copy link
Contributor

ikhoon commented May 11, 2022

A CentralDogma client asynchronously fetches the initial endpoints using DynamicEndpointGroup.

HealthCheckedEndpointGroup.builder(group, HttpApiV1Constants.HEALTH_CHECK_PATH)

final DnsAddressEndpointGroupBuilder dnsAddressEndpointGroup = DnsAddressEndpointGroup

The created CentralDogma client can't get/watch stored documentation from Central Dogma replicas if the endpoints are not resolved.
If CentralDogma.whenReadyEndpoint().get(..) is not called, CentralDogma waits 3.2 seconds for endpoints to be completed.
https://github.com/line/armeria/blob/790a2db01a8514b591bde90932ab18f63693829e/core/src/main/java/com/linecorp/armeria/client/DefaultClientRequestContext.java#L320
3.2 seconds is the default connection timeout for an Armeria client.
While a server is starting, it could take longer than 3.2 seconds because the server is busy initializing the application context.

A CentralDogma bean is a managed instance provided by centraldogma-client-spring-boot-autoconfigure.
So the CentralDogma bean is created in the main thread when a Spring application context is initialized.
We can safely block the current thread with CentralDogma.whenReadyEnpoint().get(...).
For example:

class CentralDogmaSettings {
    private long initializationTimeoutMillis = 15000;
}

class CentralDogmaClientAutoConfiguration {
    @Bean
    public CentralDogma dogmaClient(...) {
        ...

        if (initializationTimeoutMillis > 0) {
            centralDogma.whenReadyEndpoint().get(initializationTimeoutMillis, ...);
        }
        return centralDogma;
    }
}
@ikhoon ikhoon added this to the 0.56.0 milestone May 11, 2022
ikhoon added a commit to ikhoon/centraldogma that referenced this issue May 11, 2022
… 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
minwoox pushed a commit that referenced this issue Jul 6, 2022
… for Spring integration. (#692)

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 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 for 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 returning a
client.

Modifications:

- Add `initializationTimeoutMillis` to `CentralDogmaSettings` so as to
  to let users configure the timeout
  - If unspecified, 15 seconds is used by default.
  - 0 disables the waiting for initialization.

Result:

- You can now configure the initialization timeout for a `CentralDogma`
  client when using Spring integration modules.
  ```yml
  centraldogma:
    hosts:
       - ...
    initialization-timeout-millis: 15000
  ```
- Fixes #691
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant