apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
813 stars 271 forks source link

feat: experimental circuit breaker plugin #6140

Open samuelAndalon opened 1 month ago

samuelAndalon commented 1 month ago

Fixes #2251

Circuit breaker plugin that will return a GraphQLError with CIRCUIT_BREAKER_OPEN error extension code, if the StateMachine is in Open state, or if the call is not permitted, like being in HalfOpen state.

The plugin is configurable in different ways.

Target all subgraphs with default configuration

experimental.subgraph_circuit_breaker:
  enabled: true
 subgraphs: All

Target all subgraphs with spefific configuration

 experimental.subgraph_circuit_breaker:
  enabled: true
  configuration:
    success_rate: 0.5
    minimum_requests: 2
    success_rate_window_seconds: 10
    constant_backoff_seconds: 5
  subgraphs: All

Target all subgraphs with with default circuit_breaker_configuration and overrides

experimental.subgraph_circuit_breaker:
  enabled: true
  circuit_breaker_configuration:  # default values
    success_rate: 0.5
     minimum_requests: 2
     success_rate_window_seconds: 10
     constant_backoff_seconds: 5
subgraphs:
  AllWithOverrides:
    subgraph-a:
      success_rate: 0.8
      minimum_requests: 20
      success_rate_window_seconds: 1
      constant_backoff_seconds: 5
   # all other subgraphs will use provided configuration

Target only some subgraphs with default configuration

experimental.subgraph_circuit_breaker:
  enabled: true
  subgraphs: 
    Only:
      - subgraph-a
      - subgraph-b

Target only some subgraphs with overrides configuration

experimental.subgraph_circuit_breaker:
  enabled: true
subgraphs:
  OnlyWithOverrides:
    subgraph-a:
      success_rate: 0.8
      minimum_requests: 20
      success_rate_window_seconds: 1
      constant_backoff_seconds: 5
   # no more circuit breakers

Target all subgraphs except

experimental.subgraph_circuit_breaker:
  enabled: true
  subgraphs: 
    Except:
      - subgraph-a
      - subgraph-b

Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

Exceptions

Note any exceptions here

Notes

[^1]: It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. [^2]: Configuration is an important part of many changes. Where applicable please try to document configuration examples. [^3]: Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

svc-apollo-docs commented 1 month ago

✅ Docs Preview Ready

No new or changed pages found.

router-perf[bot] commented 1 month ago

CI performance tests

anujvishwakarma commented 1 week ago

Hi @samuelAndalon what is pending here, i was exploring the same feature for our service.

samuelAndalon commented 1 week ago

The only pending thing is a review, it might take a while, I advice you to implement this in your own space if you have a custom build of the router.