From b40c0488a743437600e553193c1c85947c540a23 Mon Sep 17 00:00:00 2001 From: Aleksandra Sikora Date: Mon, 17 Aug 2020 12:13:01 +0200 Subject: [PATCH 01/16] console: fix handling separated sql and statement timeout (#5600) --- .../components/Services/Data/RawSQL/Actions.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/console/src/components/Services/Data/RawSQL/Actions.js b/console/src/components/Services/Data/RawSQL/Actions.js index 8a7a13265c13b..9ef8d758d9833 100644 --- a/console/src/components/Services/Data/RawSQL/Actions.js +++ b/console/src/components/Services/Data/RawSQL/Actions.js @@ -42,6 +42,7 @@ const executeSQL = (isMigration, migrationName, statementTimeout) => ( const { isTableTrackChecked, isCascadeChecked, sql } = getState().rawSQL; const { migrationMode, readOnlyMode } = getState().main; + const isStatementTimeout = statementTimeout && !isMigration; const migrateUrl = returnMigrateUrl(migrationMode); @@ -49,7 +50,7 @@ const executeSQL = (isMigration, migrationName, statementTimeout) => ( const schemaChangesUp = []; - if (statementTimeout && !isMigration) { + if (isStatementTimeout) { schemaChangesUp.push( getRunSqlQuery( getStatementTimeoutSql(statementTimeout), @@ -111,7 +112,10 @@ const executeSQL = (isMigration, migrationName, statementTimeout) => ( } dispatch(showSuccessNotification('SQL executed!')); dispatch(fetchDataInit()).then(() => { - dispatch({ type: REQUEST_SUCCESS, data }); + dispatch({ + type: REQUEST_SUCCESS, + data: data && (isStatementTimeout ? data[1] : data[0]), + }); }); dispatch(fetchTrackedFunctions()); }, @@ -168,11 +172,7 @@ const rawSQLReducer = (state = defaultState, action) => { lastSuccess: null, }; case REQUEST_SUCCESS: - if ( - action.data && - action.data[0] && - action.data[0].result_type === 'CommandOk' - ) { + if (action.data && action.data.result_type === 'CommandOk') { return { ...state, ongoingRequest: false, @@ -188,8 +188,8 @@ const rawSQLReducer = (state = defaultState, action) => { lastError: null, lastSuccess: true, resultType: 'tuples', - result: action.data[0].result.slice(1), - resultHeaders: action.data[0].result[0], + result: action.data.result.slice(1), + resultHeaders: action.data.result[0], }; case REQUEST_ERROR: return { From e56515934a43fab4d265bad196a07ca31d38aae1 Mon Sep 17 00:00:00 2001 From: Tirumarai Selvan Date: Mon, 17 Aug 2020 17:10:27 +0530 Subject: [PATCH 02/16] tag release v1.3.1-beta.1 (#5604) backport from beta branch --- CHANGELOG.md | 8 ++++++++ .../azure-container-with-pg/azuredeploy.json | 2 +- install-manifests/azure-container/azuredeploy.json | 2 +- .../docker-compose-https/docker-compose.yaml | 2 +- .../docker-compose-pgadmin/docker-compose.yaml | 2 +- .../docker-compose-postgis/docker-compose.yaml | 2 +- install-manifests/docker-compose/docker-compose.yaml | 2 +- install-manifests/docker-run/docker-run.sh | 2 +- install-manifests/google-cloud-k8s-sql/deployment.yaml | 2 +- install-manifests/kubernetes/deployment.yaml | 2 +- scripts/cli-migrations/v1/Dockerfile | 2 +- scripts/cli-migrations/v2/Dockerfile | 2 +- server/src-rsr/catalog_versions.txt | 1 + 13 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 821301c3e196b..de51bf056b3c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## Next release + +### Bug fixes and improvements + +(Add entries here in the order of: server, console, cli, docs, others) + + +## `v1.3.1-beta.1` + ### Breaking change Headers from environment variables starting with `HASURA_GRAPHQL_` are not allowed diff --git a/install-manifests/azure-container-with-pg/azuredeploy.json b/install-manifests/azure-container-with-pg/azuredeploy.json index c0663580cdfb1..5740d8a2fc12e 100644 --- a/install-manifests/azure-container-with-pg/azuredeploy.json +++ b/install-manifests/azure-container-with-pg/azuredeploy.json @@ -98,7 +98,7 @@ "firewallRuleName": "allow-all-azure-firewall-rule", "containerGroupName": "[concat(parameters('name'), '-container-group')]", "containerName": "hasura-graphql-engine", - "containerImage": "hasura/graphql-engine:v1.3.0" + "containerImage": "hasura/graphql-engine:v1.3.1-beta.1" }, "resources": [ { diff --git a/install-manifests/azure-container/azuredeploy.json b/install-manifests/azure-container/azuredeploy.json index 79c9189aa35cf..9297bff07ef86 100644 --- a/install-manifests/azure-container/azuredeploy.json +++ b/install-manifests/azure-container/azuredeploy.json @@ -55,7 +55,7 @@ "dbName": "[parameters('postgresDatabaseName')]", "containerGroupName": "[concat(parameters('name'), '-container-group')]", "containerName": "hasura-graphql-engine", - "containerImage": "hasura/graphql-engine:v1.3.0" + "containerImage": "hasura/graphql-engine:v1.3.1-beta.1" }, "resources": [ { diff --git a/install-manifests/docker-compose-https/docker-compose.yaml b/install-manifests/docker-compose-https/docker-compose.yaml index ad536ee4f4282..2c591cc530ece 100644 --- a/install-manifests/docker-compose-https/docker-compose.yaml +++ b/install-manifests/docker-compose-https/docker-compose.yaml @@ -8,7 +8,7 @@ services: environment: POSTGRES_PASSWORD: postgrespassword graphql-engine: - image: hasura/graphql-engine:v1.3.0 + image: hasura/graphql-engine:v1.3.1-beta.1 depends_on: - "postgres" restart: always diff --git a/install-manifests/docker-compose-pgadmin/docker-compose.yaml b/install-manifests/docker-compose-pgadmin/docker-compose.yaml index ac4705650141b..dfe02a712dd7f 100644 --- a/install-manifests/docker-compose-pgadmin/docker-compose.yaml +++ b/install-manifests/docker-compose-pgadmin/docker-compose.yaml @@ -19,7 +19,7 @@ services: PGADMIN_DEFAULT_EMAIL: pgadmin@example.com PGADMIN_DEFAULT_PASSWORD: admin graphql-engine: - image: hasura/graphql-engine:v1.3.0 + image: hasura/graphql-engine:v1.3.1-beta.1 ports: - "8080:8080" depends_on: diff --git a/install-manifests/docker-compose-postgis/docker-compose.yaml b/install-manifests/docker-compose-postgis/docker-compose.yaml index a7f0cf50e1f57..9e3e91050e5f1 100644 --- a/install-manifests/docker-compose-postgis/docker-compose.yaml +++ b/install-manifests/docker-compose-postgis/docker-compose.yaml @@ -8,7 +8,7 @@ services: environment: POSTGRES_PASSWORD: postgrespassword graphql-engine: - image: hasura/graphql-engine:v1.3.0 + image: hasura/graphql-engine:v1.3.1-beta.1 ports: - "8080:8080" depends_on: diff --git a/install-manifests/docker-compose/docker-compose.yaml b/install-manifests/docker-compose/docker-compose.yaml index 8dbb5a8e485ac..21439e7edd4a3 100644 --- a/install-manifests/docker-compose/docker-compose.yaml +++ b/install-manifests/docker-compose/docker-compose.yaml @@ -8,7 +8,7 @@ services: environment: POSTGRES_PASSWORD: postgrespassword graphql-engine: - image: hasura/graphql-engine:v1.3.0 + image: hasura/graphql-engine:v1.3.1-beta.1 ports: - "8080:8080" depends_on: diff --git a/install-manifests/docker-run/docker-run.sh b/install-manifests/docker-run/docker-run.sh index e651e5b6dd02e..2f366a5066c2d 100755 --- a/install-manifests/docker-run/docker-run.sh +++ b/install-manifests/docker-run/docker-run.sh @@ -3,4 +3,4 @@ docker run -d -p 8080:8080 \ -e HASURA_GRAPHQL_DATABASE_URL=postgres://username:password@hostname:port/dbname \ -e HASURA_GRAPHQL_ENABLE_CONSOLE=true \ -e HASURA_GRAPHQL_DEV_MODE=true \ - hasura/graphql-engine:v1.3.0 + hasura/graphql-engine:v1.3.1-beta.1 diff --git a/install-manifests/google-cloud-k8s-sql/deployment.yaml b/install-manifests/google-cloud-k8s-sql/deployment.yaml index 658ce41e78781..867b01267fe33 100644 --- a/install-manifests/google-cloud-k8s-sql/deployment.yaml +++ b/install-manifests/google-cloud-k8s-sql/deployment.yaml @@ -16,7 +16,7 @@ spec: spec: containers: - name: graphql-engine - image: hasura/graphql-engine:v1.3.0 + image: hasura/graphql-engine:v1.3.1-beta.1 ports: - containerPort: 8080 readinessProbe: diff --git a/install-manifests/kubernetes/deployment.yaml b/install-manifests/kubernetes/deployment.yaml index 68bcb58ae3deb..a3480120f8592 100644 --- a/install-manifests/kubernetes/deployment.yaml +++ b/install-manifests/kubernetes/deployment.yaml @@ -18,7 +18,7 @@ spec: app: hasura spec: containers: - - image: hasura/graphql-engine:v1.3.0 + - image: hasura/graphql-engine:v1.3.1-beta.1 imagePullPolicy: IfNotPresent name: hasura env: diff --git a/scripts/cli-migrations/v1/Dockerfile b/scripts/cli-migrations/v1/Dockerfile index af3bfcb701d5f..7b5bc257af3f8 100644 --- a/scripts/cli-migrations/v1/Dockerfile +++ b/scripts/cli-migrations/v1/Dockerfile @@ -1,4 +1,4 @@ -FROM hasura/graphql-engine:v1.3.0 +FROM hasura/graphql-engine:v1.3.1-beta.1 # set an env var to let the cli know that # it is running in server environment diff --git a/scripts/cli-migrations/v2/Dockerfile b/scripts/cli-migrations/v2/Dockerfile index 93d8869c96df1..6303f1a002bca 100644 --- a/scripts/cli-migrations/v2/Dockerfile +++ b/scripts/cli-migrations/v2/Dockerfile @@ -2,7 +2,7 @@ FROM hasura/haskell-docker-packager:20190731 as packager WORKDIR /tmp RUN apt-get update && apt-get download libstdc++6 -FROM hasura/graphql-engine:v1.3.0 +FROM hasura/graphql-engine:v1.3.1-beta.1 # install libstdc++6 from .deb file COPY --from=packager /tmp/libstdc++6* . diff --git a/server/src-rsr/catalog_versions.txt b/server/src-rsr/catalog_versions.txt index 047460b34d5a7..9162f034f4fc0 100644 --- a/server/src-rsr/catalog_versions.txt +++ b/server/src-rsr/catalog_versions.txt @@ -28,3 +28,4 @@ v1.3.0-beta.2 36 v1.3.0-beta.3 36 v1.3.0-beta.4 36 v1.3.0 36 +v1.3.1-beta.1 37 From 1592470008a9d6024a077cd1afe3c04b0850c7db Mon Sep 17 00:00:00 2001 From: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Date: Mon, 17 Aug 2020 20:31:23 +0530 Subject: [PATCH 03/16] docs: fix action relationships ref link (#5602) --- docs/graphql/manual/actions/types/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/graphql/manual/actions/types/index.rst b/docs/graphql/manual/actions/types/index.rst index f54a19f584f28..b8bfd03ae1590 100644 --- a/docs/graphql/manual/actions/types/index.rst +++ b/docs/graphql/manual/actions/types/index.rst @@ -59,7 +59,7 @@ Relationships ************* Custom object types can be connected to the rest of the graph by setting up -:ref:`table relationships ` with tables/views. +:ref:`action relationships ` with tables/views. **For example**, given the object type: From 754acc7707163fc5f90d121053ba0a49cddf6d8f Mon Sep 17 00:00:00 2001 From: Sid Sethupathi Date: Mon, 17 Aug 2020 11:05:14 -0500 Subject: [PATCH 04/16] console: fix broken link in permissions section (#5598) --- .../components/Services/Data/TablePermissions/Permissions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/src/components/Services/Data/TablePermissions/Permissions.js b/console/src/components/Services/Data/TablePermissions/Permissions.js index 695021d2bd045..31a7cb64fc569 100644 --- a/console/src/components/Services/Data/TablePermissions/Permissions.js +++ b/console/src/components/Services/Data/TablePermissions/Permissions.js @@ -1766,7 +1766,7 @@ class Permissions extends Component { 'Backend only', tooltip, backendStatus, - 'https://docs.hasura.io/1.0/graphql/manual/auth/authorization/permission-rules.html#backend-only-inserts' + 'https://hasura.io/docs/1.0/graphql/manual/auth/authorization/permission-rules.html#backend-only' )} useDefaultTitleStyle testId={'toggle-backend-only'} From 684c25b14bf31e559c9b976b5264e0254daddbf8 Mon Sep 17 00:00:00 2001 From: slimlime <30815731+slimlime@users.noreply.github.com> Date: Tue, 18 Aug 2020 18:12:58 +1000 Subject: [PATCH 05/16] docs: update bash_completion directory typo (#5418) --- cli/commands/completion.go | 2 +- docs/graphql/manual/hasura-cli/hasura_completion.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/commands/completion.go b/cli/commands/completion.go index 7964938c00c16..213104734538e 100644 --- a/cli/commands/completion.go +++ b/cli/commands/completion.go @@ -12,7 +12,7 @@ import ( const completionCmdExample = `# Bash # Linux # Add Bash completion file using: - $ sudo hasura completion bash --file=/etc/bash.completion.d/hasura + $ sudo hasura completion bash --file=/etc/bash_completion.d/hasura # Mac # Install bash-completion using homebrew: $ brew install bash-completion diff --git a/docs/graphql/manual/hasura-cli/hasura_completion.rst b/docs/graphql/manual/hasura-cli/hasura_completion.rst index 8d7a7e19120b0..3b2749cb44334 100644 --- a/docs/graphql/manual/hasura-cli/hasura_completion.rst +++ b/docs/graphql/manual/hasura-cli/hasura_completion.rst @@ -27,7 +27,7 @@ Examples # Bash # Linux # Add Bash completion file using: - $ sudo hasura completion bash --file=/etc/bash.completion.d/hasura + $ sudo hasura completion bash --file=/etc/bash_completion.d/hasura # Mac # Install bash-completion using homebrew: $ brew install bash-completion From 6da6dd6bf2837244d96daefe522866f91d76800c Mon Sep 17 00:00:00 2001 From: Marion Schleifer Date: Tue, 18 Aug 2020 10:41:04 +0200 Subject: [PATCH 06/16] docs: update sample hasura endpoint urls with cloud urls (#5583) --- .../manual/guides/integrations/auth0-jwt.rst | 2 +- .../manual/guides/integrations/aws-cognito.rst | 2 +- .../migrations/config-v1/manage-migrations.rst | 12 ++++++------ .../graphql/manual/migrations/migrations-setup.rst | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/graphql/manual/guides/integrations/auth0-jwt.rst b/docs/graphql/manual/guides/integrations/auth0-jwt.rst index 0b23d3c5f3bb2..60d6b5754dc8d 100644 --- a/docs/graphql/manual/guides/integrations/auth0-jwt.rst +++ b/docs/graphql/manual/guides/integrations/auth0-jwt.rst @@ -231,7 +231,7 @@ Using Auth0 Rules again, add the following rule which will insert a new user eve function (user, context, callback) { const userId = user.user_id; const hasuraAdminSecret = "xxxx"; - const url = "https://my-hasura-app.herokuapp.com/v1/graphql"; + const url = "https://my-hasura-app.hasura.app/v1/graphql"; const upsertUserQuery = ` mutation($userId: String!){ insert_users(objects: [{ id: $userId }], on_conflict: { constraint: users_pkey, update_columns: [] }) { diff --git a/docs/graphql/manual/guides/integrations/aws-cognito.rst b/docs/graphql/manual/guides/integrations/aws-cognito.rst index 5f2a72ed535b7..fde890cf98885 100644 --- a/docs/graphql/manual/guides/integrations/aws-cognito.rst +++ b/docs/graphql/manual/guides/integrations/aws-cognito.rst @@ -160,7 +160,7 @@ The parameters available for this trigger are described `here ` Docker image, which can start the diff --git a/docs/graphql/manual/migrations/migrations-setup.rst b/docs/graphql/manual/migrations/migrations-setup.rst index 9f768b492396d..4253a3ea38037 100644 --- a/docs/graphql/manual/migrations/migrations-setup.rst +++ b/docs/graphql/manual/migrations/migrations-setup.rst @@ -61,8 +61,8 @@ Step 2: Set up a project directory ---------------------------------- For the endpoint referred here, let's say you've -deployed the GraphQL engine on Heroku, then this endpoint is: -``https://my-graphql.herokuapp.com``. In case you've deployed Hasura using Docker, +deployed the GraphQL engine on Hasura Cloud, then this endpoint is: +``https://my-graphql.hasura.app``. In case you've deployed Hasura using Docker, the URL might be ``http://xx.xx.xx.xx:8080``. In any case, the endpoint should **not** contain the ``v1/graphql`` API path. It should just be the hostname and any sub-path if it is configured that way. @@ -71,7 +71,7 @@ Let's set up a project directory by executing the following command: .. code-block:: bash - hasura init my-project --endpoint http://my-graphql.herokuapp.com + hasura init my-project --endpoint http://my-graphql.hasura.app cd my-project @@ -180,7 +180,7 @@ Step 4: Use the console from the CLI ------------------------------------ From this point onwards, instead of using the console at -``http://my-graphql.herokuapp.com/console`` you should use the console from the CLI +``http://my-graphql.hasura.app/console`` you should use the console from the CLI by running: .. code-block:: bash @@ -251,13 +251,13 @@ Step 7: Apply the migrations and metadata on another instance of the GraphQL eng ----------------------------------------------------------------------------------- Apply all migrations present in the ``migrations/`` directory and the metadata present -in the ``metadata/`` directory on a new instance at ``http://another-graphql-instance.herokuapp.com``: +in the ``metadata/`` directory on a new instance at ``http://another-graphql-instance.hasura.app``: .. code-block:: bash # in project dir - hasura migrate apply --endpoint http://another-graphql-instance.herokuapp.com - hasura metadata apply --endpoint http://another-graphql-instance.herokuapp.com + hasura migrate apply --endpoint http://another-graphql-instance.hasura.app + hasura metadata apply --endpoint http://another-graphql-instance.hasura.app In case you need an automated way of applying the migrations and metadata, take a look at the :ref:`cli-migrations ` Docker image, which can start the From 5c54501f3631b2b1a48492d3d91831c79a67c803 Mon Sep 17 00:00:00 2001 From: Marion Schleifer Date: Tue, 18 Aug 2020 13:45:37 +0200 Subject: [PATCH 07/16] docs: add docker networking guide (close #4346) (#4811) --- CHANGELOG.md | 2 +- docs/graphql/manual/actions/create.rst | 5 + docs/graphql/manual/actions/index.rst | 2 +- .../manual/auth/authentication/webhook.rst | 5 + .../manual/event-triggers/create-trigger.rst | 5 + .../manual/guides/docker-networking.rst | 118 ++++++++++++++++++ docs/graphql/manual/guides/index.rst | 1 + .../manual/remote-schemas/adding-schema.rst | 8 +- 8 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 docs/graphql/manual/guides/docker-networking.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index de51bf056b3c4..1936a7df38530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ (Add entries here in the order of: server, console, cli, docs, others) +- docs: add docs page on networking with docker (close #4346) (#4811) ## `v1.3.1-beta.1` @@ -75,7 +76,6 @@ If you do have such headers configured, then you must update the header configur ## `v1.3.0-beta.3` - ### Bug fixes and improvements (Add entries here in the order of: server, console, cli, docs, others) diff --git a/docs/graphql/manual/actions/create.rst b/docs/graphql/manual/actions/create.rst index ede7cba8ed651..a5682061b107e 100644 --- a/docs/graphql/manual/actions/create.rst +++ b/docs/graphql/manual/actions/create.rst @@ -203,6 +203,11 @@ Now, set the handler for the action: e.g. ``https://my-handler-endpoint/addNumbers`` can be templated to ``{{ACTION_BASE_ENDPOINT}}/addNumbers`` where ``ACTION_BASE_ENDPOINT`` is an ENV variable whose value is set to ``https://my-handler-endpoint`` +.. note:: + + If you are running Hasura using Docker, ensure that the Hasura Docker container can reach the handler endpoint. + See :ref:`this page ` for Docker networking. + Step 3: Finish action creation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/graphql/manual/actions/index.rst b/docs/graphql/manual/actions/index.rst index 1af9826e1afa2..852edc4b0fac1 100644 --- a/docs/graphql/manual/actions/index.rst +++ b/docs/graphql/manual/actions/index.rst @@ -24,7 +24,7 @@ enrichment from external sources and any other complex business logic. :class: no-shadow :alt: Actions high level architecture -.. admonition:: Support +.. admonition:: Supported from Actions are supported in Hasura GraphQL engine versions ``v.1.2.0`` and above. diff --git a/docs/graphql/manual/auth/authentication/webhook.rst b/docs/graphql/manual/auth/authentication/webhook.rst index f90cbc1d48a6e..09d0171833dc6 100644 --- a/docs/graphql/manual/auth/authentication/webhook.rst +++ b/docs/graphql/manual/auth/authentication/webhook.rst @@ -37,6 +37,11 @@ Configuring webhook mode * You can configure Hasura to send either a ``GET`` or a ``POST`` request to your auth webhook. The default configuration is ``GET`` and you can override this with ``POST`` by using the ``--auth-hook-mode`` flag or the ``HASURA_GRAPHQL_AUTH_HOOK_MODE`` environment variable (*in addition to those specified above; see* :ref:`GraphQL engine server options `). +.. note:: + + If you are running Hasura using Docker, ensure that the Hasura Docker container can reach the webhook. + See :ref:`this page ` for Docker networking. + Spec for the webhook -------------------- diff --git a/docs/graphql/manual/event-triggers/create-trigger.rst b/docs/graphql/manual/event-triggers/create-trigger.rst index abe2176110f16..29aa4d7961733 100644 --- a/docs/graphql/manual/event-triggers/create-trigger.rst +++ b/docs/graphql/manual/event-triggers/create-trigger.rst @@ -41,6 +41,11 @@ The HTTP(s) URL which will be called with the event payload on configured operat can be entered manually or can be picked up from an environment variable (*the environment variable needs to be set before using it for this configuration*). +.. note:: + + If you are running Hasura using Docker, ensure that the Hasura Docker container can reach the webhook. + See :ref:`this page ` for Docker networking. + Advanced Settings ----------------- diff --git a/docs/graphql/manual/guides/docker-networking.rst b/docs/graphql/manual/guides/docker-networking.rst new file mode 100644 index 0000000000000..e1eec1b503fe0 --- /dev/null +++ b/docs/graphql/manual/guides/docker-networking.rst @@ -0,0 +1,118 @@ +.. meta:: + :description: Docker networking with Hasura + :keywords: hasura, docs, deployment, network, docker + +.. _docker_networking: + +Docker networking +================= + +.. contents:: Table of contents + :backlinks: none + :depth: 2 + :local: + +Introduction +------------ + +Sometimes you might want to connect Hasura with APIs (e.g. auth webhooks, event triggers, remote schemas) that are either running outside of Docker or in a different Docker container. +Depending on the setting, the network config is different. This section shows how to connect in each of these use cases. + +Network config +-------------- + +.. rst-class:: api_tabs +.. tabs:: + + .. tab:: Linux + + .. list-table:: + :stub-columns: 1 + :header-rows: 1 + + * - Connection + - Config + - Comment + * - **Hasura to API (outside Docker)** + - 1. With ``--net=host``, e.g. ``localhost:3000 --net=host`` + 2. Otherwise, ``:3000``, e.g. ``172.17.0.1:3000`` + - 1. Assuming the API is running on port ``3000`` + 2. The Docker bridge IP can be found via ``ifconfig`` + * - **API (outside Docker) to Hasura** + - ``localhost:8080`` + - Hasura runs on port ``8080`` by default + * - **Hasura to API (both in docker-compose)** + - service name, e.g.: ``api:3000`` + - Assuming the API is running on port ``3000`` + * - **API to Hasura (both in docker-compose)** + - service name, e.g.: ``hasura:8080`` + - Hasura runs on port ``8080`` by default + * - **Hasura to API (both running with separate docker run)** + - Docker internal IP address + - Can be obtained with ``docker inspect`` + * - **API to Hasura (both running with separate docker run)** + - Docker internal IP address + - Can be obtained with ``docker inspect`` + + .. tab:: Mac + + .. list-table:: + :stub-columns: 1 + :header-rows: 1 + + + * - Connection + - Config + - Comment + * - **Hasura to API (outside Docker)** + - ``host.docker.internal:3000`` + - + * - **API (outside Docker) to Hasura** + - ``localhost:8080`` + - Hasura runs on port ``8080`` by default + * - **Hasura to API (both in docker-compose)** + - service name, e.g.: ``api:3000`` + - Assuming the API is running on port ``3000`` + * - **API to Hasura (both in docker-compose)** + - service name, e.g.: ``hasura:8080`` + - Hasura runs on port ``8080`` by default + * - **Hasura to API (both running with separate docker run)** + - Docker internal IP address + - Can be obtained with ``docker inspect`` + * - **API to Hasura (both running with separate docker run)** + - Docker internal IP address + - Can be obtained with ``docker inspect`` + + + .. tab:: Windows + + .. list-table:: + :stub-columns: 1 + :header-rows: 1 + + * - Connection + - Config + - Comment + * - **Hasura to API (outside Docker)** + - ``docker.for.win.localhost:3000`` + - + * - **API (outside Docker) to Hasura** + - ``localhost:8080`` + - Hasura runs on port ``8080`` by default + * - **Hasura to API (both in docker-compose)** + - service name, e.g.: ``api:3000`` + - Assuming the API is running on port ``3000`` + * - **API to Hasura (both in docker-compose)** + - service name, e.g.: ``hasura:8080`` + - Hasura runs on port ``8080`` by default + * - **Hasura to API (both running with separate docker run)** + - Docker internal IP address + - Can be obtained with ``docker inspect`` + * - **API to Hasura (both running with separate docker run)** + - Docker internal IP address + - Can be obtained with ``docker inspect`` + +Advanced +-------- + +Learn more about Docker specific networking in the `Docker documentation `__. diff --git a/docs/graphql/manual/guides/index.rst b/docs/graphql/manual/guides/index.rst index f2c8c8b324383..9fa7cf1949ea9 100644 --- a/docs/graphql/manual/guides/index.rst +++ b/docs/graphql/manual/guides/index.rst @@ -17,6 +17,7 @@ Guides / Tutorials / Resources :titlesonly: Data modelling guides + Docker networking Sample apps & boilerplates Integration/migration tutorials Integrating with monitoring frameworks diff --git a/docs/graphql/manual/remote-schemas/adding-schema.rst b/docs/graphql/manual/remote-schemas/adding-schema.rst index 3d0e942a73587..84eef707b1812 100644 --- a/docs/graphql/manual/remote-schemas/adding-schema.rst +++ b/docs/graphql/manual/remote-schemas/adding-schema.rst @@ -48,10 +48,10 @@ You need to enter the following information: .. note:: - During **local development** with the remote schema server on localhost, ensure that the Hasura Docker container can reach - the server endpoint on the host. A common way to do this is to use the domain ``host.docker.internal`` on Docker for Mac and Windows or the Docker bridge IP on Linux (typically ``172.17.0.1`` - the IP address of ``docker0`` interface. use ``ip addr show docker0``) instead of ``127.0.0.1``. - - Similarly, if you are adding the URL using env variable, then run the Hasura docker container with the env variable added during `docker run`. Example ``-e REMOTE_SCHEMA_ENDPOINT=http://host.docker.internal:4000/mycustomgraphql`` + If you are running Hasura using Docker, ensure that the Hasura Docker container can reach the server endpoint. + See :ref:`this page ` for Docker networking. + + If you are adding the URL using env variable, then run the Hasura docker container with the env variable added during `docker run`. Example ``-e REMOTE_SCHEMA_ENDPOINT=http://host.docker.internal:4000/mycustomgraphql``. - **Headers**: configure the headers to be sent to your custom GraphQL server: From 2358f6bbae22f7e3525e470cbc8573af317c8c67 Mon Sep 17 00:00:00 2001 From: Marion Schleifer Date: Tue, 18 Aug 2020 14:29:58 +0200 Subject: [PATCH 08/16] cli/docs: add missing global flags for seeds command and add new cli commands to docs (#5565) --- CHANGELOG.md | 1 + cli/commands/seed.go | 22 ++++--- cli/commands/seed_create.go | 2 +- .../manual/guides/docker-networking.rst | 4 +- .../manual/hasura-cli/hasura_seeds.rst | 45 ++++++++++++++ .../manual/hasura-cli/hasura_seeds_apply.rst | 57 ++++++++++++++++++ .../manual/hasura-cli/hasura_seeds_create.rst | 60 +++++++++++++++++++ docs/graphql/manual/hasura-cli/index.rst | 6 ++ 8 files changed, 187 insertions(+), 10 deletions(-) create mode 100644 docs/graphql/manual/hasura-cli/hasura_seeds.rst create mode 100644 docs/graphql/manual/hasura-cli/hasura_seeds_apply.rst create mode 100644 docs/graphql/manual/hasura-cli/hasura_seeds_create.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 1936a7df38530..c24c92c048955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ (Add entries here in the order of: server, console, cli, docs, others) - docs: add docs page on networking with docker (close #4346) (#4811) +- cli: add missing global flags for seeds command (#5565) ## `v1.3.1-beta.1` diff --git a/cli/commands/seed.go b/cli/commands/seed.go index 201726e13fddb..649c3a2cbdfe0 100644 --- a/cli/commands/seed.go +++ b/cli/commands/seed.go @@ -2,6 +2,7 @@ package commands import ( "github.com/hasura/graphql-engine/cli" + "github.com/hasura/graphql-engine/cli/util" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -28,14 +29,21 @@ func NewSeedCmd(ec *cli.ExecutionContext) *cobra.Command { newSeedCreateCmd(ec), newSeedApplyCmd(ec), ) - seedCmd.PersistentFlags().String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine") - seedCmd.PersistentFlags().String("admin-secret", "", "admin secret for Hasura GraphQL Engine") - seedCmd.PersistentFlags().String("access-key", "", "access key for Hasura GraphQL Engine") - seedCmd.PersistentFlags().MarkDeprecated("access-key", "use --admin-secret instead") - v.BindPFlag("endpoint", seedCmd.PersistentFlags().Lookup("endpoint")) - v.BindPFlag("admin_secret", seedCmd.PersistentFlags().Lookup("admin-secret")) - v.BindPFlag("access_key", seedCmd.PersistentFlags().Lookup("access-key")) + f := seedCmd.PersistentFlags() + + f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine") + f.String("admin-secret", "", "admin secret for Hasura GraphQL Engine") + f.String("access-key", "", "access key for Hasura GraphQL Engine") + f.MarkDeprecated("access-key", "use --admin-secret instead") + f.Bool("insecure-skip-tls-verify", false, "skip TLS verification and disable cert checking (default: false)") + f.String("certificate-authority", "", "path to a cert file for the certificate authority") + + util.BindPFlag(v, "endpoint", f.Lookup("endpoint")) + util.BindPFlag(v, "admin_secret", f.Lookup("admin-secret")) + util.BindPFlag(v, "access_key", f.Lookup("access-key")) + util.BindPFlag(v, "insecure_skip_tls_verify", f.Lookup("insecure-skip-tls-verify")) + util.BindPFlag(v, "certificate_authority", f.Lookup("certificate-authority")) return seedCmd } diff --git a/cli/commands/seed_create.go b/cli/commands/seed_create.go index 108cfcf0597ff..d315270e7de2d 100644 --- a/cli/commands/seed_create.go +++ b/cli/commands/seed_create.go @@ -31,7 +31,7 @@ func newSeedCreateCmd(ec *cli.ExecutionContext) *cobra.Command { } cmd := &cobra.Command{ Use: "create seed_name", - Short: "create a new seed file", + Short: "Create a new seed file", Example: ` # Create a new seed file and use editor to add SQL: hasura seed create new_table_seed diff --git a/docs/graphql/manual/guides/docker-networking.rst b/docs/graphql/manual/guides/docker-networking.rst index e1eec1b503fe0..4c1130c879b15 100644 --- a/docs/graphql/manual/guides/docker-networking.rst +++ b/docs/graphql/manual/guides/docker-networking.rst @@ -66,7 +66,7 @@ Network config - Comment * - **Hasura to API (outside Docker)** - ``host.docker.internal:3000`` - - + - Assuming the API is running on port ``3000`` * - **API (outside Docker) to Hasura** - ``localhost:8080`` - Hasura runs on port ``8080`` by default @@ -95,7 +95,7 @@ Network config - Comment * - **Hasura to API (outside Docker)** - ``docker.for.win.localhost:3000`` - - + - Assuming the API is running on port ``3000`` * - **API (outside Docker) to Hasura** - ``localhost:8080`` - Hasura runs on port ``8080`` by default diff --git a/docs/graphql/manual/hasura-cli/hasura_seeds.rst b/docs/graphql/manual/hasura-cli/hasura_seeds.rst new file mode 100644 index 0000000000000..e871135bd522d --- /dev/null +++ b/docs/graphql/manual/hasura-cli/hasura_seeds.rst @@ -0,0 +1,45 @@ +.. _hasura_seeds: + +Hasura CLI: hasura seeds +------------------------ + +Manage seed data + +Synopsis +~~~~~~~~ + + +Manage seed data + +Alias: sd + +Options +~~~~~~~ + +:: + + --admin-secret string admin secret for Hasura GraphQL Engine (env "HASURA_GRAPHQL_ADMIN_SECRET") + --certificate-authority string path to a cert file for the certificate authority (env "HASURA_GRAPHQL_CERTIFICATE_AUTHORITY") + --endpoint string http(s) endpoint for Hasura GraphQL Engine (env "HASURA_GRAPHQL_ENDPOINT") + -h, --help help for seeds + --insecure-skip-tls-verify skip TLS verification and disable cert checking (default: false) (env "HASURA_GRAPHQL_INSECURE_SKIP_TLS_VERIFY") + +Options inherited from parent commands +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:: + + --envfile string .env filename to load ENV vars from (default ".env") + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --no-color do not colorize output (default: false) + --project string directory where commands are executed (default: current dir) + --skip-update-check Skip automatic update check on command execution + +SEE ALSO +~~~~~~~~ + +* :ref:`hasura ` - Hasura GraphQL Engine command line tool +* :ref:`hasura seeds apply ` - Apply seed data +* :ref:`hasura seeds create ` - Create a new seed file + +*Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/hasura_seeds_apply.rst b/docs/graphql/manual/hasura-cli/hasura_seeds_apply.rst new file mode 100644 index 0000000000000..f32816158f86f --- /dev/null +++ b/docs/graphql/manual/hasura-cli/hasura_seeds_apply.rst @@ -0,0 +1,57 @@ +.. _hasura_seeds_apply: + +Hasura CLI: hasura seeds apply +------------------------------ + +Apply seed data + +Synopsis +~~~~~~~~ + + +Apply seed data + +:: + + hasura seeds apply [flags] + +Examples +~~~~~~~~ + +:: + + # Apply all seeds on the database: + hasura seed apply + + # Apply only a particular file: + hasura seed apply --file seeds/1234_add_some_seed_data.sql + +Options +~~~~~~~ + +:: + + -f, --file stringArray seed file to apply + -h, --help help for apply + +Options inherited from parent commands +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:: + + --admin-secret string admin secret for Hasura GraphQL Engine (env "HASURA_GRAPHQL_ADMIN_SECRET") + --certificate-authority string path to a cert file for the certificate authority (env "HASURA_GRAPHQL_CERTIFICATE_AUTHORITY") + --endpoint string http(s) endpoint for Hasura GraphQL Engine (env "HASURA_GRAPHQL_ENDPOINT") + --envfile string .env filename to load ENV vars from (default ".env") + --insecure-skip-tls-verify skip TLS verification and disable cert checking (default: false) (env "HASURA_GRAPHQL_INSECURE_SKIP_TLS_VERIFY") + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --no-color do not colorize output (default: false) + --project string directory where commands are executed (default: current dir) + --skip-update-check Skip automatic update check on command execution + +SEE ALSO +~~~~~~~~ + +* :ref:`hasura seeds ` - Manage seed data + +*Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/hasura_seeds_create.rst b/docs/graphql/manual/hasura-cli/hasura_seeds_create.rst new file mode 100644 index 0000000000000..d96dd01f90f3d --- /dev/null +++ b/docs/graphql/manual/hasura-cli/hasura_seeds_create.rst @@ -0,0 +1,60 @@ +.. _hasura_seeds_create: + +Hasura CLI: hasura seeds create +------------------------------- + +Create a new seed file + +Synopsis +~~~~~~~~ + + +Create a new seed file + +:: + + hasura seeds create seed_name [flags] + +Examples +~~~~~~~~ + +:: + + # Create a new seed file and use editor to add SQL: + hasura seed create new_table_seed + + # Create a new seed by exporting data from tables already present in the database: + hasura seed create table1_seed --from-table table1 + + # Export data from multiple tables: + hasura seed create tables_seed --from-table table1 --from-table table2 + +Options +~~~~~~~ + +:: + + --from-table stringArray name of table from which seed file has to be initialized + -h, --help help for create + +Options inherited from parent commands +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:: + + --admin-secret string admin secret for Hasura GraphQL Engine (env "HASURA_GRAPHQL_ADMIN_SECRET") + --certificate-authority string path to a cert file for the certificate authority (env "HASURA_GRAPHQL_CERTIFICATE_AUTHORITY") + --endpoint string http(s) endpoint for Hasura GraphQL Engine (env "HASURA_GRAPHQL_ENDPOINT") + --envfile string .env filename to load ENV vars from (default ".env") + --insecure-skip-tls-verify skip TLS verification and disable cert checking (default: false) (env "HASURA_GRAPHQL_INSECURE_SKIP_TLS_VERIFY") + --log-level string log level (DEBUG, INFO, WARN, ERROR, FATAL) (default "INFO") + --no-color do not colorize output (default: false) + --project string directory where commands are executed (default: current dir) + --skip-update-check Skip automatic update check on command execution + +SEE ALSO +~~~~~~~~ + +* :ref:`hasura seeds ` - Manage seed data + +*Auto generated by spf13/cobra* diff --git a/docs/graphql/manual/hasura-cli/index.rst b/docs/graphql/manual/hasura-cli/index.rst index fc4360ef826a6..df25c62545d52 100644 --- a/docs/graphql/manual/hasura-cli/index.rst +++ b/docs/graphql/manual/hasura-cli/index.rst @@ -61,6 +61,9 @@ Commands - :ref:`hasura plugins upgrade ` - :ref:`hasura scripts ` - :ref:`hasura scripts update-project-v2 ` +- :ref:`hasura seeds ` +- :ref:`hasura seeds apply ` +- :ref:`hasura seeds create ` - :ref:`hasura update-cli ` - :ref:`hasura version ` @@ -106,6 +109,9 @@ Refer to :ref:`uninstall_hasura_cli`. hasura plugins upgrade hasura scripts hasura scripts update-project-v2 + hasura seeds + hasura seeds apply + hasura seeds create hasura update-cli hasura version uninstall-hasura-cli From fa34845ff5bd7eb0b84d0734eb7685181d187b4d Mon Sep 17 00:00:00 2001 From: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Date: Tue, 18 Aug 2020 18:48:17 +0530 Subject: [PATCH 09/16] docs: add posthog (#5613) --- docs/_theme/djangodocs/basic/layout.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/_theme/djangodocs/basic/layout.html b/docs/_theme/djangodocs/basic/layout.html index 82cea1c4e87a8..2a60a73e75fa2 100644 --- a/docs/_theme/djangodocs/basic/layout.html +++ b/docs/_theme/djangodocs/basic/layout.html @@ -140,6 +140,11 @@

{{ _('Navigation') }}

'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-PF5MQ2Z'); + + {%- if use_opensearch %} Date: Wed, 19 Aug 2020 01:23:12 +0530 Subject: [PATCH 10/16] server: Pass EKG Metrics Store as argument to runHGEServer (#5560) * Add ekg-core to build-executable .cabal * Move creation of EKG Store to Main.hs This helps to share metrics between pro and OSS and helps surface the metrics from OSS in Datadog via Pro. Co-authored-by: Phil Freeman --- server/graphql-engine.cabal | 1 + server/src-exec/Main.hs | 5 ++++- server/src-lib/Hasura/App.hs | 6 +++++- server/src-lib/Hasura/Server/App.hs | 5 ++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/server/graphql-engine.cabal b/server/graphql-engine.cabal index 194c17c6d3105..d20fb55390500 100644 --- a/server/graphql-engine.cabal +++ b/server/graphql-engine.cabal @@ -423,6 +423,7 @@ executable graphql-engine , text , text-conversions , unix + , ekg-core test-suite graphql-engine-tests import: common-all, common-exe diff --git a/server/src-exec/Main.hs b/server/src-exec/Main.hs index a7bb293f400ae..8dc0af125c635 100644 --- a/server/src-exec/Main.hs +++ b/server/src-exec/Main.hs @@ -23,6 +23,8 @@ import qualified Database.PG.Query as Q import qualified Hasura.Tracing as Tracing import qualified System.Exit as Sys import qualified System.Posix.Signals as Signals +import qualified System.Metrics as EKG + main :: IO () main = do @@ -40,6 +42,7 @@ runApp env (HGEOptionsG rci hgeCmd) = withVersion $$(getVersionFromEnvironment) $ case hgeCmd of HCServe serveOptions -> do (initCtx, initTime) <- initialiseCtx env hgeCmd rci + ekgStore <- liftIO EKG.newStore let shutdownApp = return () -- Catches the SIGTERM signal and initiates a graceful shutdown. -- Graceful shutdown for regular HTTP requests is already implemented in @@ -50,7 +53,7 @@ runApp env (HGEOptionsG rci hgeCmd) = Signals.sigTERM (Signals.CatchOnce (shutdownGracefully initCtx)) Nothing - runHGEServer env serveOptions initCtx Nothing initTime shutdownApp Nothing + runHGEServer env serveOptions initCtx Nothing initTime shutdownApp Nothing ekgStore HCExport -> do (initCtx, _) <- initialiseCtx env hgeCmd rci diff --git a/server/src-lib/Hasura/App.hs b/server/src-lib/Hasura/App.hs index 1504d85f458e3..ae34203f3495b 100644 --- a/server/src-lib/Hasura/App.hs +++ b/server/src-lib/Hasura/App.hs @@ -75,6 +75,8 @@ import Hasura.Session import qualified Hasura.GraphQL.Execute.LiveQuery.Poll as EL import qualified Hasura.GraphQL.Transport.WebSocket.Server as WS import qualified Hasura.Tracing as Tracing +import qualified System.Metrics as EKG + data ExitCode = InvalidEnvironmentVariableOptionsError @@ -308,8 +310,9 @@ runHGEServer -> IO () -- ^ shutdown function -> Maybe EL.LiveQueryPostPollHook + -> EKG.Store -> m () -runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp postPollHook = do +runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp postPollHook ekgStore = do -- Comment this to enable expensive assertions from "GHC.AssertNF". These -- will log lines to STDOUT containing "not in normal form". In the future we -- could try to integrate this into our tests. For now this is a development @@ -351,6 +354,7 @@ runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp pos soResponseInternalErrorsConfig postPollHook _icSchemaCache + ekgStore -- log inconsistent schema objects inconsObjs <- scInconsistentObjs <$> liftIO (getSCFromRef cacheRef) diff --git a/server/src-lib/Hasura/Server/App.hs b/server/src-lib/Hasura/Server/App.hs index 104c39cbcb50b..2501917ae9400 100644 --- a/server/src-lib/Hasura/Server/App.hs +++ b/server/src-lib/Hasura/Server/App.hs @@ -604,9 +604,10 @@ mkWaiApp -> ResponseInternalErrorsConfig -> Maybe EL.LiveQueryPostPollHook -> (RebuildableSchemaCache Run, Maybe UTCTime) + -> EKG.Store -> m HasuraApp mkWaiApp env isoLevel logger sqlGenCtx enableAL pool pgExecCtxCustom ci httpManager mode corsCfg enableConsole consoleAssetsDir - enableTelemetry instanceId apis lqOpts planCacheOptions responseErrorsConfig liveQueryHook (schemaCache, cacheBuiltTime) = do + enableTelemetry instanceId apis lqOpts planCacheOptions responseErrorsConfig liveQueryHook (schemaCache, cacheBuiltTime) ekgStore = do (planCache, schemaCacheRef) <- initialiseCache let getSchemaCache = first lastBuiltSchemaCache <$> readIORef (_scrCache schemaCacheRef) @@ -619,8 +620,6 @@ mkWaiApp env isoLevel logger sqlGenCtx enableAL pool pgExecCtxCustom ci httpMana wsServerEnv <- WS.createWSServerEnv logger pgExecCtx lqState getSchemaCache httpManager corsPolicy sqlGenCtx enableAL planCache - ekgStore <- liftIO EKG.newStore - let serverCtx = ServerCtx { scPGExecCtx = pgExecCtx , scConnInfo = ci From 9082e5f091af4712feb4158825fe74c2f22cfc18 Mon Sep 17 00:00:00 2001 From: Lyndon Maydwell Date: Wed, 19 Aug 2020 07:42:50 +1000 Subject: [PATCH 11/16] PG span tracing improvements (close #465) (#5607) * Better name for Fetch Data * Changing tracing to distinguish PG * Changing trace names * Finer-grained PG tracing * Update WebSocket.hs Co-authored-by: Phil Freeman Co-authored-by: Phil Freeman --- server/src-lib/Hasura/GraphQL/Execute/Query.hs | 2 +- server/src-lib/Hasura/GraphQL/Transport/HTTP.hs | 7 ++++--- server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs | 4 ++-- server/src-lib/Hasura/RQL/DML/RemoteJoin.hs | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/server/src-lib/Hasura/GraphQL/Execute/Query.hs b/server/src-lib/Hasura/GraphQL/Execute/Query.hs index 24f6b19dafb0b..8e94925d06153 100644 --- a/server/src-lib/Hasura/GraphQL/Execute/Query.hs +++ b/server/src-lib/Hasura/GraphQL/Execute/Query.hs @@ -317,7 +317,7 @@ mkLazyRespTx env manager reqHdrs userInfo resolved = do RRSql (PreparedSql q args maybeRemoteJoins) -> do let prepArgs = map fst args case maybeRemoteJoins of - Nothing -> liftTx $ asSingleRowJsonResp q prepArgs + Nothing -> Tracing.trace "Postgres" . liftTx $ asSingleRowJsonResp q prepArgs Just remoteJoins -> executeQueryWithRemoteJoins env manager reqHdrs userInfo q prepArgs remoteJoins return (G.unName $ G.unAlias alias, resp) diff --git a/server/src-lib/Hasura/GraphQL/Transport/HTTP.hs b/server/src-lib/Hasura/GraphQL/Transport/HTTP.hs index 70cd3e37ae9dc..3092873763083 100644 --- a/server/src-lib/Hasura/GraphQL/Transport/HTTP.hs +++ b/server/src-lib/Hasura/GraphQL/Transport/HTTP.hs @@ -168,15 +168,16 @@ runHasuraGQ runHasuraGQ reqId (query, queryParsed) userInfo resolvedOp = do (E.ExecutionCtx logger _ pgExecCtx _ _ _ _ _) <- ask (telemTimeIO, respE) <- withElapsedTime $ runExceptT $ case resolvedOp of - E.ExOpQuery tx genSql asts -> trace "pg" $ do + E.ExOpQuery tx genSql asts -> trace "Query" $ do -- log the generated SQL and the graphql query logQueryLog logger query genSql reqId Tracing.interpTraceT id $ executeQuery queryParsed asts genSql pgExecCtx Q.ReadOnly tx - E.ExOpMutation respHeaders tx -> trace "pg" $ do + E.ExOpMutation respHeaders tx -> trace "Mutate" $ do logQueryLog logger query Nothing reqId ctx <- Tracing.currentContext - (respHeaders,) <$> Tracing.interpTraceT (runLazyTx pgExecCtx Q.ReadWrite . withTraceContext ctx . withUserInfo userInfo) tx + (respHeaders,) <$> + Tracing.interpTraceT (runLazyTx pgExecCtx Q.ReadWrite . withTraceContext ctx . withUserInfo userInfo) tx E.ExOpSubs _ -> throw400 UnexpectedPayload diff --git a/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs b/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs index 6587b6649e130..c1d38e7021b1c 100644 --- a/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs +++ b/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs @@ -363,11 +363,11 @@ onStart env serverEnv wsConn (StartMsg opId q) = catchAndIgnore $ do -> E.ExecOp (Tracing.TraceT (LazyTx QErr)) -> ExceptT () m () runHasuraGQ timerTot telemCacheHit reqId query queryParsed userInfo = \case - E.ExOpQuery opTx genSql asts -> Tracing.trace "pg" $ + E.ExOpQuery opTx genSql asts -> Tracing.trace "Query" $ execQueryOrMut Telem.Query genSql . fmap snd $ Tracing.interpTraceT id $ executeQuery queryParsed asts genSql pgExecCtx Q.ReadOnly opTx -- Response headers discarded over websockets - E.ExOpMutation _ opTx -> Tracing.trace "pg" do + E.ExOpMutation _ opTx -> Tracing.trace "Mutate" do ctx <- Tracing.currentContext execQueryOrMut Telem.Mutation Nothing $ Tracing.interpTraceT (runLazyTx pgExecCtx Q.ReadWrite . withTraceContext ctx . withUserInfo userInfo) opTx diff --git a/server/src-lib/Hasura/RQL/DML/RemoteJoin.hs b/server/src-lib/Hasura/RQL/DML/RemoteJoin.hs index 279e164e2b0d4..b94384050e13d 100644 --- a/server/src-lib/Hasura/RQL/DML/RemoteJoin.hs +++ b/server/src-lib/Hasura/RQL/DML/RemoteJoin.hs @@ -61,7 +61,7 @@ executeQueryWithRemoteJoins -> m EncJSON executeQueryWithRemoteJoins env manager reqHdrs userInfo q prepArgs rjs = do -- Step 1: Perform the query on database and fetch the response - pgRes <- runIdentity . Q.getRow <$> liftTx (Q.rawQE dmlTxErrorHandler q prepArgs True) + pgRes <- runIdentity . Q.getRow <$> Tracing.trace "Postgres" (liftTx (Q.rawQE dmlTxErrorHandler q prepArgs True)) jsonRes <- either (throw500 . T.pack) pure $ AO.eitherDecode pgRes -- Step 2: Traverse through the JSON obtained in above step and generate composite JSON value with remote joins compositeJson <- traverseQueryResponseJSON rjMap jsonRes From ea76e7840eaf2da68c7170a3d55cccf60083954b Mon Sep 17 00:00:00 2001 From: Naveen Naidu Date: Wed, 19 Aug 2020 04:20:15 +0530 Subject: [PATCH 12/16] Tracing.hs: Add B3 headers for tracing (#5517) Use B3-Propagation for Tracing Headers The Tracing headers which we use now X-Hasura- are not standard,though they help us trace requests within our systems but this willbreak/not work when we tend to use the other Trace Recorders.Hence it's better to refactor the code to allow using at least B3 headers for now. i#Refractor injectHTTPContext Co-authored-by: Phil Freeman --- server/graphql-engine.cabal | 2 ++ server/src-lib/Hasura/Tracing.hs | 45 +++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/server/graphql-engine.cabal b/server/graphql-engine.cabal index d20fb55390500..6b420b721e6f8 100644 --- a/server/graphql-engine.cabal +++ b/server/graphql-engine.cabal @@ -110,6 +110,8 @@ library , uuid , vector , vector-builder + , binary + , base16-bytestring -- Logging related , network diff --git a/server/src-lib/Hasura/Tracing.hs b/server/src-lib/Hasura/Tracing.hs index 1e25bbae0dd89..c50fbb008b05a 100644 --- a/server/src-lib/Hasura/Tracing.hs +++ b/server/src-lib/Hasura/Tracing.hs @@ -36,6 +36,9 @@ import qualified Network.HTTP.Client as HTTP import qualified Network.HTTP.Types.Header as HTTP import qualified System.Random as Rand import qualified Web.HttpApiData as HTTP +import qualified Data.Binary as Bin +import qualified Data.ByteString.Base16 as Hex + -- | Any additional human-readable key-value pairs relevant -- to the execution of a block of code. @@ -77,9 +80,9 @@ instance HasReporter m => HasReporter (ExceptT e m) where -- the active span within that trace, and the span's parent, -- unless the current span is the root. data TraceContext = TraceContext - { tcCurrentTrace :: Word64 - , tcCurrentSpan :: Word64 - , tcCurrentParent :: Maybe Word64 + { tcCurrentTrace :: !Word64 + , tcCurrentSpan :: !Word64 + , tcCurrentParent :: !(Maybe Word64) } -- | The 'TraceT' monad transformer adds the ability to keep track of @@ -198,12 +201,29 @@ instance MonadTrace m => MonadTrace (ExceptT e m) where currentReporter = lift currentReporter attachMetadata = lift . attachMetadata +-- | Encode Word64 to 16 character hex string +word64ToHex :: Word64 -> Text +word64ToHex randNum = bsToTxt $ Hex.encode numInBytes + where numInBytes = BL.toStrict (Bin.encode randNum) + +-- | Decode 16 character hex string to Word64 +-- | Hex.Decode returns two tuples: (properly decoded data, string starts at the first invalid base16 sequence) +hexToWord64 :: Text -> Maybe Word64 +hexToWord64 randText = do + let (decoded, leftovers) = Hex.decode $ txtToBs randText + decodedWord64 = Bin.decode $ BL.fromStrict decoded + guard (BS.null leftovers) + pure decodedWord64 + + -- | Inject the trace context as a set of HTTP headers. injectHttpContext :: TraceContext -> [HTTP.Header] injectHttpContext TraceContext{..} = - [ ("X-Hasura-TraceId", fromString (show tcCurrentTrace)) - , ("X-Hasura-SpanId", fromString (show tcCurrentSpan)) - ] + ("X-B3-TraceId", txtToBs $ word64ToHex tcCurrentTrace) + : ("X-B3-SpanId", txtToBs $ word64ToHex tcCurrentSpan) + : [ ("X-B3-ParentSpanId", txtToBs $ word64ToHex parentID) + | parentID <- maybeToList tcCurrentParent + ] -- | Extract the trace and parent span headers from a HTTP request -- and create a new 'TraceContext'. The new context will contain @@ -213,19 +233,20 @@ extractHttpContext :: [HTTP.Header] -> IO (Maybe TraceContext) extractHttpContext hdrs = do freshSpanId <- liftIO Rand.randomIO pure $ TraceContext - <$> (HTTP.parseHeaderMaybe =<< lookup "X-Hasura-TraceId" hdrs) + <$> (hexToWord64 =<< HTTP.parseHeaderMaybe =<< lookup "X-B3-TraceId" hdrs) <*> pure freshSpanId - <*> pure (HTTP.parseHeaderMaybe =<< lookup "X-Hasura-SpanId" hdrs) + <*> pure (hexToWord64 =<< HTTP.parseHeaderMaybe =<< lookup "X-B3-SpanId" hdrs) + -- | Inject the trace context as a JSON value, appropriate for -- storing in (e.g.) an event trigger payload. injectEventContext :: TraceContext -> J.Value -injectEventContext ctx = +injectEventContext TraceContext{..} = J.object - [ "trace_id" J..= tcCurrentTrace ctx - , "span_id" J..= tcCurrentSpan ctx + [ "trace_id" J..= tcCurrentTrace + , "span_id" J..= tcCurrentSpan ] - + -- | Extract a trace context from an event trigger payload. extractEventContext :: J.Value -> IO (Maybe TraceContext) extractEventContext e = do From fa944b18dd32e4e6a3ddbb3ef04c99bad48f4574 Mon Sep 17 00:00:00 2001 From: Naveen Naidu Date: Wed, 19 Aug 2020 22:23:46 +0530 Subject: [PATCH 13/16] Fix strigified JSON for the prepared_argument in query_log (#5615) Fix the `toJson` instance of `PreparedSql` to use `pgScalarValueToJson` instead of `txtEncodedPGVal` Fixes: https://github.com/hasura/graphql-engine/issues/5582 --- server/src-lib/Hasura/GraphQL/Execute/Query.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src-lib/Hasura/GraphQL/Execute/Query.hs b/server/src-lib/Hasura/GraphQL/Execute/Query.hs index 8e94925d06153..e0d1391795d11 100644 --- a/server/src-lib/Hasura/GraphQL/Execute/Query.hs +++ b/server/src-lib/Hasura/GraphQL/Execute/Query.hs @@ -281,7 +281,7 @@ data PreparedSql instance J.ToJSON PreparedSql where toJSON (PreparedSql q prepArgs _) = J.object [ "query" J..= Q.getQueryText q - , "prepared_arguments" J..= map (txtEncodedPGVal . snd) prepArgs + , "prepared_arguments" J..= map (pgScalarValueToJson . snd) prepArgs ] -- | Intermediate reperesentation of a computed SQL statement and prepared From 95750b61f9605f690ab6f156dcdb5db58492fca2 Mon Sep 17 00:00:00 2001 From: Kentaro Suzuki <33363411+kentaro84207@users.noreply.github.com> Date: Thu, 20 Aug 2020 16:40:17 +0900 Subject: [PATCH 14/16] console: fix folding of invocation information in redeliver event modal (close #5515) (#5559) --- .../Services/Events/Common/Components/RedeliverEvent.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/console/src/components/Services/Events/Common/Components/RedeliverEvent.tsx b/console/src/components/Services/Events/Common/Components/RedeliverEvent.tsx index e6a1eb34810af..f9baea1257576 100644 --- a/console/src/components/Services/Events/Common/Components/RedeliverEvent.tsx +++ b/console/src/components/Services/Events/Common/Components/RedeliverEvent.tsx @@ -111,6 +111,7 @@ const RedeliverEvent: React.FC = ({ dispatch, eventId }) => { resizable manual showPagination={false} + freezeWhenExpanded SubComponent={(logRow: any) => { const finalIndex = logRow.index; const finalRow = logs[finalIndex]; From 72ecaed8d14ad449b2bb3262e86a6ce3821b80c1 Mon Sep 17 00:00:00 2001 From: Rishichandra Wawhal Date: Thu, 20 Aug 2020 16:06:08 +0530 Subject: [PATCH 15/16] console: remove postinstall script from package.json (#5630) --- console/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/console/package.json b/console/package.json index 8d62a5e2bad2f..82e8329fe7e5e 100644 --- a/console/package.json +++ b/console/package.json @@ -19,7 +19,6 @@ "build": "webpack --progress -p --colors --display-error-details --config webpack/prod.config.js", "server-build": "make server-build", "build-unused": "webpack --verbose --colors --display-error-details --config webpack/prod.config.js --json | webpack-unused -s src", - "postinstall": "webpack --display-error-details --config webpack/prod.config.js", "cypress": "cypress open", "test": "cypress run --spec 'cypress/integration/**/**/test.ts' --key $CYPRESS_KEY --parallel --record", "lint": "eslint -c .eslintrc src --ext .js,.ts,.tsx", From b93da39b5c6764b00157ee59d35a414f08b7253f Mon Sep 17 00:00:00 2001 From: Aleksandra Sikora Date: Thu, 20 Aug 2020 16:32:45 +0200 Subject: [PATCH 16/16] console: fix `remove column` test (#5622) --- console/cypress/integration/data/modify/spec.ts | 14 +++++++++++--- .../Services/Data/TableModify/PrimaryKeyEditor.js | 8 ++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/console/cypress/integration/data/modify/spec.ts b/console/cypress/integration/data/modify/spec.ts index bdb0477dc6279..6fea244502abb 100644 --- a/console/cypress/integration/data/modify/spec.ts +++ b/console/cypress/integration/data/modify/spec.ts @@ -214,12 +214,20 @@ export const passModifyPkey = () => { cy.get(getElementFromAlias('modify-table-edit-pks')).click(); cy.get(getElementFromAlias('primary-key-select-1')).select('1'); cy.get(getElementFromAlias('modify-table-pks-save')).click(); + cy.get(getElementFromAlias('pk-config-text')).within(() => { + cy.get('b').contains(getColName(0)); + cy.get('b').contains('id'); + }); cy.wait(5000); - // TODO - // test disappearance expect - // (cy.get(getElementFromAlias('modify-table-column-1-remove'))).not.to.exist; + cy.get(getElementFromAlias('remove-pk-column-1')).click(); cy.get(getElementFromAlias('modify-table-pks-save')).click(); + cy.get(getElementFromAlias('pk-config-text')).within(() => { + cy.get('b').contains('id'); + }); + cy.get(getElementFromAlias('pk-config-text')).within(() => { + cy.get('b').should('not.contain', getColName(0)); + }); cy.get(getElementFromAlias('modify-table-close-pks')).click(); cy.wait(3000); }; diff --git a/console/src/components/Services/Data/TableModify/PrimaryKeyEditor.js b/console/src/components/Services/Data/TableModify/PrimaryKeyEditor.js index 4ab8a5a95d590..08ecaf74012c3 100644 --- a/console/src/components/Services/Data/TableModify/PrimaryKeyEditor.js +++ b/console/src/components/Services/Data/TableModify/PrimaryKeyEditor.js @@ -55,7 +55,9 @@ const PrimaryKeyEditor = ({ ); // label next to the button when the editor is expanded - const pkEditorExpandedLabel = () =>
{pkConfigText}
; + const pkEditorExpandedLabel = () => ( +
{pkConfigText}
+ ); // expanded editor content const pkEditorExpanded = () => ( @@ -95,7 +97,9 @@ const PrimaryKeyEditor = ({ ); }; - useEffect(setPkEditState, [columns]); + useEffect(() => { + setPkEditState(); + }, [columns.length]); // remove const onRemove = () => {