graphql-engine/server/src-lib/Hasura/Server
Anon Ray 06b599b747 server: multitenant metadata storage
The metadata storage implementation for graphql-engine-multitenant.

- It uses a centralized PG database to store metadata of all tenants (instead of per tenant database)
- Similarly, it uses a single schema-sync listener thread per MT worker (instead of listener thread per tenant) (PS: although, the processor thread is spawned per tenant)
- 2 new flags are introduced - `--metadataDatabaseUrl` and (optional) `--metadataDatabaseRetries`

Internally, a "metadata mode" is introduced to indicate an external/managed store vs a store managed by each pro-server.

To run :
- obtain the schema file (located at `pro/server/res/cloud/metadata_db_schema.sql`)
- apply the schema on a PG database
- set the `--metadataDatabaseUrl` flag to point to the above database
- run the MT executable

The schema (and its migrations) for the metadata db is managed outside the MT worker.

### New metadata

The following is the new portion of `Metadata` added :

```yaml
version: 3
metrics_config:
  analyze_query_variables: true
  analyze_response_body: false
api_limits:
  disabled: false
  depth_limit:
    global: 5
    per_role:
      user: 7
      editor: 9
  rate_limit:
    per_role:
      user:
        unique_params:
        - x-hasura-user-id
        - x-hasura-team-id
        max_reqs_per_min: 20
    global:
      unique_params: IP
      max_reqs_per_min: 10
```

- In Pro, the code around fetching/updating/syncing pro-config is removed
- That also means, `hdb_pro_catalog` for keeping the config cache is not required. Hence the `hdb_pro_catalog` is also removed
- The required config comes from metadata / schema cache

### New Metadata APIs

- `set_api_limits`
- `remove_api_limits`
- `set_metrics_config`
- `remove_metrics_config`

#### `set_api_limits`

```yaml
type: set_api_limits
args:
  disabled: false
  depth_limit:
    global: 5
    per_role:
      user: 7
      editor: 9
  rate_limit:
    per_role:
      anonymous:
         max_reqs_per_min: 10
         unique_params: "ip"
      editor:
        max_reqs_per_min: 30
        unique_params:
        - x-hasura-user-id
      user:
        unique_params:
        - x-hasura-user-id
        - x-hasura-team-id
        max_reqs_per_min: 20
    global:
      unique_params: IP
      max_reqs_per_min: 10
```

#### `remove_api_limits`

```yaml
type: remove_api_limits
args: {}
```

#### `set_metrics_config`

```yaml
type: set_metrics_config
args:
  analyze_query_variables: true
  analyze_response_body: false
```

#### `remove_metrics_config`

```yaml
type: remove_metrics_config
args: {}
```

#### TODO
- [x] on-prem pro implementation for `MonadMetadataStorage`
- [x] move the project config from Lux to pro metadata (PR: #379)
- [ ] console changes for pro config/api limits, subscription workers (cc @soorajshankar @beerose)
- [x] address other minor TODOs
  - [x] TxIso for `MonadSourceResolver`
  - [x] enable EKG connection pool metrics
  - [x] add logging of connection info when sources are added?
  - [x] confirm if the `buildReason` for schema cache is correct
- [ ] testing
- [x] 1.3 -> 1.4 cloud migration script (#465; PR: #508)
  - [x] one-time migration of existing metadata from users' db to centralized PG
  - [x] one-time migration of pro project config + api limits + regression tests from metrics API  to metadata
- [ ] integrate with infra team (WIP - cc @hgiasac)
  - [x] benchmark with 1000+ tenants + each tenant making read/update metadata query every second (PR: https://github.com/hasura/graphql-engine-mono/pull/411)
  - [ ] benchmark with few tenants having large metadata (100+ tables etc.)
  - [ ] when user moves regions (https://github.com/hasura/lux/issues/1717)
    - [ ] metadata has to be migrated from one regional PG to another
    - [ ] migrate metrics data as well ?
      - [ ] operation logs
      - [ ] regression test runs

- [ ] find a way to share the schema files with the infra team

Co-authored-by: Naveen Naidu <30195193+Naveenaidu@users.noreply.github.com>
GitOrigin-RevId: 39e8361f2c0e96e0f9e8f8fb45e6cc14857f31f1
2021-02-11 17:55:21 +00:00
..
API server: multitenant metadata storage 2021-02-11 17:55:21 +00:00
Auth pass gql requests into auth webhook POST body (#149) 2021-02-03 07:11:39 +00:00
Init server: new function permissions layer 2021-01-29 05:49:09 +00:00
Migrate server: move Hasura.SQL to Hasura.Backends.Postgres (#6053) 2020-10-27 13:53:49 +00:00
Telemetry server: simplify JSON instances 2021-01-19 19:15:42 +00:00
App.hs server: multitenant metadata storage 2021-02-11 17:55:21 +00:00
Auth.hs pass gql requests into auth webhook POST body (#149) 2021-02-03 07:11:39 +00:00
CheckUpdates.hs server: simplify JSON instances 2021-01-19 19:15:42 +00:00
Compression.hs server: move Hasura.SQL to Hasura.Backends.Postgres (#6053) 2020-10-27 13:53:49 +00:00
Cors.hs server: simplify JSON instances 2021-01-19 19:15:42 +00:00
Init.hs server: new function permissions layer 2021-01-29 05:49:09 +00:00
Logging.hs server: simplify JSON instances 2021-01-19 19:15:42 +00:00
Middleware.hs Migrate to GHC 8.10, upgrade dependencies. Closes #4517 2020-05-13 19:13:02 -04:00
Migrate.hs server: multitenant metadata storage 2021-02-11 17:55:21 +00:00
Rest.hs server: support restified versions of graphql queries (#303) 2021-01-29 01:03:35 +00:00
SchemaUpdate.hs server: multitenant metadata storage 2021-02-11 17:55:21 +00:00
Telemetry.hs server: new function permissions layer 2021-01-29 05:49:09 +00:00
Types.hs server: metadata storage abstraction for scheduled triggers 2020-11-25 10:57:38 +00:00
Utils.hs Merge pull request #113 from hasura/karthikeyan/remote-schema-permissions 2020-12-21 09:12:35 +00:00
Version.hs server: make more use of hlint (#6059) 2020-10-28 16:40:33 +00:00