line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.8k stars 912 forks source link

Provide a way to detect unhealthy connections #5763

Closed ikhoon closed 1 month ago

ikhoon commented 3 months ago

Motivation:

Currently, there is no extension point to detect errors for specific connections and terminate connections that are unhealthy.

Related: #5717 #5751

API design:

OutlierDetector is similar to CircuitBreaker, but the state is simpler, only one direction, and optimized for ephemeral resources such as connections and streams.

Example:

OutlierDetectingRule rule =
  OutlierDetectingRule
    .builder()
    .onServerError()
    .onException(IOException.class)
    .onException(WriteTimeoutException, OutlierDetectionDecision.FATAL)
    .build();

OutlierDetection outlierDetection = 
  OutlierDetection
    .builder(rule)
    .counterSlidingWindow(10_seconds)
    .counterUpdateInterval(1_seconds)
    .failureRateThreshold(0.5)
    .build();

ClientFactory
  .builder()
  // Apply the OutlierDetection to detect and close unhealthy connections
  .connectionOutlierDetection(outlierDetection)

Modifications:

Result:

github-actions[bot] commented 3 months ago

🔍 Build Scan® (commit: 76c38f1c380f4a63933784afc8c4ef28421f031b)

Job name Status Build Scan®
build-self-hosted-unsafe-jdk-8 https://ge.armeria.dev/s/a2l3qfp437e4g
build-self-hosted-unsafe-jdk-21-snapshot-blockhound https://ge.armeria.dev/s/rob6boeoowa5i
build-self-hosted-unsafe-jdk-17-min-java-17-coverage https://ge.armeria.dev/s/qb3yyvpwsxsgq
build-self-hosted-unsafe-jdk-17-min-java-11 https://ge.armeria.dev/s/r6eldo3vnos2w
build-self-hosted-unsafe-jdk-17-leak https://ge.armeria.dev/s/ds2dzip3zfckm
build-self-hosted-unsafe-jdk-11 https://ge.armeria.dev/s/wpojdg464ddu2
build-macos-12-jdk-21 https://ge.armeria.dev/s/fzw52exefj6xs
ikhoon commented 2 months ago

It seems like OutlierDetectingRule is used alongside OutlierDetector, and both are retrieved and created from this OutlierDetection. What do you think of adding OutlierDetectingRule to OutlierDetector instead?

They are used together but the role of OutlierDetector and OutlierDetectingRule is different. OutlierDetector is designed as a utility. It may be used alone. So I didn't want to force users who only need OutlierDetector to implement OutlierDetectingRule.

minwoox commented 2 months ago

OutlierDetector is designed as a utility. It may be used alone.

Haven't thought about this case. Then, I'm fine with the current design. 👍