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

gateway: Small improvements to error messages and behavior during updates. #3811

Merged
merged 29 commits into from
Mar 6, 2020

Commits on Mar 3, 2020

  1. Adjust deceiving error message about previous schemas and falling back.

    This message was being issued when a new server starts up, prior to ever having
    a schema, when a storage secret (or any other artifact) can't be fetched
    from GCS (or any error within `updateServiceDefinitions`) despite the fact
    that there may be no `previousSchema`.
    
    While I could use `previousSchema` to change the error message, I don't
    think that it's this methods concern to decide what happens in the event of
    an error.  I think it's only this methods concern to actually do the update,
    if it is in fact successful.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    06c3267 View commit details
    Browse the repository at this point in the history
  2. Throw when updating the schema doesn't fail as expected.

    Currently, we log the error and just return without throwing which causes
    `load` (one of two places where `updateComposition` is called to not
    actually fail and follow-up logic then suggests "Gateway successfully loaded
    schema", even though that cannot be true.
    
    The nice thing about this change (in addition to allowing someone to `catch`
    an error from `ApolloGateway.prototype.load`) is that this should bubble all
    the way up to the place where we currently call `load` within Apollo
    Server's constructor, and stop the server from starting in this failure
    condition:
    
    https://github.com/apollographql/apollo-server/blob/7dcee80ff33061c0911458d593ebbca5a9c73939/packages/apollo-server-core/src/ApolloServer.ts#L366
    
    The other place we call `updateComposition` is within a `setTimeout`.  That
    particular case is less troublesome since it will retry on the next interval.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    1655f4b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    827cba2 View commit details
    Browse the repository at this point in the history
  4. Move "previous" variables closer to where they are used.

    No need to have them so far away from their usage and to even do these
    assignments at all when there are already escape routes that exit this code
    path.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    7250bfe View commit details
    Browse the repository at this point in the history
  5. Align error messages with consistent terminology and add clarity.

    * Refer to the thing we are processing consistently as "schema definitions".
    * Also make them generally more factual.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    c1ee91e View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    c3fb481 View commit details
    Browse the repository at this point in the history
  7. Switch to using single argument logger usage and serialization.

    Rely on `message` only if it's present, and fall back to serialization
    methods which might exist on the prototype otherwise (e.g. `toJSON`,
    `toString`).
    
    Also, switch to a single parameter usage of the logging facility.  While
    `console.log` supports it, its certainly possible that the logger will
    _not_, and will need that positional parameter for something else.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    e1d97d3 View commit details
    Browse the repository at this point in the history
  8. gateway: Trap unhandled promise rejections in polling.

    While successful `updateComposition` invocations were working properly,
    failed invocations (including GCS access errors, network hiccups and just
    general configuration mistakes) were currently cluttering the logs with
    warnings of unhandled promise rejections.
    
    While those unhandled rejections did include the actual error messages, this
    adjusts them to be caught and logged in a structured manner with our
    `logger`, sparing our logs from those unnecessarily verbose (and scary!)
    messages.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    da06fa8 View commit details
    Browse the repository at this point in the history
  9. Remove incorrect comment about typings being an appropriate assertion.

    Adjusting the typings only works for users of TypeScript.  On the other
    hand, this is a one-time assertion which happens at instantiation time which
    could save a JavaScript developer from the pain of not knowing what's going
    on!
    
    There might be typing improvements to be had, but claiming it as an alternate
    approach to handling this isn't correct.  The typings can still be improved,
    of course.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    88b87ea View commit details
    Browse the repository at this point in the history
  10. typings: Remove any type!

    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    846e59e View commit details
    Browse the repository at this point in the history
  11. Use the same fetch response handling for the waterfall of GCS requests.

    Overall, the success/failure behavior should be expected to be similar for
    all of these requests, as they all access the same GCS store.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    ee4c9ac View commit details
    Browse the repository at this point in the history
  12. Do not prefix potentially the same error object on every request.

    Sometimes, the error object which is being caught here is in fact not a
    misconfiguration of server options, but rather an error which was thrown in
    a promise chain.
    
    By appending the "Invalid options provided to ApolloServer" string to the
    error object's `message` property in this method that is called on _every_
    request to the server (`runHttpQuery`), we're risking appending the same
    prefix to the same error over and over (i.e. "a: a: a: a: a: b").
    
    While this prefix may have been true at one point, it is no longer possible
    to enforce in a world where the schema is obtained asynchronously.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    d8c682b View commit details
    Browse the repository at this point in the history
  13. Ensure the executor is set in gateway mode after failed load reco…

    …veries.
    
    Previously, if the initial call to `load` failed, but its intention (fetching a
    federated schema configuration in managed federation) is eventually
    accomplished via a subsequent fetch (via setInterval polling), the
    `executor` would not be set.
    
    This resulted in a continued failure even if the `schema` was eventually set
    since federated `schema`s require the Gateway's `executor` to do pull off
    their much more complex (remote!) execution strategy!
    
    The solution was simple since `executor` was already present on the actual
    `ApolloGateway`, but that required exposing that property as a valid type to
    access from the interface that `ApolloGateway` implements: `GraphQLService`.
    
    I don't see why a `GraphQLService` wouldn't have an executor, so it seemed
    appropriate to add, particularly since our only `GraphQLService` is the
    `ApolloGateway` class itself.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    c473f88 View commit details
    Browse the repository at this point in the history
  14. Ensure that initial gateway load failures trap the downstream error.

    In particular, this blocks any rejected promises which may come from GCS
    load prior to returning them to the `schemaDerivedData` promise (which is
    where the `initSchema` method assigns the result to).
    
    Failure to do this results in the server middleware sending the error
    directly to the client.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    a30bee7 View commit details
    Browse the repository at this point in the history
  15. Allow other middleware (e.g. Playground) when initial Gateway load fa…

    …ils.
    
    Another approach to this would be to throw an error here, but this is our
    only opportunity to allow the server to recover after initial failure.
    
    On the one hand, this approach is more graceful, but on the other hand,
    perhaps we actually want initial failure (after timeouts elapse) to not bind
    the other middleware.  Either way, the server doesn't just `process.exit`
    right now, and with certain non-Node.js environments, it may be worthwhile
    to operate in this mode.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    99229fe View commit details
    Browse the repository at this point in the history
  16. Ensure the executor is still set on ApolloServer when load reje…

    …cts.
    
    Because we want the actual executor to work when a schema might eventually
    become available, as it may when `onSchemaChange` hooks eventually succeed.
    abernix authored and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    f878c7f View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    4f2fbff View commit details
    Browse the repository at this point in the history
  18. Update packages/apollo-gateway/src/__tests__/gateway/executor.test.ts

    Co-Authored-By: Trevor Scheer <trevor@apollographql.com>
    abernix and trevor-scheer committed Mar 3, 2020
    Configuration menu
    Copy the full SHA
    03038e3 View commit details
    Browse the repository at this point in the history

Commits on Mar 4, 2020

  1. Update packages/apollo-gateway/src/loadServicesFromStorage.ts

    Co-Authored-By: Trevor Scheer <trevor@apollographql.com>
    abernix and trevor-scheer committed Mar 4, 2020
    Configuration menu
    Copy the full SHA
    4d4ab5b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0a50943 View commit details
    Browse the repository at this point in the history
  3. Re-apply 4d4ab5b: apollo-gateway/src/loadServicesFromStorage.ts

    To correct the syntax error.
    
    Co-Authored-By: Trevor Scheer <trevor@apollographql.com>
    abernix and trevor-scheer committed Mar 4, 2020
    Configuration menu
    Copy the full SHA
    554e20c View commit details
    Browse the repository at this point in the history

Commits on Mar 6, 2020

  1. chore(deps): update dependency gatsby-theme-apollo-docs to v4.0.13 (#…

    …3856)
    
    Co-authored-by: WhiteSource Renovate <renovatebot@gmail.com>
    renovate[bot] and renovate-bot committed Mar 6, 2020
    Configuration menu
    Copy the full SHA
    a75a366 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    81a72e2 View commit details
    Browse the repository at this point in the history
  3. Change error message to not include word "lacks".

    No particular reason, but I just didn't enjoy the previous wording (my own!).
    abernix committed Mar 6, 2020
    Configuration menu
    Copy the full SHA
    1400905 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    5dc847a View commit details
    Browse the repository at this point in the history
  5. Remove CHANGELOG.md annotations for pre-release version designators.

    These have been released!
    abernix committed Mar 6, 2020
    Configuration menu
    Copy the full SHA
    3d3ed9d View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    0c55de9 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    bba47c9 View commit details
    Browse the repository at this point in the history
  8. Add CHANGELOG.md for #3811.

    abernix committed Mar 6, 2020
    Configuration menu
    Copy the full SHA
    264547c View commit details
    Browse the repository at this point in the history