这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@rakeshkky
Copy link
Member

@rakeshkky rakeshkky commented Apr 29, 2019

Description

This PR fixes:-

  • While defining new metadata on the console like adding tables/functions, relationships, permissions etc. server throws remote schema errors if the remote server is not available
  • Sending raw response body (from a remote server on non 200s) as error message to the client

Details:-

  • If any remote schema present in metadata, the server makes introspection query to the remote server to fetch graphql schema for each /v1/query which modifies the schema state, such as track_table, track_function etc.
  • Adding a remote schema (add_remote_schema query type) makes 2 network requests. One to fetch and validate. The other is to fetch and stitch the remote schema at different levels.
  • Making a bulk query takes significant time since each query make a network request to remote server and rebuilds the graphql schema

The above issues are solved by caching remote schema GraphQL types and avoid refreshing remote schema for each /v1/query API call.
To refresh remote schema, a new /v1/query query type reload_remote_schema is introduced and it is integrated with reload button under modify section of a remote schema in console.

Results:-

Tracking ~300 tables through console which actually makes a bulk query, in the local setup.

  • Before: 26.308018138 sec
  • After: 1.249884826 sec

Affected components

  • Server
  • Console
  • Docs
  • Tests

Design and Solution

Server:-

  • Cache parsed GraphQL types from remote server introspection query response to avoid making network requests on every metadata update /v1/query.
  • Move graphql schema generation to runQueryM function. This'll abort any changes made if graphql schema generation fails
  • Introduce a new reload_remote_schema query type to re-fetch GraphQL types from a given remote server.
  • A better error response when the remote schema server responded with non 200 status code
  • Log the HTTP exception in JSON format under internal field of error if it occurs while contacting remote server to fetch schema

Console:-

  • Use reload_remote_schema API instead of reload_metadata under reload section of a remote schema.

To Reviewer (server):-

Start with ../SchemaCache.hs file and look for RemoteSchemaCtx type

  • No new modules are added
  • Type RemoteGCtx moved to ..GraphQL/Context.hs since it represents graphQL context for remote schema
  • Type RemoteSchemaCtx is context of remote schema which'll be stored in schema cache
  • New functions buildGCtxMapPG and buildGCtxMap are defined to make GraphQL schema in state monad

critical modules:

  • ../Server/Query.hs
  • ../App.hs
  • ../DDL/RemoteSchema.hs
  • ../GraphQL/RemoteServer.hs

Related Issues

close #1679

Breaking Changes

  1. Error response while adding a remote schema is improved to avoid proxying response body in error field on non 200 status code

Before

{
  "path": "$.args[0].args",
  "error": "<Large HTML Response Body from Remote Server>",
  "code": "remote-schema-error"
}

After:

{
  "internal": {
    "raw_body": "<Large HTML Response Body from Remote Server>"
  },
  "path": "$.args[0].args",
  "error": "introspection query to https://hasura.io/random has responded with 404 status code",
  "code": "remote-schema-error"
}
  1. Now, http-log of the server will have a new internal property in error object when HTTP or API exception from remote server occurs while adding.

Before:

{
  "timestamp": "2019-06-19T18:59:18.060+0530",
  "level": "info",
  "type": "http-log",
  "detail": {
    "status": 400,
    "query_hash": "ddc917a7d389e0b2bf2ec4e566df8c5a1f3cc612",
    "http_version": "HTTP/1.1",
    "query_execution_time": 0.001634484,
    "request_id": null,
    "url": "/v1/query",
    "ip": "127.0.0.1",
    "response_size": 147,
    "user": {
      "x-hasura-role": "admin"
    },
    "method": "POST",
    "detail": {
      "error": {
        "path": "$.args[0].args",
        "error": "HTTP exception occurred while sending the request to http://localhost:8181/graphql",
        "code": "remote-schema-error"
      },
      "request": "{\"type\":\"bulk\",\"args\":[{\"type\":\"add_remote_schema\",\"args\":{\"name\":\"random\",\"definition\":{\"url\":\"http://localhost:8181/graphql\",\"headers\":[],\"forward_client_headers\":false}}}]}"
    }
  }
}

After:

{
  "timestamp": "2019-06-19T18:53:40.965+0530",
  "level": "info",
  "type": "http-log",
  "detail": {
    "status": 400,
    "query_hash": "a0818e9c99f276c36346affe4d4122a16c864e2e",
    "http_version": "HTTP/1.1",
    "query_execution_time": 0.001481765,
    "request_id": null,
    "url": "/v1/query",
    "ip": "127.0.0.1",
    "response_size": 482,
    "user": {
      "x-hasura-role": "admin"
    },
    "method": "POST",
    "detail": {
      "error": {
        "internal": {
          "message": "ConnectionFailure Network.Socket.connect: <socket: 18>: does not exist (Connection refused)",
          "request": {
            "proxy": null,
            "secure": "False",
            "path": "/graphql",
            "responseTimeout": "ResponseTimeoutDefault",
            "method": "POST",
            "host": "localhost",
            "requestVersion": "HTTP/1.1",
            "redirectCount": "10",
            "port": "8181"
          }
        },
        "path": "$.args[0].args",
        "error": "HTTP exception occurred while sending the request to http://localhost:8181/graphql",
        "code": "remote-schema-error"
      },
      "request": "{\"type\":\"bulk\",\"args\":[{\"type\":\"add_remote_schema\",\"args\":{\"name\":\"random\",\"definition\":{\"url\":\"http://localhost:8181/graphql\",\"headers\":[],\"forward_client_headers\":false}}}]}"
    }
  }
}

Limitation

While adding multiple remote schemas in a bulk query, the error lacks the context of the remote schema which caused merge conflicts, if any, since stitching of all remote schemas happens at the end of the query.

Updates after discussion with @0x777 (3rd July 2019):

Do not build GraphQL context at the end of the bulk query. Fallback to the current method. However, for each query in bulk query, the GraphQL context is built but without fetching schemas from remote servers as we're caching them. We should preserve the semantics of bulk query ie. treat each query as isolated. Hence, GraphQL schema needs to be built for each bulk query.

@rakeshkky rakeshkky added s/do-not-merge Do not merge this pull request to master c/console Related to console c/server Related to server c/docs Related to docs labels Apr 29, 2019
@rakeshkky rakeshkky self-assigned this Apr 29, 2019
@netlify
Copy link

netlify bot commented Apr 29, 2019

Deploy preview for hasura-docs ready!

Built with commit bfba275

https://deploy-preview-2089--hasura-docs.netlify.com

@hasura-bot
Copy link
Contributor

Review app for commit d5c48e8 deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-d5c48e8

@rakeshkky rakeshkky requested a review from ecthiender May 2, 2019 08:03
@rakeshkky rakeshkky requested a review from nizar-m May 2, 2019 11:41
@hasura-bot
Copy link
Contributor

Review app for commit 6fd7e4f deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-6fd7e4f

@hasura-bot
Copy link
Contributor

Review app for commit cd6b659 deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-cd6b6599

Resolve Conflicts:
	server/src-lib/Hasura/RQL/DDL/Schema/Table.hs
	server/src-lib/Hasura/Server/App.hs
@hasura-bot
Copy link
Contributor

Review app for commit a452f07 deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-a452f07a

Resolve Conflicts:
	docs/graphql/manual/api-reference/schema-metadata-api/index.rst
	docs/graphql/manual/api-reference/schema-metadata-api/syntax-defs.rst
	server/src-lib/Hasura/RQL/Types/SchemaCache.hs
	server/src-lib/Hasura/Server/App.hs
	server/src-lib/Hasura/Server/Query.hs
@hasura-bot
Copy link
Contributor

Review app for commit ac480f9 deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-ac480f92

@hasura-bot
Copy link
Contributor

Review app for commit 5d96397 deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-5d963971

ecthiender
ecthiender previously approved these changes May 27, 2019
Copy link
Contributor

@ecthiender ecthiender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server changes LGTM. Requires console changes.

@ecthiender
Copy link
Contributor

The logic for reloading the schema cache (after DDL queries) has changed a bit. @0x777 needs to review those bits. cc @dsandip

@dsandip
Copy link
Member

dsandip commented May 28, 2019

@karthikvt26 @rikinsk For console, the button highlighted 👇 (and the help text) need to change to use reload_remote_schema API instead of reload_metadata:

Screenshot 2019-05-28 at 1 16 13 PM

0x777
0x777 previously approved these changes Jul 3, 2019
@arvi3411301
Copy link
Member

/heroku deploy

@hasura-bot
Copy link
Contributor

Review app for commit fe1ab51 deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-fe1ab512

@dsandip dsandip assigned rikinsk-zz and unassigned rakeshkky and karthikvt26 Jul 4, 2019
@rikinsk-zz rikinsk-zz assigned karthikvt26 and unassigned rikinsk-zz Jul 4, 2019
@hasura-bot
Copy link
Contributor

Review app for commit 6d7039b deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-6d7039b1

@rikinsk-zz
Copy link

rikinsk-zz commented Jul 4, 2019

When I reload a schema with a conflicting type, this is the screen I see.
Screenshot from 2019-07-04 18-51-11

There are no details shown to help debug. The error details from response need to be shown.

edit: fixed now

@rikinsk-zz rikinsk-zz self-requested a review July 5, 2019 10:24
rikinsk-zz
rikinsk-zz previously approved these changes Jul 5, 2019
@rikinsk-zz rikinsk-zz self-requested a review July 5, 2019 10:27
@hasura-bot
Copy link
Contributor

Review app for commit dc4c026 deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-dc4c026b

@hasura-bot
Copy link
Contributor

Review app for commit bfba275 deployed to Heroku: https://hge-ci-pull-2089.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2089-bfba2757

@0x777 0x777 merged commit 9eb38e6 into hasura:master Jul 8, 2019
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-2089.herokuapp.com is deleted

polRk pushed a commit to polRk/graphql-engine that referenced this pull request Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/console Related to console c/docs Related to docs c/server Related to server s/has-breaking-changes s/ok-to-merge Status: This pull request can be merged to master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cache remote schema's introspection query