apollographql / router

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

Configuration param to disable Redis cache for APQ and Query Planning #3506

Open nathanmarcos opened 1 year ago

nathanmarcos commented 1 year ago

Is your feature request related to a problem? Please describe. The Redis cache for APQ and Query Planning are enterprise features and require a "service" Apollo key to operate. We use the exact same router.yaml file for all environments and we change the configuration via env vars. On our local env we run the application without an Apollo key since we load the supergraph from a file, but the application doesn't boot up due to the following error:

2023-07-27T11:14:33.516769Z  ERROR Not connected to GraphOS. In order to enable these features for a self-hosted instance of Apollo Router, the Router must be connected to a graph in GraphOS (using APOLLO_KEY and APOLLO_GRAPH_REF) that provides a license for the following features:

Configuration yaml:
* Query plan caching
  .supergraph.query_planning.experimental_cache.redis

* APQ caching
  .apq.router.cache.redis

See https://go.apollo.dev/o/elp for more information.
2023-07-27T11:14:33.518709Z  INFO stopped
2023-07-27T11:14:33.519103Z  ERROR license violation

Describe the solution you'd like We would love to have the ability of turning Redis cache off via env var in the router.yaml file, example:

supergraph:
  query_planning:
    experimental_cache:
      in_memory:
        limit: 1024
      redis:
----->  enabled: ${env.ENABLE_REDIS_CACHE:-false}
        urls:
          - "redis://${env.REDIS_HOST:-127.0.0.1}"

apq:
  router:
    cache:
      in_memory:
        limit: 1024
      redis:
----->  enabled: ${env.ENABLE_REDIS_CACHE:-false}
        urls:
          - "redis://${env.REDIS_HOST:-127.0.0.1}"

Describe alternatives you've considered As an alternative solution, you could change those errors to WARN and let the application run without those 2 features when the Apollo key is not set.

o0Ignition0o commented 1 year ago

This seems very reasonable, would you be open to make a PR for this?

There might be a subtlety around it being enabled: true if an other key is set, and we'd probably need a migration.

nathanmarcos commented 1 year ago

Sure thing, @o0Ignition0o ! I created a draft for you to have a look. I'm pretty sure there are some things to be improved/added to it. 😄

o0Ignition0o commented 1 year ago

cc @BrynCooke and @abernix, does this configuration proposal look sensible to you?

nathanmarcos commented 1 year ago

Hello @o0Ignition0o , I just resolved some small conflicts on that PR and it's ready for review again. Please, let me know if there is anything else I can do to help move it forward.