2022-03-16 03:39:21 +03:00
{- # LANGUAGE QuasiQuotes # -}
{- # LANGUAGE TemplateHaskell # -}
2020-10-07 11:55:39 +03:00
{- # LANGUAGE UndecidableInstances # -}
2022-08-17 04:07:44 +03:00
{- # LANGUAGE ViewPatterns # -}
2019-11-26 15:14:21 +03:00
2022-09-22 16:56:50 +03:00
-- | Imported by 'server/src-exec/Main.hs'.
2021-11-04 19:08:33 +03:00
module Hasura.App
2023-01-06 12:33:13 +03:00
( ExitCode ( AuthConfigurationError , DatabaseMigrationError , DowngradeProcessError , MetadataCleanError , MetadataExportError , SchemaCacheInitError ) ,
2021-11-04 19:08:33 +03:00
ExitException ( ExitException ) ,
2022-02-24 02:40:35 +03:00
GlobalCtx ( .. ) ,
2021-11-04 19:08:33 +03:00
PGMetadataStorageAppT ( runPGMetadataStorageAppT ) ,
accessDeniedErrMsg ,
flushLogger ,
getCatalogStateTx ,
initGlobalCtx ,
2023-01-06 12:33:13 +03:00
initAuthMode ,
initialiseServerCtx ,
initSubscriptionsState ,
2021-11-04 19:08:33 +03:00
migrateCatalogSchema ,
mkLoggers ,
mkPGLogger ,
notifySchemaCacheSyncTx ,
parseArgs ,
2022-03-14 21:31:46 +03:00
throwErrExit ,
throwErrJExit ,
2021-11-04 19:08:33 +03:00
printJSON ,
printYaml ,
readTlsAllowlist ,
resolvePostgresConnInfo ,
runHGEServer ,
setCatalogStateTx ,
-- * Exported for testing
mkHGEServer ,
mkPgSourceResolver ,
2022-01-04 14:53:50 +03:00
mkMSSQLSourceResolver ,
2021-11-04 19:08:33 +03:00
)
where
2019-11-26 15:14:21 +03:00
2021-09-24 01:56:37 +03:00
import Control.Concurrent.Async.Lifted.Safe qualified as LA
import Control.Concurrent.Extended qualified as C
import Control.Concurrent.STM qualified as STM
import Control.Concurrent.STM.TVar ( readTVarIO )
import Control.Exception ( bracket_ , throwIO )
import Control.Monad.Catch
( Exception ,
MonadCatch ,
MonadMask ,
MonadThrow ,
onException ,
)
import Control.Monad.Morph ( hoist )
import Control.Monad.STM ( atomically )
import Control.Monad.Stateless
import Control.Monad.Trans.Control ( MonadBaseControl ( .. ) )
2022-12-19 15:45:21 +03:00
import Control.Monad.Trans.Managed ( ManagedT ( .. ) , allocate , allocate_ )
2022-06-07 10:08:53 +03:00
import Control.Retry qualified as Retry
2021-09-24 01:56:37 +03:00
import Data.Aeson qualified as A
import Data.ByteString.Char8 qualified as BC
2022-09-13 18:35:58 +03:00
import Data.ByteString.Lazy qualified as BL
2021-09-24 01:56:37 +03:00
import Data.ByteString.Lazy.Char8 qualified as BLC
import Data.Environment qualified as Env
import Data.FileEmbed ( makeRelativeToProject )
import Data.HashMap.Strict qualified as HM
2022-06-30 14:26:10 +03:00
import Data.Set.NonEmpty qualified as NE
2021-09-24 01:56:37 +03:00
import Data.Text qualified as T
import Data.Time.Clock ( UTCTime )
import Data.Time.Clock qualified as Clock
import Data.Yaml qualified as Y
2022-10-17 11:04:54 +03:00
import Database.MSSQL.Pool qualified as MSPool
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
import Database.PG.Query qualified as PG
2022-10-17 11:04:54 +03:00
import Database.PG.Query qualified as Q
2021-09-24 01:56:37 +03:00
import GHC.AssertNF.CPP
2022-01-04 14:53:50 +03:00
import Hasura.Backends.MSSQL.Connection
2021-09-24 01:56:37 +03:00
import Hasura.Backends.Postgres.Connection
import Hasura.Base.Error
import Hasura.Eventing.Common
import Hasura.Eventing.EventTrigger
import Hasura.Eventing.ScheduledTrigger
import Hasura.GraphQL.Execute
( ExecutionStep ( .. ) ,
MonadGQLExecutionCheck ( .. ) ,
checkQueryInAllowlist ,
)
import Hasura.GraphQL.Execute.Action
import Hasura.GraphQL.Execute.Action.Subscription
import Hasura.GraphQL.Execute.Backend qualified as EB
2022-03-21 13:39:49 +03:00
import Hasura.GraphQL.Execute.Subscription.Poll qualified as ES
2023-01-06 12:33:13 +03:00
import Hasura.GraphQL.Execute.Subscription.State qualified as ES
2021-09-24 01:56:37 +03:00
import Hasura.GraphQL.Logging ( MonadQueryLog ( .. ) )
2022-07-14 20:57:28 +03:00
import Hasura.GraphQL.Schema.Options qualified as Options
2021-09-24 01:56:37 +03:00
import Hasura.GraphQL.Transport.HTTP
( CacheStoreSuccess ( CacheStoreSkipped ) ,
MonadExecuteQuery ( .. ) ,
)
import Hasura.GraphQL.Transport.HTTP.Protocol ( toParsed )
import Hasura.GraphQL.Transport.WebSocket.Server qualified as WS
import Hasura.Logging
import Hasura.Metadata.Class
2022-11-23 19:40:21 +03:00
import Hasura.PingSources
2021-09-24 01:56:37 +03:00
import Hasura.Prelude
import Hasura.QueryTags
2022-09-15 14:45:14 +03:00
import Hasura.RQL.DDL.EventTrigger ( MonadEventLogCleanup ( .. ) )
2021-09-24 01:56:37 +03:00
import Hasura.RQL.DDL.Schema.Cache
import Hasura.RQL.DDL.Schema.Cache.Common
import Hasura.RQL.DDL.Schema.Catalog
2022-04-27 16:57:28 +03:00
import Hasura.RQL.Types.Allowlist
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.Common
2021-09-24 01:56:37 +03:00
import Hasura.RQL.Types.Eventing.Backend
2022-04-27 16:57:28 +03:00
import Hasura.RQL.Types.Metadata
import Hasura.RQL.Types.Network
2022-10-20 04:32:54 +03:00
import Hasura.RQL.Types.ResizePool
2022-04-27 16:57:28 +03:00
import Hasura.RQL.Types.SchemaCache
import Hasura.RQL.Types.SchemaCache.Build
import Hasura.RQL.Types.Source
2021-09-24 01:56:37 +03:00
import Hasura.SQL.AnyBackend qualified as AB
2022-04-27 16:57:28 +03:00
import Hasura.SQL.Backend
2021-09-24 01:56:37 +03:00
import Hasura.Server.API.Query ( requiresAdmin )
import Hasura.Server.App
import Hasura.Server.Auth
import Hasura.Server.CheckUpdates ( checkForUpdates )
2023-01-26 12:39:49 +03:00
import Hasura.Server.Init hiding ( checkFeatureFlag )
2021-09-29 19:20:06 +03:00
import Hasura.Server.Limits
2021-09-24 01:56:37 +03:00
import Hasura.Server.Logging
import Hasura.Server.Metrics ( ServerMetrics ( .. ) )
2021-11-10 17:34:22 +03:00
import Hasura.Server.Migrate ( migrateCatalog )
2022-07-24 00:18:01 +03:00
import Hasura.Server.Prometheus
( PrometheusMetrics ( .. ) ,
decWarpThreads ,
incWarpThreads ,
)
2022-03-09 01:59:28 +03:00
import Hasura.Server.SchemaCacheRef
( SchemaCacheRef ,
getSchemaCache ,
initialiseSchemaCacheRef ,
logInconsistentMetadata ,
)
2021-09-24 01:56:37 +03:00
import Hasura.Server.SchemaUpdate
import Hasura.Server.Telemetry
import Hasura.Server.Types
import Hasura.Server.Version
import Hasura.Session
2022-11-22 04:36:35 +03:00
import Hasura.ShutdownLatch
2021-09-24 01:56:37 +03:00
import Hasura.Tracing qualified as Tracing
2023-01-06 12:33:13 +03:00
import Network.HTTP.Client qualified as HTTP
2022-09-27 12:24:19 +03:00
import Network.HTTP.Client.Blocklisting ( Blocklist )
server: http ip blocklist (closes #2449)
## Description
This PR is in reference to #2449 (support IP blacklisting for multitenant)
*RFC Update: Add support for IPv6 blocking*
### Solution and Design
Using [http-client-restricted](https://hackage.haskell.org/package/http-client-restricted) package, we're creating the HTTP manager with restricting capabilities. The IPs can be supplied from the CLI arguments as `--ipv4BlocklistCidrs cidr1, cidr2...` or `--disableDefaultIPv4Blocklist` for a default IP list. The new manager will block all requests to the provided CIDRs.
We are extracting the error message string to show the end-user that given IP is blocked from being set as a webhook. There are 2 ways to extract the error message "connection to IP address is blocked". Given below are the responses from event trigger to a blocked IP for these implementations:
- 6d74fde316f61e246c861befcca5059d33972fa7 - We return the error message string as a HTTPErr(HOther) from `Hasura/Eventing/HTTP.hs`.
```
{
"data": {
"message": "blocked connection to private IP address "
},
"version": "2",
"type": "client_error"
}
```
- 88e17456345cbb449a5ecd4877c84c9f319dbc25 - We case match on HTTPExceptionContent for InternaException in `Hasura/HTTP.hs` and extract the error message string from it. (this is implemented as it handles all the cases where pro engine makes webhook requests)
```
{
"data": {
"message": {
"type": "http_exception",
"message": "blocked connection to private IP address ",
"request": {
"secure": false,
"path": "/webhook",
"responseTimeout": "ResponseTimeoutMicro 60000000",
"queryString": "",
"method": "POST",
"requestHeaders": {
"Content-Type": "application/json",
"X-B3-ParentSpanId": "5ae6573edb2a6b36",
"X-B3-TraceId": "29ea7bd6de6ebb8f",
"X-B3-SpanId": "303137d9f1d4f341",
"User-Agent": "hasura-graphql-engine/cerebushttp-ip-blacklist-a793a0e41-dirty"
},
"host": "139.59.90.109",
"port": 8000
}
}
},
"version": "2",
"type": "client_error"
}
```
### Steps to test and verify
The restricted IPs can be used as webhooks in event triggers, and hasura will return an error message in reponse.
### Limitations, known bugs & workarounds
- The `http-client-restricted` has a needlessly complex interface, and puts effort into implementing proxy support which we don't want, so we've inlined a stripped down version.
- Performance constraint: As the blocking is checked for each request, if a long list of blocked CIDRs is supplied, iterating through all of them is not what we would prefer. Using trie is suggested to overcome this. (Added to RFC)
- Calls to Lux endpoints are inconsistent: We use either the http manager from the ProServeCtx which is unrestricted, or the http manager from the ServeCtx which is restricted (the latter through the instances for MonadMetadataApiAuthorization and UserAuthentication). (The failure scenario here would be: cloud sets PRO_ENDPOINT to something that resolves to an internal address, and then restricted requests to those endpoints fail, causing auth to fail on user requests. This is about HTTP requests to lux auth endpoints.)
## Changelog
- ✅ `CHANGELOG.md` is updated with user-facing content relevant to this PR.
## Affected components
- ✅ Server
- ✅ Tests
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3186
Co-authored-by: Robert <132113+robx@users.noreply.github.com>
GitOrigin-RevId: 5bd2de2d028bc416b02c99e996c7bebce56fb1e7
2022-02-25 16:29:55 +03:00
import Network.HTTP.Client.CreateManager ( mkHttpManager )
2021-09-24 01:56:37 +03:00
import Network.HTTP.Client.Manager ( HasHttpManagerM ( .. ) )
2021-10-20 23:01:22 +03:00
import Network.Wai ( Application )
2021-09-24 01:56:37 +03:00
import Network.Wai.Handler.Warp qualified as Warp
import Options.Applicative
2022-09-21 21:01:48 +03:00
import Refined ( unrefine )
2021-09-24 01:56:37 +03:00
import System.Log.FastLogger qualified as FL
import System.Metrics qualified as EKG
import System.Metrics.Gauge qualified as EKG . Gauge
import Text.Mustache.Compile qualified as M
import Web.Spock.Core qualified as Spock
2021-09-23 15:37:56 +03:00
2020-07-14 22:00:58 +03:00
data ExitCode
2021-09-24 01:56:37 +03:00
= -- these are used during server initialization:
InvalidEnvironmentVariableOptionsError
2020-07-14 22:00:58 +03:00
| InvalidDatabaseConnectionParamsError
| AuthConfigurationError
| EventSubSystemError
2020-12-21 21:56:00 +03:00
| DatabaseMigrationError
2021-09-24 01:56:37 +03:00
| -- | used by MT because it initialises the schema cache only
-- these are used in app/Main.hs:
SchemaCacheInitError
2020-07-14 22:00:58 +03:00
| MetadataExportError
| MetadataCleanError
| ExecuteProcessError
| DowngradeProcessError
2021-09-24 01:56:37 +03:00
deriving ( Show )
2020-07-14 22:00:58 +03:00
2021-09-24 01:56:37 +03:00
data ExitException = ExitException
{ eeCode :: ! ExitCode ,
eeMessage :: ! BC . ByteString
}
deriving ( Show )
2020-07-14 22:00:58 +03:00
instance Exception ExitException
2022-03-14 21:31:46 +03:00
throwErrExit :: ( MonadIO m ) => forall a . ExitCode -> String -> m a
throwErrExit reason = liftIO . throwIO . ExitException reason . BC . pack
2020-07-14 22:00:58 +03:00
2022-03-14 21:31:46 +03:00
throwErrJExit :: ( A . ToJSON a , MonadIO m ) => forall b . ExitCode -> a -> m b
throwErrJExit reason = liftIO . throwIO . ExitException reason . BLC . toStrict . A . encode
2019-11-26 15:14:21 +03:00
2022-07-15 11:54:27 +03:00
--------------------------------------------------------------------------------
-- TODO(SOLOMON): Move Into `Hasura.Server.Init`. Unable to do so
-- currently due `throwErrExit`.
2019-11-26 15:14:21 +03:00
2022-09-22 16:56:50 +03:00
-- | Parse cli arguments to graphql-engine executable.
2023-02-20 16:43:34 +03:00
parseArgs :: EnabledLogTypes impl => Env . Environment -> IO ( HGEOptions ( ServeOptions impl ) )
parseArgs env = do
2019-11-26 15:14:21 +03:00
rawHGEOpts <- execParser opts
2023-02-20 16:43:34 +03:00
let eitherOpts = runWithEnv ( Env . toList env ) $ mkHGEOptions rawHGEOpts
2022-03-14 21:31:46 +03:00
onLeft eitherOpts $ throwErrExit InvalidEnvironmentVariableOptionsError
2019-11-26 15:14:21 +03:00
where
2021-09-24 01:56:37 +03:00
opts =
info
2022-07-15 11:54:27 +03:00
( helper <*> parseHgeOpts )
2021-09-24 01:56:37 +03:00
( fullDesc
2022-06-23 04:27:00 +03:00
<> header " Hasura GraphQL Engine: Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events. "
2021-09-24 01:56:37 +03:00
<> footerDoc ( Just mainCmdFooter )
)
2022-07-15 11:54:27 +03:00
--------------------------------------------------------------------------------
2019-11-26 15:14:21 +03:00
printJSON :: ( A . ToJSON a , MonadIO m ) => a -> m ()
printJSON = liftIO . BLC . putStrLn . A . encode
printYaml :: ( A . ToJSON a , MonadIO m ) => a -> m ()
printYaml = liftIO . BC . putStrLn . Y . encode
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
mkPGLogger :: Logger Hasura -> PG . PGLogger
mkPGLogger ( Logger logger ) ( PG . PLERetryMsg msg ) =
2019-11-26 15:14:21 +03:00
logger $ PGLog LevelWarn msg
2020-11-24 09:10:04 +03:00
-- | Context required for all graphql-engine CLI commands
2021-09-24 01:56:37 +03:00
data GlobalCtx = GlobalCtx
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
{ _gcMetadataDbConnInfo :: ! PG . ConnInfo ,
2021-09-24 01:56:37 +03:00
-- | --database-url option, @'UrlConf' is required to construct default source configuration
2021-01-07 12:04:22 +03:00
-- and optional retries
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
_gcDefaultPostgresConnInfo :: ! ( Maybe ( UrlConf , PG . ConnInfo ) , Maybe Int )
2020-11-24 09:10:04 +03:00
}
2019-11-26 15:14:21 +03:00
2021-08-24 10:36:32 +03:00
readTlsAllowlist :: SchemaCacheRef -> IO [ TlsAllow ]
2022-03-09 01:59:28 +03:00
readTlsAllowlist scRef = scTlsAllowlist <$> getSchemaCache scRef
2021-08-24 10:36:32 +03:00
2021-09-24 01:56:37 +03:00
initGlobalCtx ::
( MonadIO m ) =>
Env . Environment ->
-- | the metadata DB URL
Maybe String ->
-- | the user's DB URL
PostgresConnInfo ( Maybe UrlConf ) ->
m GlobalCtx
2020-12-28 15:56:00 +03:00
initGlobalCtx env metadataDbUrl defaultPgConnInfo = do
let PostgresConnInfo dbUrlConf maybeRetries = defaultPgConnInfo
2021-02-11 20:54:25 +03:00
mkConnInfoFromSource dbUrl = do
resolvePostgresConnInfo env dbUrl maybeRetries
mkConnInfoFromMDb mdbUrl =
let retries = fromMaybe 1 maybeRetries
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
in ( PG . ConnInfo retries . PG . CDDatabaseURI . txtToBs . T . pack ) mdbUrl
2021-02-11 20:54:25 +03:00
mkGlobalCtx mdbConnInfo sourceConnInfo =
2022-02-24 02:40:35 +03:00
pure $ GlobalCtx mdbConnInfo ( sourceConnInfo , maybeRetries )
2021-01-07 12:04:22 +03:00
2021-02-11 20:54:25 +03:00
case ( metadataDbUrl , dbUrlConf ) of
( Nothing , Nothing ) ->
2022-03-14 21:31:46 +03:00
throwErrExit
2021-09-24 01:56:37 +03:00
InvalidDatabaseConnectionParamsError
" Fatal Error: Either of --metadata-database-url or --database-url option expected "
2021-02-11 20:54:25 +03:00
-- If no metadata storage specified consider use default database as
-- metadata storage
( Nothing , Just dbUrl ) -> do
connInfo <- mkConnInfoFromSource dbUrl
mkGlobalCtx connInfo $ Just ( dbUrl , connInfo )
( Just mdUrl , Nothing ) -> do
let mdConnInfo = mkConnInfoFromMDb mdUrl
mkGlobalCtx mdConnInfo Nothing
( Just mdUrl , Just dbUrl ) -> do
srcConnInfo <- mkConnInfoFromSource dbUrl
let mdConnInfo = mkConnInfoFromMDb mdUrl
mkGlobalCtx mdConnInfo ( Just ( dbUrl , srcConnInfo ) )
2020-11-24 09:10:04 +03:00
2020-11-25 13:56:44 +03:00
-- | An application with Postgres database as a metadata storage
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
newtype PGMetadataStorageAppT m a = PGMetadataStorageAppT { runPGMetadataStorageAppT :: ( PG . PGPool , PG . PGLogger ) -> m a }
2021-09-24 01:56:37 +03:00
deriving
( Functor ,
Applicative ,
Monad ,
MonadIO ,
Rewrite OpenAPI
### Description
This PR rewrites OpenAPI to be more idiomatic. Some noteworthy changes:
- we accumulate all required information during the Analyze phase, to avoid having to do a single lookup in the schema cache during the OpenAPI generation phase (we now only need the schema cache as input to run the analysis)
- we no longer build intermediary endpoint information and aggregate it, we directly build the the `PathItem` for each endpoint; additionally, that means we no longer have to assume that different methods have the same metadata
- we no longer have to first declare types, then craft references: we do everything in one step
- we now properly deal with nullability by treating "typeName" and "typeName!" as different
- we add a bunch of additional fields in the generated "schema", such as title
- we do now support enum values in both input and output positions
- checking whether the request body is required is now performed on the fly rather than by introspecting the generated schema
- the methods in the file are sorted by topic
### Controversial point
However, this PR creates some additional complexity, that we might not want to keep. The main complexity is _knot-tying_: to avoid lookups when generating the OpenAPI, it builds an actual graph of input types, which means that we need something similar to (but simpler than) `MonadSchema`, to avoid infinite recursions when analyzing the input types of a query. To do this, this PR introduces `CircularT`, a lesser `SchemaT` that aims at avoiding ever having to reinvent this particular wheel ever again.
### Remaining work
- [x] fix existing tests (they are all failing due to some of the schema changes)
- [ ] add tests to cover the new features:
- [x] tests for `CircularT`
- [ ] tests for enums in output schemas
- [x] extract / document `CircularT` if we wish to keep it
- [x] add more comments to `OpenAPI`
- [x] have a second look at `buildVariableSchema`
- [x] fix all missing diagnostics in `Analyze`
- [x] add a Changelog entry?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4654
Co-authored-by: David Overton <7734777+dmoverton@users.noreply.github.com>
GitOrigin-RevId: f4a9191f22dfcc1dccefd6a52f5c586b6ad17172
2022-06-30 15:55:56 +03:00
MonadFix ,
2021-09-24 01:56:37 +03:00
MonadCatch ,
MonadThrow ,
MonadMask ,
HasHttpManagerM ,
HasServerConfigCtx ,
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
MonadReader ( PG . PGPool , PG . PGLogger ) ,
2022-05-24 10:21:39 +03:00
MonadBase b ,
MonadBaseControl b
2021-09-24 01:56:37 +03:00
)
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
via ( ReaderT ( PG . PGPool , PG . PGLogger ) m )
2022-05-24 10:21:39 +03:00
deriving
( MonadTrans
)
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
via ( ReaderT ( PG . PGPool , PG . PGLogger ) )
2020-12-28 15:56:00 +03:00
2021-09-24 01:56:37 +03:00
resolvePostgresConnInfo ::
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
( MonadIO m ) => Env . Environment -> UrlConf -> Maybe Int -> m PG . ConnInfo
2020-12-28 15:56:00 +03:00
resolvePostgresConnInfo env dbUrlConf maybeRetries = do
dbUrlText <-
runExcept ( resolveUrlConf env dbUrlConf ) ` onLeft ` \ err ->
2022-03-14 21:31:46 +03:00
liftIO ( throwErrJExit InvalidDatabaseConnectionParamsError err )
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
pure $ PG . ConnInfo retries $ PG . CDDatabaseURI $ txtToBs dbUrlText
2020-12-28 15:56:00 +03:00
where
retries = fromMaybe 1 maybeRetries
2020-11-24 09:10:04 +03:00
2023-01-06 12:33:13 +03:00
initAuthMode ::
( C . ForkableMonadIO m , Tracing . HasReporter m ) =>
ServeOptions impl ->
HTTP . Manager ->
Logger Hasura ->
m AuthMode
initAuthMode ServeOptions { .. } httpManager logger = do
authModeRes <-
runExceptT $
setupAuthMode
soAdminSecret
soAuthHook
soJwtSecret
soUnAuthRole
logger
httpManager
authMode <- onLeft authModeRes ( throwErrExit AuthConfigurationError . T . unpack )
-- forking a dedicated polling thread to dynamically get the latest JWK settings
-- set by the user and update the JWK accordingly. This will help in applying the
-- updates without restarting HGE.
_ <- C . forkImmortal " update JWK " logger $ updateJwkCtx authMode httpManager logger
return authMode
initSubscriptionsState ::
ServeOptions impl ->
Logger Hasura ->
Maybe ES . SubscriptionPostPollHook ->
IO ES . SubscriptionsState
initSubscriptionsState ServeOptions { .. } logger liveQueryHook = ES . initSubscriptionsState soLiveQueryOpts soStreamingQueryOpts postPollHook
where
postPollHook = fromMaybe ( ES . defaultSubscriptionPostPollHook logger ) liveQueryHook
2020-11-24 09:10:04 +03:00
-- | Initializes or migrates the catalog and returns the context required to start the server.
2023-01-06 12:33:13 +03:00
initialiseServerCtx ::
2021-10-13 19:38:56 +03:00
( C . ForkableMonadIO m , MonadCatch m ) =>
2021-09-24 01:56:37 +03:00
Env . Environment ->
GlobalCtx ->
ServeOptions Hasura ->
2023-01-06 12:33:13 +03:00
Maybe ES . SubscriptionPostPollHook ->
2022-03-09 01:59:28 +03:00
ServerMetrics ->
2023-01-06 12:33:13 +03:00
PrometheusMetrics ->
Tracing . SamplingPolicy ->
2023-01-23 16:35:48 +03:00
( FeatureFlag -> IO Bool ) ->
2023-01-06 12:33:13 +03:00
ManagedT m ServerCtx
2023-01-23 16:35:48 +03:00
initialiseServerCtx env GlobalCtx { .. } serveOptions @ ServeOptions { .. } liveQueryHook serverMetrics prometheusMetrics traceSamplingPolicy checkFeatureFlag = do
2019-11-26 15:14:21 +03:00
instanceId <- liftIO generateInstanceId
2020-06-03 00:27:14 +03:00
latch <- liftIO newShutdownLatch
2020-11-24 09:10:04 +03:00
loggers @ ( Loggers loggerCtx logger pgLogger ) <- mkLoggers soEnabledLogTypes soLogLevel
2022-07-27 14:46:19 +03:00
when ( null soAdminSecret ) $ do
let errMsg :: Text
errMsg = " WARNING: No admin secret provided "
unLogger logger $
StartupLog
{ slLogLevel = LevelWarn ,
slKind = " no_admin_secret " ,
slInfo = A . toJSON errMsg
}
2020-11-24 09:10:04 +03:00
-- log serve options
2023-01-06 12:33:13 +03:00
unLogger logger $ serveOptsToLog serveOptions
2020-12-28 15:56:00 +03:00
2020-11-24 09:10:04 +03:00
-- log postgres connection info
2020-12-28 15:56:00 +03:00
unLogger logger $ connInfoToLog _gcMetadataDbConnInfo
2022-12-19 15:45:21 +03:00
metadataDbPool <-
allocate
( liftIO $ PG . initPGPool _gcMetadataDbConnInfo soConnParams pgLogger )
( liftIO . PG . destroyPGPool )
2020-12-28 15:56:00 +03:00
2021-09-24 01:56:37 +03:00
let maybeDefaultSourceConfig =
fst _gcDefaultPostgresConnInfo <&> \ ( dbUrlConf , _ ) ->
let connSettings =
PostgresPoolSettings
2022-10-17 11:04:54 +03:00
{ _ppsMaxConnections = Just $ Q . cpConns soConnParams ,
_ppsTotalMaxConnections = Nothing ,
_ppsIdleTimeout = Just $ Q . cpIdleTime soConnParams ,
2021-09-24 01:56:37 +03:00
_ppsRetries = snd _gcDefaultPostgresConnInfo <|> Just 1 ,
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
_ppsPoolTimeout = PG . cpTimeout soConnParams ,
_ppsConnectionLifetime = PG . cpMbLifetime soConnParams
2021-09-24 01:56:37 +03:00
}
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
sourceConnInfo = PostgresSourceConnInfo dbUrlConf ( Just connSettings ) ( PG . cpAllowPrepare soConnParams ) soTxIso Nothing
2023-01-25 10:12:53 +03:00
in PostgresConnConfiguration sourceConnInfo Nothing defaultPostgresExtensionsSchema Nothing mempty
2022-07-14 20:57:28 +03:00
optimizePermissionFilters
| EFOptimizePermissionFilters ` elem ` soExperimentalFeatures = Options . OptimizePermissionFilters
| otherwise = Options . Don'tOptimizePermissionFilters
2022-09-30 16:24:32 +03:00
bigqueryStringNumericInput
| EFBigQueryStringNumericInput ` elem ` soExperimentalFeatures = Options . EnableBigQueryStringNumericInput
| otherwise = Options . DisableBigQueryStringNumericInput
sqlGenCtx = SQLGenCtx soStringifyNum soDangerousBooleanCollapse optimizePermissionFilters bigqueryStringNumericInput
2020-11-24 09:10:04 +03:00
2021-09-24 01:56:37 +03:00
let serverConfigCtx =
ServerConfigCtx
soInferFunctionPermissions
soEnableRemoteSchemaPermissions
sqlGenCtx
soEnableMaintenanceMode
soExperimentalFeatures
2021-11-30 15:31:27 +03:00
soEventingMode
2021-12-08 09:26:46 +03:00
soReadOnlyMode
2022-05-26 14:54:30 +03:00
soDefaultNamingConvention
2022-10-20 15:45:31 +03:00
soMetadataDefaults
2023-01-23 16:35:48 +03:00
checkFeatureFlag
2021-02-18 19:46:14 +03:00
2022-03-14 21:31:46 +03:00
rebuildableSchemaCache <-
2020-12-28 15:56:00 +03:00
lift . flip onException ( flushLogger loggerCtx ) $
2021-09-24 01:56:37 +03:00
migrateCatalogSchema
env
logger
metadataDbPool
maybeDefaultSourceConfig
2022-09-27 12:24:19 +03:00
mempty
2021-09-24 01:56:37 +03:00
serverConfigCtx
( mkPgSourceResolver pgLogger )
2022-01-04 14:53:50 +03:00
mkMSSQLSourceResolver
2022-08-09 14:42:12 +03:00
soExtensionsSchema
2021-04-06 06:25:02 +03:00
-- Start a background thread for listening schema sync events from other server instances,
metaVersionRef <- liftIO $ STM . newEmptyTMVarIO
2021-04-07 12:59:48 +03:00
-- An interval of 0 indicates that no schema sync is required
case soSchemaPollInterval of
2022-11-29 04:00:28 +03:00
Skip -> unLogger logger $ mkGenericLog @ Text LevelInfo " schema-sync " " Schema sync disabled "
2022-08-17 04:07:44 +03:00
Interval interval -> do
2022-11-29 04:00:28 +03:00
unLogger logger $ mkGenericLog @ String LevelInfo " schema-sync " ( " Schema sync enabled. Polling at " <> show interval )
2022-08-17 04:07:44 +03:00
void $ startSchemaSyncListenerThread logger metadataDbPool instanceId interval metaVersionRef
2021-04-06 06:25:02 +03:00
2022-03-09 01:59:28 +03:00
schemaCacheRef <- initialiseSchemaCacheRef serverMetrics rebuildableSchemaCache
2021-02-11 20:54:25 +03:00
server: http ip blocklist (closes #2449)
## Description
This PR is in reference to #2449 (support IP blacklisting for multitenant)
*RFC Update: Add support for IPv6 blocking*
### Solution and Design
Using [http-client-restricted](https://hackage.haskell.org/package/http-client-restricted) package, we're creating the HTTP manager with restricting capabilities. The IPs can be supplied from the CLI arguments as `--ipv4BlocklistCidrs cidr1, cidr2...` or `--disableDefaultIPv4Blocklist` for a default IP list. The new manager will block all requests to the provided CIDRs.
We are extracting the error message string to show the end-user that given IP is blocked from being set as a webhook. There are 2 ways to extract the error message "connection to IP address is blocked". Given below are the responses from event trigger to a blocked IP for these implementations:
- 6d74fde316f61e246c861befcca5059d33972fa7 - We return the error message string as a HTTPErr(HOther) from `Hasura/Eventing/HTTP.hs`.
```
{
"data": {
"message": "blocked connection to private IP address "
},
"version": "2",
"type": "client_error"
}
```
- 88e17456345cbb449a5ecd4877c84c9f319dbc25 - We case match on HTTPExceptionContent for InternaException in `Hasura/HTTP.hs` and extract the error message string from it. (this is implemented as it handles all the cases where pro engine makes webhook requests)
```
{
"data": {
"message": {
"type": "http_exception",
"message": "blocked connection to private IP address ",
"request": {
"secure": false,
"path": "/webhook",
"responseTimeout": "ResponseTimeoutMicro 60000000",
"queryString": "",
"method": "POST",
"requestHeaders": {
"Content-Type": "application/json",
"X-B3-ParentSpanId": "5ae6573edb2a6b36",
"X-B3-TraceId": "29ea7bd6de6ebb8f",
"X-B3-SpanId": "303137d9f1d4f341",
"User-Agent": "hasura-graphql-engine/cerebushttp-ip-blacklist-a793a0e41-dirty"
},
"host": "139.59.90.109",
"port": 8000
}
}
},
"version": "2",
"type": "client_error"
}
```
### Steps to test and verify
The restricted IPs can be used as webhooks in event triggers, and hasura will return an error message in reponse.
### Limitations, known bugs & workarounds
- The `http-client-restricted` has a needlessly complex interface, and puts effort into implementing proxy support which we don't want, so we've inlined a stripped down version.
- Performance constraint: As the blocking is checked for each request, if a long list of blocked CIDRs is supplied, iterating through all of them is not what we would prefer. Using trie is suggested to overcome this. (Added to RFC)
- Calls to Lux endpoints are inconsistent: We use either the http manager from the ProServeCtx which is unrestricted, or the http manager from the ServeCtx which is restricted (the latter through the instances for MonadMetadataApiAuthorization and UserAuthentication). (The failure scenario here would be: cloud sets PRO_ENDPOINT to something that resolves to an internal address, and then restricted requests to those endpoints fail, causing auth to fail on user requests. This is about HTTP requests to lux auth endpoints.)
## Changelog
- ✅ `CHANGELOG.md` is updated with user-facing content relevant to this PR.
## Affected components
- ✅ Server
- ✅ Tests
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3186
Co-authored-by: Robert <132113+robx@users.noreply.github.com>
GitOrigin-RevId: 5bd2de2d028bc416b02c99e996c7bebce56fb1e7
2022-02-25 16:29:55 +03:00
srvMgr <- liftIO $ mkHttpManager ( readTlsAllowlist schemaCacheRef ) mempty
2021-08-24 10:36:32 +03:00
2023-01-06 12:33:13 +03:00
authMode <- liftIO $ initAuthMode serveOptions srvMgr logger
subscriptionsState <- liftIO $ initSubscriptionsState serveOptions logger liveQueryHook
2021-09-24 01:56:37 +03:00
pure $
2023-01-06 12:33:13 +03:00
ServerCtx
{ scLoggers = loggers ,
scCacheRef = schemaCacheRef ,
scAuthMode = authMode ,
scManager = srvMgr ,
scSQLGenCtx = sqlGenCtx ,
scEnabledAPIs = soEnabledAPIs ,
scInstanceId = instanceId ,
scSubscriptionState = subscriptionsState ,
2023-02-08 06:35:19 +03:00
scEnableAllowList = soEnableAllowList ,
2023-01-06 12:33:13 +03:00
scEnvironment = env ,
scResponseInternalErrorsConfig = soResponseInternalErrorsConfig ,
scRemoteSchemaPermsCtx = soEnableRemoteSchemaPermissions ,
scFunctionPermsCtx = soInferFunctionPermissions ,
scEnableMaintenanceMode = soEnableMaintenanceMode ,
scExperimentalFeatures = soExperimentalFeatures ,
scLoggingSettings = LoggingSettings soEnabledLogTypes soEnableMetadataQueryLogging ,
scEventingMode = soEventingMode ,
scEnableReadOnlyMode = soReadOnlyMode ,
scDefaultNamingConvention = soDefaultNamingConvention ,
scServerMetrics = serverMetrics ,
scMetadataDefaults = soMetadataDefaults ,
scEnabledLogTypes = soEnabledLogTypes ,
scMetadataDbPool = metadataDbPool ,
scShutdownLatch = latch ,
scMetaVersionRef = metaVersionRef ,
scPrometheusMetrics = prometheusMetrics ,
2023-01-23 16:35:48 +03:00
scTraceSamplingPolicy = traceSamplingPolicy ,
scCheckFeatureFlag = checkFeatureFlag
2023-01-06 12:33:13 +03:00
}
2021-09-24 01:56:37 +03:00
mkLoggers ::
( MonadIO m , MonadBaseControl IO m ) =>
HashSet ( EngineLogType Hasura ) ->
LogLevel ->
ManagedT m Loggers
2020-11-24 09:10:04 +03:00
mkLoggers enabledLogs logLevel = do
2020-12-21 21:56:00 +03:00
loggerCtx <- mkLoggerCtx ( defaultLoggerSettings True logLevel ) enabledLogs
2020-11-24 09:10:04 +03:00
let logger = mkLogger loggerCtx
pgLogger = mkPGLogger logger
return $ Loggers loggerCtx logger pgLogger
2019-11-26 15:14:21 +03:00
2020-06-19 09:42:32 +03:00
-- | helper function to initialize or migrate the @hdb_catalog@ schema (used by pro as well)
2021-09-24 01:56:37 +03:00
migrateCatalogSchema ::
2021-10-13 19:38:56 +03:00
( MonadIO m , MonadBaseControl IO m ) =>
2021-09-24 01:56:37 +03:00
Env . Environment ->
Logger Hasura ->
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
PG . PGPool ->
2021-09-24 01:56:37 +03:00
Maybe ( SourceConnConfiguration ( 'Postgres 'Vanilla ) ) ->
2022-09-27 12:24:19 +03:00
Blocklist ->
2021-09-24 01:56:37 +03:00
ServerConfigCtx ->
2022-01-04 14:53:50 +03:00
SourceResolver ( 'Postgres 'Vanilla ) ->
SourceResolver ( 'MSSQL ) ->
2022-08-09 14:42:12 +03:00
ExtensionsSchema ->
2022-03-14 21:31:46 +03:00
m RebuildableSchemaCache
2020-06-19 09:42:32 +03:00
migrateCatalogSchema
2021-09-24 01:56:37 +03:00
env
logger
pool
defaultSourceConfig
2022-09-27 12:24:19 +03:00
blockList
2021-09-24 01:56:37 +03:00
serverConfigCtx
2022-01-04 14:53:50 +03:00
pgSourceResolver
2022-08-09 14:42:12 +03:00
mssqlSourceResolver
extensionsSchema = do
2021-09-24 01:56:37 +03:00
initialiseResult <- runExceptT $ do
-- TODO: should we allow the migration to happen during maintenance mode?
-- Allowing this can be a sanity check, to see if the hdb_catalog in the
-- DB has been set correctly
2022-03-14 21:31:46 +03:00
currentTime <- liftIO Clock . getCurrentTime
2021-09-24 01:56:37 +03:00
( migrationResult , metadata ) <-
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
PG . runTx pool ( PG . Serializable , Just PG . ReadWrite ) $
2021-09-24 01:56:37 +03:00
migrateCatalog
defaultSourceConfig
2022-08-09 14:42:12 +03:00
extensionsSchema
2021-09-24 01:56:37 +03:00
( _sccMaintenanceMode serverConfigCtx )
currentTime
2022-09-27 12:24:19 +03:00
let tlsAllowList = networkTlsAllowlist $ _metaNetwork metadata
httpManager <- liftIO $ mkHttpManager ( pure tlsAllowList ) blockList
2021-09-24 01:56:37 +03:00
let cacheBuildParams =
2022-01-04 14:53:50 +03:00
CacheBuildParams httpManager pgSourceResolver mssqlSourceResolver serverConfigCtx
2021-11-10 17:34:22 +03:00
buildReason = CatalogSync
2021-09-24 01:56:37 +03:00
schemaCache <-
runCacheBuild cacheBuildParams $
2021-11-09 17:21:48 +03:00
buildRebuildableSchemaCacheWithReason buildReason logger env metadata
2021-09-24 01:56:37 +03:00
pure ( migrationResult , schemaCache )
( migrationResult , schemaCache ) <-
initialiseResult ` onLeft ` \ err -> do
unLogger
logger
StartupLog
{ slLogLevel = LevelError ,
slKind = " catalog_migrate " ,
slInfo = A . toJSON err
}
2022-03-14 21:31:46 +03:00
liftIO ( throwErrJExit DatabaseMigrationError err )
2021-09-24 01:56:37 +03:00
unLogger logger migrationResult
2022-03-14 21:31:46 +03:00
pure schemaCache
2020-04-01 18:14:26 +03:00
2021-05-14 12:38:37 +03:00
-- | Event triggers live in the user's DB and other events
-- (cron, one-off and async actions)
-- live in the metadata DB, so we need a way to differentiate the
-- type of shutdown action
2021-09-24 01:56:37 +03:00
data ShutdownAction
= EventTriggerShutdownAction ( IO () )
2023-02-03 04:03:23 +03:00
| MetadataDBShutdownAction ( ExceptT QErr IO () )
2021-05-14 12:38:37 +03:00
2020-06-19 09:42:32 +03:00
-- | If an exception is encountered , flush the log buffer and
-- rethrow If we do not flush the log buffer on exception, then log lines
-- may be missed
-- See: https://github.com/hasura/graphql-engine/issues/4772
2020-07-14 22:00:58 +03:00
flushLogger :: MonadIO m => LoggerCtx impl -> m ()
flushLogger = liftIO . FL . flushLogStr . _lcLoggerSet
2020-06-19 09:42:32 +03:00
2020-12-21 21:56:00 +03:00
-- | This function acts as the entrypoint for the graphql-engine webserver.
--
-- Note: at the exit of this function, or in case of a graceful server shutdown
-- (SIGTERM, or more generally, whenever the shutdown latch is set), we need to
-- make absolutely sure that we clean up any resources which were allocated during
-- server setup. In the case of a multitenant process, failure to do so can lead to
2020-12-28 15:56:00 +03:00
-- resource leaks.
2020-12-21 21:56:00 +03:00
--
-- To track these resources, we use the ManagedT monad, and attach finalizers at
-- the same point in the code where we allocate resources. If you fork a new
-- long-lived thread, or create a connection pool, or allocate any other
-- long-lived resource, make sure to pair the allocator with its finalizer.
-- There are plenty of examples throughout the code. For example, see
-- 'C.forkManagedT'.
--
-- Note also: the order in which the finalizers run can be important. Specifically,
-- we want the finalizers for the logger threads to run last, so that we retain as
-- many "thread stopping" log messages as possible. The order in which the
-- finalizers is run is determined by the order in which they are introduced in the
-- code.
2021-09-24 01:56:37 +03:00
2020-12-02 09:16:05 +03:00
{- HLINT ignore runHGEServer "Avoid lambda" -}
2023-02-20 20:41:55 +03:00
{- HLINT ignore runHGEServer "Use withAsync" -}
2021-09-24 01:56:37 +03:00
runHGEServer ::
forall m impl .
2021-10-13 19:38:56 +03:00
( MonadIO m ,
Rewrite OpenAPI
### Description
This PR rewrites OpenAPI to be more idiomatic. Some noteworthy changes:
- we accumulate all required information during the Analyze phase, to avoid having to do a single lookup in the schema cache during the OpenAPI generation phase (we now only need the schema cache as input to run the analysis)
- we no longer build intermediary endpoint information and aggregate it, we directly build the the `PathItem` for each endpoint; additionally, that means we no longer have to assume that different methods have the same metadata
- we no longer have to first declare types, then craft references: we do everything in one step
- we now properly deal with nullability by treating "typeName" and "typeName!" as different
- we add a bunch of additional fields in the generated "schema", such as title
- we do now support enum values in both input and output positions
- checking whether the request body is required is now performed on the fly rather than by introspecting the generated schema
- the methods in the file are sorted by topic
### Controversial point
However, this PR creates some additional complexity, that we might not want to keep. The main complexity is _knot-tying_: to avoid lookups when generating the OpenAPI, it builds an actual graph of input types, which means that we need something similar to (but simpler than) `MonadSchema`, to avoid infinite recursions when analyzing the input types of a query. To do this, this PR introduces `CircularT`, a lesser `SchemaT` that aims at avoiding ever having to reinvent this particular wheel ever again.
### Remaining work
- [x] fix existing tests (they are all failing due to some of the schema changes)
- [ ] add tests to cover the new features:
- [x] tests for `CircularT`
- [ ] tests for enums in output schemas
- [x] extract / document `CircularT` if we wish to keep it
- [x] add more comments to `OpenAPI`
- [x] have a second look at `buildVariableSchema`
- [x] fix all missing diagnostics in `Analyze`
- [x] add a Changelog entry?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4654
Co-authored-by: David Overton <7734777+dmoverton@users.noreply.github.com>
GitOrigin-RevId: f4a9191f22dfcc1dccefd6a52f5c586b6ad17172
2022-06-30 15:55:56 +03:00
MonadFix m ,
2021-09-24 01:56:37 +03:00
MonadMask m ,
MonadStateless IO m ,
LA . Forall ( LA . Pure m ) ,
UserAuthentication ( Tracing . TraceT m ) ,
HttpLog m ,
ConsoleRenderer m ,
2022-12-07 14:28:58 +03:00
MonadVersionAPIWithExtraData m ,
2021-09-24 01:56:37 +03:00
MonadMetadataApiAuthorization m ,
MonadGQLExecutionCheck m ,
MonadConfigApiHandler m ,
MonadQueryLog m ,
WS . MonadWSLog m ,
MonadExecuteQuery m ,
Tracing . HasReporter m ,
HasResourceLimits m ,
2023-02-03 04:03:23 +03:00
MonadMetadataStorageQueryAPI m ,
2021-09-24 01:56:37 +03:00
MonadResolveSource m ,
2022-09-09 11:26:44 +03:00
EB . MonadQueryTags m ,
MonadEventLogCleanup m
2021-09-24 01:56:37 +03:00
) =>
( ServerCtx -> Spock . SpockT m () ) ->
Env . Environment ->
ServeOptions impl ->
2023-01-06 12:33:13 +03:00
ServerCtx ->
2021-09-24 01:56:37 +03:00
-- | start time
UTCTime ->
2022-08-05 14:50:11 +03:00
-- | A hook which can be called to indicate when the server is started succesfully
Maybe ( IO () ) ->
2023-01-06 12:33:13 +03:00
EKG . Store EKG . EmptyMetrics ->
2023-01-23 16:35:48 +03:00
( FeatureFlag -> IO Bool ) ->
2021-09-24 01:56:37 +03:00
ManagedT m ()
2023-01-23 16:35:48 +03:00
runHGEServer setupHook env serveOptions serverCtx @ ServerCtx { .. } initTime startupStatusHook ekgStore checkFeatureFlag = do
2021-10-20 23:01:22 +03:00
waiApplication <-
2023-01-23 16:35:48 +03:00
mkHGEServer setupHook env serveOptions serverCtx ekgStore checkFeatureFlag
2021-10-20 23:01:22 +03:00
2023-01-06 12:33:13 +03:00
let logger = _lsLogger $ scLoggers
2022-08-05 14:50:11 +03:00
-- `startupStatusHook`: add `Service started successfully` message to config_status
-- table when a tenant starts up in multitenant
2021-10-20 23:01:22 +03:00
let warpSettings :: Warp . Settings
warpSettings =
2022-08-17 04:07:44 +03:00
Warp . setPort ( _getPort $ soPort serveOptions )
2021-10-20 23:01:22 +03:00
. Warp . setHost ( soHost serveOptions )
. Warp . setGracefulShutdownTimeout ( Just 30 ) -- 30s graceful shutdown
. Warp . setInstallShutdownHandler shutdownHandler
2022-10-04 00:49:32 +03:00
. Warp . setBeforeMainLoop ( for_ startupStatusHook id )
2021-10-20 23:01:22 +03:00
. setForkIOWithMetrics
$ Warp . defaultSettings
setForkIOWithMetrics :: Warp . Settings -> Warp . Settings
setForkIOWithMetrics = Warp . setFork \ f -> do
void $
C . forkIOWithUnmask
( \ unmask ->
bracket_
2022-07-24 00:18:01 +03:00
( do
2023-01-06 12:33:13 +03:00
EKG . Gauge . inc ( smWarpThreads scServerMetrics )
incWarpThreads ( pmConnections scPrometheusMetrics )
2022-07-24 00:18:01 +03:00
)
( do
2023-01-06 12:33:13 +03:00
EKG . Gauge . dec ( smWarpThreads scServerMetrics )
decWarpThreads ( pmConnections scPrometheusMetrics )
2022-07-24 00:18:01 +03:00
)
2021-10-20 23:01:22 +03:00
( f unmask )
)
shutdownHandler :: IO () -> IO ()
shutdownHandler closeSocket =
LA . link =<< LA . async do
2023-01-06 12:33:13 +03:00
waitForShutdown $ scShutdownLatch
2022-11-29 04:00:28 +03:00
unLogger logger $ mkGenericLog @ Text LevelInfo " server " " gracefully shutting down server "
2021-10-20 23:01:22 +03:00
closeSocket
2022-10-20 11:29:14 +03:00
finishTime <- liftIO Clock . getCurrentTime
let apiInitTime = realToFrac $ Clock . diffUTCTime finishTime initTime
unLogger logger $
2022-11-02 23:53:23 +03:00
mkGenericLog LevelInfo " server " $
StartupTimeInfo " starting API server " apiInitTime
2022-10-20 11:29:14 +03:00
2021-10-20 23:01:22 +03:00
-- Here we block until the shutdown latch 'MVar' is filled, and then
-- shut down the server. Once this blocking call returns, we'll tidy up
-- any resources using the finalizers attached using 'ManagedT' above.
-- Structuring things using the shutdown latch in this way lets us decide
-- elsewhere exactly how we want to control shutdown.
liftIO $ Warp . runSettings warpSettings waiApplication
-- | Part of a factorization of 'runHGEServer' to expose the constructed WAI
-- application for testing purposes. See 'runHGEServer' for documentation.
mkHGEServer ::
forall m impl .
( MonadIO m ,
Rewrite OpenAPI
### Description
This PR rewrites OpenAPI to be more idiomatic. Some noteworthy changes:
- we accumulate all required information during the Analyze phase, to avoid having to do a single lookup in the schema cache during the OpenAPI generation phase (we now only need the schema cache as input to run the analysis)
- we no longer build intermediary endpoint information and aggregate it, we directly build the the `PathItem` for each endpoint; additionally, that means we no longer have to assume that different methods have the same metadata
- we no longer have to first declare types, then craft references: we do everything in one step
- we now properly deal with nullability by treating "typeName" and "typeName!" as different
- we add a bunch of additional fields in the generated "schema", such as title
- we do now support enum values in both input and output positions
- checking whether the request body is required is now performed on the fly rather than by introspecting the generated schema
- the methods in the file are sorted by topic
### Controversial point
However, this PR creates some additional complexity, that we might not want to keep. The main complexity is _knot-tying_: to avoid lookups when generating the OpenAPI, it builds an actual graph of input types, which means that we need something similar to (but simpler than) `MonadSchema`, to avoid infinite recursions when analyzing the input types of a query. To do this, this PR introduces `CircularT`, a lesser `SchemaT` that aims at avoiding ever having to reinvent this particular wheel ever again.
### Remaining work
- [x] fix existing tests (they are all failing due to some of the schema changes)
- [ ] add tests to cover the new features:
- [x] tests for `CircularT`
- [ ] tests for enums in output schemas
- [x] extract / document `CircularT` if we wish to keep it
- [x] add more comments to `OpenAPI`
- [x] have a second look at `buildVariableSchema`
- [x] fix all missing diagnostics in `Analyze`
- [x] add a Changelog entry?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4654
Co-authored-by: David Overton <7734777+dmoverton@users.noreply.github.com>
GitOrigin-RevId: f4a9191f22dfcc1dccefd6a52f5c586b6ad17172
2022-06-30 15:55:56 +03:00
MonadFix m ,
2021-10-20 23:01:22 +03:00
MonadMask m ,
MonadStateless IO m ,
LA . Forall ( LA . Pure m ) ,
UserAuthentication ( Tracing . TraceT m ) ,
HttpLog m ,
ConsoleRenderer m ,
2022-12-07 14:28:58 +03:00
MonadVersionAPIWithExtraData m ,
2021-10-20 23:01:22 +03:00
MonadMetadataApiAuthorization m ,
MonadGQLExecutionCheck m ,
MonadConfigApiHandler m ,
MonadQueryLog m ,
WS . MonadWSLog m ,
MonadExecuteQuery m ,
Tracing . HasReporter m ,
HasResourceLimits m ,
2023-02-03 04:03:23 +03:00
MonadMetadataStorageQueryAPI m ,
2021-10-20 23:01:22 +03:00
MonadResolveSource m ,
2022-09-09 11:26:44 +03:00
EB . MonadQueryTags m ,
MonadEventLogCleanup m
2021-10-20 23:01:22 +03:00
) =>
( ServerCtx -> Spock . SpockT m () ) ->
Env . Environment ->
ServeOptions impl ->
2023-01-06 12:33:13 +03:00
ServerCtx ->
2021-10-20 23:01:22 +03:00
EKG . Store EKG . EmptyMetrics ->
2023-01-23 16:35:48 +03:00
( FeatureFlag -> IO Bool ) ->
2021-10-20 23:01:22 +03:00
ManagedT m Application
2023-01-23 16:35:48 +03:00
mkHGEServer setupHook env ServeOptions { .. } serverCtx @ ServerCtx { .. } ekgStore checkFeatureFlag = do
2020-06-16 20:44:59 +03:00
-- 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
-- tool.
2020-03-18 04:31:22 +03:00
--
-- NOTE: be sure to compile WITHOUT code coverage, for this to work properly.
liftIO disableAssertNF
2021-08-24 10:36:32 +03:00
2022-08-26 07:37:35 +03:00
let optimizePermissionFilters
2022-07-14 20:57:28 +03:00
| EFOptimizePermissionFilters ` elem ` soExperimentalFeatures = Options . OptimizePermissionFilters
| otherwise = Options . Don'tOptimizePermissionFilters
2022-09-30 16:24:32 +03:00
bigqueryStringNumericInput
| EFBigQueryStringNumericInput ` elem ` soExperimentalFeatures = Options . EnableBigQueryStringNumericInput
| otherwise = Options . DisableBigQueryStringNumericInput
sqlGenCtx = SQLGenCtx soStringifyNum soDangerousBooleanCollapse optimizePermissionFilters bigqueryStringNumericInput
2023-01-06 12:33:13 +03:00
Loggers loggerCtx logger _ = scLoggers
2023-01-06 09:39:10 +03:00
2021-09-24 01:56:37 +03:00
HasuraApp app cacheRef actionSubState stopWsServer <-
lift $
flip onException ( flushLogger loggerCtx ) $
mkWaiApp
setupHook
env
soCorsConfig
2023-02-07 08:58:24 +03:00
soConsoleStatus
2021-09-24 01:56:37 +03:00
soConsoleAssetsDir
2022-09-27 17:50:32 +03:00
soConsoleSentryDsn
2021-09-24 01:56:37 +03:00
soEnableTelemetry
2023-01-06 12:33:13 +03:00
scCacheRef
2021-09-24 01:56:37 +03:00
soConnectionOptions
2022-07-15 11:54:27 +03:00
soWebSocketKeepAlive
2023-01-06 12:33:13 +03:00
scEnabledLogTypes
serverCtx
2022-07-15 11:54:27 +03:00
soWebSocketConnectionInitTimeout
2023-01-06 12:33:13 +03:00
ekgStore
2021-02-18 19:46:14 +03:00
2023-01-06 12:33:13 +03:00
-- Init ServerConfigCtx
2021-02-18 19:46:14 +03:00
let serverConfigCtx =
2021-09-24 01:56:37 +03:00
ServerConfigCtx
soInferFunctionPermissions
soEnableRemoteSchemaPermissions
sqlGenCtx
soEnableMaintenanceMode
soExperimentalFeatures
2021-11-30 15:31:27 +03:00
soEventingMode
2021-12-08 09:26:46 +03:00
soReadOnlyMode
2022-05-26 14:54:30 +03:00
soDefaultNamingConvention
2022-10-20 15:45:31 +03:00
soMetadataDefaults
2023-01-23 16:35:48 +03:00
checkFeatureFlag
2019-11-26 15:14:21 +03:00
2021-05-25 13:49:59 +03:00
-- Log Warning if deprecated environment variables are used
2022-03-09 01:59:28 +03:00
sources <- scSources <$> liftIO ( getSchemaCache cacheRef )
2021-05-25 13:49:59 +03:00
liftIO $ logDeprecatedEnvVars logger env sources
2019-11-26 15:14:21 +03:00
-- log inconsistent schema objects
2022-03-09 01:59:28 +03:00
inconsObjs <- scInconsistentObjs <$> liftIO ( getSchemaCache cacheRef )
liftIO $ logInconsistentMetadata logger inconsObjs
2019-11-26 15:14:21 +03:00
2021-07-27 08:41:16 +03:00
-- NOTE: `newLogTVar` is being used to make sure that the metadata logger runs only once
-- while logging errors or any `inconsistent_metadata` logs.
newLogTVar <- liftIO $ STM . newTVarIO False
2021-11-30 15:31:27 +03:00
2020-11-24 09:10:04 +03:00
-- Start a background thread for processing schema sync event present in the '_sscSyncEventRef'
2021-09-24 01:56:37 +03:00
_ <-
startSchemaSyncProcessorThread
logger
2023-01-06 12:33:13 +03:00
scManager
scMetaVersionRef
2021-09-24 01:56:37 +03:00
cacheRef
2023-01-06 12:33:13 +03:00
scInstanceId
2021-09-24 01:56:37 +03:00
serverConfigCtx
newLogTVar
2021-05-14 12:38:37 +03:00
lockedEventsCtx <-
liftIO $
2021-09-24 01:56:37 +03:00
LockedEventsCtx
<$> STM . newTVarIO mempty
<*> STM . newTVarIO mempty
<*> STM . newTVarIO mempty
<*> STM . newTVarIO mempty
2021-04-27 20:22:54 +03:00
2021-11-30 15:31:27 +03:00
case soEventingMode of
EventingEnabled -> do
2022-06-05 23:27:09 +03:00
startEventTriggerPollerThread logger lockedEventsCtx cacheRef
2021-11-30 15:31:27 +03:00
startAsyncActionsPollerThread logger lockedEventsCtx cacheRef actionSubState
2021-05-14 12:38:37 +03:00
2023-02-07 15:22:08 +03:00
-- Create logger for logging the statistics of fetched cron triggers
fetchedCronTriggerStatsLogger <-
allocate
( createFetchedCronTriggerStatsLogger logger )
( closeFetchedCronTriggersStatsLogger logger )
2021-11-30 15:31:27 +03:00
-- start a background thread to create new cron events
_cronEventsThread <-
C . forkManagedT " runCronEventsGenerator " logger $
2023-02-07 15:22:08 +03:00
runCronEventsGenerator logger fetchedCronTriggerStatsLogger ( getSchemaCache cacheRef )
2021-09-24 01:56:37 +03:00
2022-06-05 23:27:09 +03:00
startScheduledEventsPollerThread logger lockedEventsCtx cacheRef
2021-11-30 15:31:27 +03:00
EventingDisabled ->
2022-11-29 04:00:28 +03:00
unLogger logger $ mkGenericLog @ Text LevelInfo " server " " starting in eventing disabled mode "
2020-05-13 15:33:16 +03:00
2019-11-26 15:14:21 +03:00
-- start a background thread to check for updates
2021-09-24 01:56:37 +03:00
_updateThread <-
C . forkManagedT " checkForUpdates " logger $
2022-11-02 23:53:23 +03:00
liftIO $
2023-01-06 12:33:13 +03:00
checkForUpdates loggerCtx scManager
2019-11-26 15:14:21 +03:00
2022-11-23 19:40:21 +03:00
-- Start a background thread for source pings
_sourcePingPoller <-
C . forkManagedT " sourcePingPoller " logger $ do
let pingLog =
2022-11-29 04:00:28 +03:00
unLogger logger . mkGenericLog @ String LevelInfo " sources-ping "
2022-11-23 19:40:21 +03:00
liftIO
( runPingSources
2023-02-14 15:14:33 +03:00
env
2022-11-23 19:40:21 +03:00
pingLog
( scSourcePingConfig <$> getSchemaCache cacheRef )
)
2019-11-26 15:14:21 +03:00
-- start a background thread for telemetry
2021-09-24 01:56:37 +03:00
_telemetryThread <-
2023-02-08 04:46:21 +03:00
if isTelemetryEnabled soEnableTelemetry
2021-09-24 01:56:37 +03:00
then do
2022-11-29 04:00:28 +03:00
lift . unLogger logger $ mkGenericLog @ Text LevelInfo " telemetry " telemetryNotice
2021-09-24 01:56:37 +03:00
2022-03-14 21:31:46 +03:00
dbUid <-
2023-02-03 04:03:23 +03:00
getMetadataDbUid ` onLeftM ` throwErrJExit DatabaseMigrationError
2022-03-14 21:31:46 +03:00
pgVersion <-
2023-01-06 12:33:13 +03:00
liftIO ( runExceptT $ PG . runTx scMetadataDbPool ( PG . ReadCommitted , Nothing ) $ getPgVersion )
2023-02-03 04:03:23 +03:00
` onLeftM ` throwErrJExit DatabaseMigrationError
2021-09-24 01:56:37 +03:00
telemetryThread <-
C . forkManagedT " runTelemetry " logger $
2022-11-02 23:53:23 +03:00
liftIO $
2023-01-06 12:33:13 +03:00
runTelemetry logger scManager ( getSchemaCache cacheRef ) dbUid scInstanceId pgVersion soExperimentalFeatures
2021-09-24 01:56:37 +03:00
return $ Just telemetryThread
else return Nothing
2020-07-30 05:34:50 +03:00
2021-10-20 23:01:22 +03:00
-- These cleanup actions are not directly associated with any
-- resource, but we still need to make sure we clean them up here.
allocate_ ( pure () ) ( liftIO stopWsServer )
2021-09-24 01:56:37 +03:00
2021-10-20 23:01:22 +03:00
pure app
2019-11-26 15:14:21 +03:00
where
2022-06-07 10:08:53 +03:00
isRetryRequired _ resp = do
return $ case resp of
Right _ -> False
Left err -> qeCode err == ConcurrentUpdate
2020-11-25 13:56:44 +03:00
prepareScheduledEvents ( Logger logger ) = do
2022-11-29 04:00:28 +03:00
liftIO $ logger $ mkGenericLog @ Text LevelInfo " scheduled_triggers " " preparing data "
2023-02-03 04:03:23 +03:00
res <- Retry . retrying Retry . retryPolicyDefault isRetryRequired ( return unlockAllLockedScheduledEvents )
2022-11-29 04:00:28 +03:00
onLeft res ( \ err -> logger $ mkGenericLog @ String LevelError " scheduled_triggers " ( show $ qeError err ) )
2020-07-02 14:57:09 +03:00
2021-05-14 12:38:37 +03:00
getProcessingScheduledEventsCount :: LockedEventsCtx -> IO Int
getProcessingScheduledEventsCount LockedEventsCtx { .. } = do
2021-09-24 01:56:37 +03:00
processingCronEvents <- readTVarIO leCronEvents
processingOneOffEvents <- readTVarIO leOneOffEvents
return $ length processingOneOffEvents + length processingCronEvents
shutdownEventTriggerEvents ::
[ BackendSourceInfo ] ->
Logger Hasura ->
LockedEventsCtx ->
IO ()
2021-09-20 10:34:59 +03:00
shutdownEventTriggerEvents sources ( Logger logger ) LockedEventsCtx { .. } = do
2021-05-14 12:38:37 +03:00
-- TODO: is this correct?
-- event triggers should be tied to the life cycle of a source
2021-09-20 10:34:59 +03:00
lockedEvents <- readTVarIO leEvents
forM_ sources $ \ backendSourceInfo -> do
2023-01-16 20:19:45 +03:00
AB . dispatchAnyBackend @ BackendEventTrigger backendSourceInfo \ ( SourceInfo sourceName _ _ _ sourceConfig _ _ :: SourceInfo b ) -> do
2022-07-01 14:47:20 +03:00
let sourceNameText = sourceNameToText sourceName
logger $ mkGenericLog LevelInfo " event_triggers " $ " unlocking events of source: " <> sourceNameText
2022-10-04 00:49:32 +03:00
for_ ( HM . lookup sourceName lockedEvents ) $ \ sourceLockedEvents -> do
2022-06-30 14:26:10 +03:00
-- No need to execute unlockEventsTx when events are not present
2022-10-04 00:49:32 +03:00
for_ ( NE . nonEmptySet sourceLockedEvents ) $ \ nonEmptyLockedEvents -> do
2022-06-30 14:26:10 +03:00
res <- Retry . retrying Retry . retryPolicyDefault isRetryRequired ( return $ unlockEventsInSource @ b sourceConfig nonEmptyLockedEvents )
case res of
Left err ->
logger $
2022-07-01 14:47:20 +03:00
mkGenericLog LevelWarn " event_trigger " $
" Error while unlocking event trigger events of source: " <> sourceNameText <> " error: " <> showQErr err
2022-06-30 14:26:10 +03:00
Right count ->
logger $
2022-07-01 14:47:20 +03:00
mkGenericLog LevelInfo " event_trigger " $
tshow count <> " events of source " <> sourceNameText <> " were successfully unlocked "
2021-09-24 01:56:37 +03:00
shutdownAsyncActions ::
LockedEventsCtx ->
2023-02-03 04:03:23 +03:00
ExceptT QErr m ()
2021-05-14 12:38:37 +03:00
shutdownAsyncActions lockedEventsCtx = do
lockedActionEvents <- liftIO $ readTVarIO $ leActionEvents lockedEventsCtx
2023-02-03 04:03:23 +03:00
liftEitherM $ setProcessingActionLogsToPending ( LockedActionIdArray $ toList lockedActionEvents )
2020-07-02 14:57:09 +03:00
2021-05-14 12:38:37 +03:00
-- This function is a helper function to do couple of things:
--
-- 1. When the value of the `graceful-shutdown-timeout` > 0, we poll
-- the in-flight events queue we maintain using the `processingEventsCountAction`
-- number of in-flight processing events, in case of actions it is the
-- actions which are in 'processing' state and in scheduled events
-- it is the events which are in 'locked' state. The in-flight events queue is polled
-- every 5 seconds until either the graceful shutdown time is exhausted
-- or the number of in-flight processing events is 0.
-- 2. After step 1, we unlock all the events which were attempted to process by the current
-- graphql-engine instance that are still in the processing
-- state. In actions, it means to set the status of such actions to 'pending'
-- and in scheduled events, the status will be set to 'unlocked'.
2021-09-24 01:56:37 +03:00
waitForProcessingAction ::
Logger Hasura ->
String ->
IO Int ->
ShutdownAction ->
Seconds ->
IO ()
2021-05-14 12:38:37 +03:00
waitForProcessingAction l @ ( Logger logger ) actionType processingEventsCountAction' shutdownAction maxTimeout
| maxTimeout <= 0 = do
2022-11-02 23:53:23 +03:00
case shutdownAction of
EventTriggerShutdownAction userDBShutdownAction -> userDBShutdownAction
MetadataDBShutdownAction metadataDBShutdownAction ->
2023-02-03 04:03:23 +03:00
runExceptT metadataDBShutdownAction >>= \ case
2022-11-02 23:53:23 +03:00
Left err ->
logger $
mkGenericLog LevelWarn ( T . pack actionType ) $
" Error while unlocking the processing "
<> tshow actionType
<> " err - "
<> showQErr err
Right () -> pure ()
2021-05-14 12:38:37 +03:00
| otherwise = do
2022-11-02 23:53:23 +03:00
processingEventsCount <- processingEventsCountAction'
if ( processingEventsCount == 0 )
then
logger $
2022-11-29 04:00:28 +03:00
mkGenericLog @ Text LevelInfo ( T . pack actionType ) $
2022-11-02 23:53:23 +03:00
" All in-flight events have finished processing "
else unless ( processingEventsCount == 0 ) $ do
C . sleep ( 5 ) -- sleep for 5 seconds and then repeat
waitForProcessingAction l actionType processingEventsCountAction' shutdownAction ( maxTimeout - ( Seconds 5 ) )
2021-09-24 01:56:37 +03:00
2022-06-05 23:27:09 +03:00
startEventTriggerPollerThread logger lockedEventsCtx cacheRef = do
2022-12-01 10:47:19 +03:00
schemaCache <- liftIO $ getSchemaCache cacheRef
2022-09-21 21:01:48 +03:00
let maxEventThreads = unrefine soEventsHttpPoolSize
fetchInterval = milliseconds $ unrefine soEventsFetchInterval
2022-12-01 10:47:19 +03:00
allSources = HM . elems $ scSources schemaCache
2021-11-30 15:31:27 +03:00
2022-09-21 21:01:48 +03:00
unless ( unrefine soEventsFetchBatchSize == 0 || fetchInterval == 0 ) $ do
2021-11-30 15:31:27 +03:00
-- Don't start the events poller thread when fetchBatchSize or fetchInterval is 0
-- prepare event triggers data
2022-08-17 04:07:44 +03:00
eventEngineCtx <- liftIO $ atomically $ initEventEngineCtx maxEventThreads fetchInterval soEventsFetchBatchSize
2021-11-30 15:31:27 +03:00
let eventsGracefulShutdownAction =
waitForProcessingAction
logger
" event_triggers "
( length <$> readTVarIO ( leEvents lockedEventsCtx ) )
( EventTriggerShutdownAction ( shutdownEventTriggerEvents allSources logger lockedEventsCtx ) )
2022-09-21 21:01:48 +03:00
( unrefine soGracefulShutdownTimeout )
2023-01-30 09:06:45 +03:00
-- Create logger for logging the statistics of events fetched
fetchedEventsStatsLogger <-
allocate
( createFetchedEventsStatsLogger logger )
( closeFetchedEventsStatsLogger logger )
2022-11-29 04:00:28 +03:00
unLogger logger $ mkGenericLog @ Text LevelInfo " event_triggers " " starting workers "
2022-11-02 23:53:23 +03:00
void
$ C . forkManagedTWithGracefulShutdown
2021-11-30 15:31:27 +03:00
" processEventQueue "
logger
( C . ThreadShutdown ( liftIO eventsGracefulShutdownAction ) )
2022-11-02 23:53:23 +03:00
$ processEventQueue
logger
2023-01-30 09:06:45 +03:00
fetchedEventsStatsLogger
2023-01-06 12:33:13 +03:00
scManager
2022-11-02 23:53:23 +03:00
( getSchemaCache cacheRef )
eventEngineCtx
lockedEventsCtx
2023-01-06 12:33:13 +03:00
scServerMetrics
( pmEventTriggerMetrics scPrometheusMetrics )
2022-11-02 23:53:23 +03:00
soEnableMaintenanceMode
2021-11-30 15:31:27 +03:00
startAsyncActionsPollerThread logger lockedEventsCtx cacheRef actionSubState = do
-- start a background thread to handle async actions
case soAsyncActionsFetchInterval of
Skip -> pure () -- Don't start the poller thread
2022-09-21 21:01:48 +03:00
Interval ( unrefine -> sleepTime ) -> do
2021-11-30 15:31:27 +03:00
let label = " asyncActionsProcessor "
asyncActionGracefulShutdownAction =
( liftWithStateless \ lowerIO ->
( waitForProcessingAction
logger
" async_actions "
( length <$> readTVarIO ( leActionEvents lockedEventsCtx ) )
( MetadataDBShutdownAction ( hoist lowerIO ( shutdownAsyncActions lockedEventsCtx ) ) )
2022-09-21 21:01:48 +03:00
( unrefine soGracefulShutdownTimeout )
2021-11-30 15:31:27 +03:00
)
)
2022-11-02 23:53:23 +03:00
void
$ C . forkManagedTWithGracefulShutdown
2021-11-30 15:31:27 +03:00
label
logger
( C . ThreadShutdown asyncActionGracefulShutdownAction )
2022-11-02 23:53:23 +03:00
$ asyncActionsProcessor
env
logger
( getSchemaCache cacheRef )
( leActionEvents lockedEventsCtx )
2023-01-06 12:33:13 +03:00
scManager
scPrometheusMetrics
2022-11-02 23:53:23 +03:00
sleepTime
Nothing
2021-11-30 15:31:27 +03:00
-- start a background thread to handle async action live queries
void $
C . forkManagedT " asyncActionSubscriptionsProcessor " logger $
asyncActionSubscriptionsProcessor actionSubState
2022-06-05 23:27:09 +03:00
startScheduledEventsPollerThread logger lockedEventsCtx cacheRef = do
2021-11-30 15:31:27 +03:00
-- prepare scheduled triggers
lift $ prepareScheduledEvents logger
2023-01-30 09:06:45 +03:00
-- Create logger for logging the statistics of scheduled events fetched
scheduledEventsStatsLogger <-
allocate
( createFetchedScheduledEventsStatsLogger logger )
( closeFetchedScheduledEventsStatsLogger logger )
2021-11-30 15:31:27 +03:00
-- start a background thread to deliver the scheduled events
-- _scheduledEventsThread <- do
let scheduledEventsGracefulShutdownAction =
( liftWithStateless \ lowerIO ->
( waitForProcessingAction
logger
" scheduled_events "
( getProcessingScheduledEventsCount lockedEventsCtx )
2023-02-03 04:03:23 +03:00
( MetadataDBShutdownAction ( liftEitherM $ hoist lowerIO unlockAllLockedScheduledEvents ) )
2022-09-21 21:01:48 +03:00
( unrefine soGracefulShutdownTimeout )
2021-11-30 15:31:27 +03:00
)
)
2022-11-02 23:53:23 +03:00
void
$ C . forkManagedTWithGracefulShutdown
2021-11-30 15:31:27 +03:00
" processScheduledTriggers "
logger
( C . ThreadShutdown scheduledEventsGracefulShutdownAction )
2022-11-02 23:53:23 +03:00
$ processScheduledTriggers
env
logger
2023-01-30 09:06:45 +03:00
scheduledEventsStatsLogger
2023-01-06 12:33:13 +03:00
scManager
scPrometheusMetrics
2022-11-02 23:53:23 +03:00
( getSchemaCache cacheRef )
lockedEventsCtx
2021-11-30 15:31:27 +03:00
2021-05-26 19:19:26 +03:00
instance ( Monad m ) => Tracing . HasReporter ( PGMetadataStorageAppT m )
2020-07-15 13:40:48 +03:00
2021-05-26 19:19:26 +03:00
instance ( Monad m ) => HasResourceLimits ( PGMetadataStorageAppT m ) where
2021-09-29 19:20:06 +03:00
askHTTPHandlerLimit = pure $ ResourceLimits id
2022-10-27 18:34:43 +03:00
askGraphqlOperationLimit _ _ _ = pure $ ResourceLimits id
2020-12-03 07:06:22 +03:00
2021-05-26 19:19:26 +03:00
instance ( MonadIO m ) => HttpLog ( PGMetadataStorageAppT m ) where
2021-07-05 12:45:31 +03:00
type ExtraHttpLogMetadata ( PGMetadataStorageAppT m ) = ()
2021-04-06 20:52:55 +03:00
2021-07-05 12:45:31 +03:00
emptyExtraHttpLogMetadata = ()
2022-12-15 10:48:18 +03:00
buildExtraHttpLogMetadata _ _ = ()
2021-04-06 20:52:55 +03:00
2022-12-15 10:48:18 +03:00
logHttpError logger loggingSettings userInfoM reqId waiReq req qErr headers _ =
2021-09-24 01:56:37 +03:00
unLogger logger $
mkHttpLog $
2022-04-11 20:49:25 +03:00
mkHttpErrorLogContext userInfoM loggingSettings reqId waiReq req qErr Nothing Nothing headers
2019-11-26 15:14:21 +03:00
2022-09-13 18:35:58 +03:00
logHttpSuccess logger loggingSettings userInfoM reqId waiReq reqBody response compressedResponse qTime cType headers ( CommonHttpLogMetadata rb batchQueryOpLogs , () ) =
2021-09-24 01:56:37 +03:00
unLogger logger $
mkHttpLog $
2022-09-13 18:35:58 +03:00
mkHttpAccessLogContext userInfoM loggingSettings reqId waiReq reqBody ( BL . length response ) compressedResponse qTime cType headers rb batchQueryOpLogs
2019-11-26 15:14:21 +03:00
2021-05-26 19:19:26 +03:00
instance ( Monad m ) => MonadExecuteQuery ( PGMetadataStorageAppT m ) where
2021-06-17 09:27:58 +03:00
cacheLookup _ _ _ _ = pure ( [] , Nothing )
2021-09-24 01:56:37 +03:00
cacheStore _ _ _ = pure ( Right CacheStoreSkipped )
2020-07-15 13:40:48 +03:00
2021-05-26 19:19:26 +03:00
instance ( MonadIO m , MonadBaseControl IO m ) => UserAuthentication ( Tracing . TraceT ( PGMetadataStorageAppT m ) ) where
2021-02-03 10:10:39 +03:00
resolveUserInfo logger manager headers authMode reqs =
2022-12-15 10:48:18 +03:00
runExceptT $ do
( a , b , c ) <- getUserInfoWithExpTime logger manager headers authMode reqs
pure $ ( a , b , c , ExtraUserInfo Nothing )
2019-11-26 15:14:21 +03:00
2021-01-07 12:04:22 +03:00
accessDeniedErrMsg :: Text
accessDeniedErrMsg =
" restricted access : admin only "
2021-05-26 19:19:26 +03:00
instance ( Monad m ) => MonadMetadataApiAuthorization ( PGMetadataStorageAppT m ) where
2021-01-07 12:04:22 +03:00
authorizeV1QueryApi query handlerCtx = runExceptT do
2020-12-14 07:30:19 +03:00
let currRole = _uiRole $ hcUser handlerCtx
2020-04-24 12:10:53 +03:00
when ( requiresAdmin query && currRole /= adminRoleName ) $
2022-11-02 23:53:23 +03:00
withPathK " args " $
throw400 AccessDenied accessDeniedErrMsg
2021-01-07 12:04:22 +03:00
authorizeV1MetadataApi _ handlerCtx = runExceptT do
let currRole = _uiRole $ hcUser handlerCtx
when ( currRole /= adminRoleName ) $
2022-11-02 23:53:23 +03:00
withPathK " args " $
throw400 AccessDenied accessDeniedErrMsg
2021-01-07 12:04:22 +03:00
2021-04-16 16:26:11 +03:00
authorizeV2QueryApi _ handlerCtx = runExceptT do
2021-01-07 12:04:22 +03:00
let currRole = _uiRole $ hcUser handlerCtx
2021-04-16 16:26:11 +03:00
when ( currRole /= adminRoleName ) $
2022-11-02 23:53:23 +03:00
withPathK " args " $
throw400 AccessDenied accessDeniedErrMsg
2019-11-26 15:14:21 +03:00
2021-05-26 19:19:26 +03:00
instance ( Monad m ) => ConsoleRenderer ( PGMetadataStorageAppT m ) where
2022-09-27 17:50:32 +03:00
renderConsole path authMode enableTelemetry consoleAssetsDir consoleSentryDsn =
return $ mkConsoleHTML path authMode enableTelemetry consoleAssetsDir consoleSentryDsn
2019-11-26 15:14:21 +03:00
2022-12-07 14:28:58 +03:00
instance ( Monad m ) => MonadVersionAPIWithExtraData ( PGMetadataStorageAppT m ) where
getExtraDataForVersionAPI = return []
2021-05-26 19:19:26 +03:00
instance ( Monad m ) => MonadGQLExecutionCheck ( PGMetadataStorageAppT m ) where
2022-04-05 10:18:21 +03:00
checkGQLExecution userInfo _ enableAL sc query _ = runExceptT $ do
2020-06-16 18:23:06 +03:00
req <- toParsed query
2022-02-08 19:53:30 +03:00
checkQueryInAllowlist enableAL AllowlistModeGlobalOnly userInfo req sc
2020-06-16 18:23:06 +03:00
return req
2021-05-05 15:25:27 +03:00
executeIntrospection _ introspectionQuery _ =
pure $ Right $ ExecStepRaw introspectionQuery
2022-10-13 19:50:05 +03:00
checkGQLBatchedReqs _ _ _ _ = runExceptT $ pure ()
2021-05-26 19:19:26 +03:00
instance ( MonadIO m , MonadBaseControl IO m ) => MonadConfigApiHandler ( PGMetadataStorageAppT m ) where
2020-06-16 18:23:06 +03:00
runConfigApiHandler = configApiGetHandler
2021-05-26 19:19:26 +03:00
instance ( MonadIO m ) => MonadQueryLog ( PGMetadataStorageAppT m ) where
2022-06-26 01:08:01 +03:00
logQueryLog logger = unLogger logger
2020-06-19 09:42:32 +03:00
2021-05-26 19:19:26 +03:00
instance ( MonadIO m ) => WS . MonadWSLog ( PGMetadataStorageAppT m ) where
2022-06-26 01:08:01 +03:00
logWSLog logger = unLogger logger
2020-06-19 09:42:32 +03:00
2021-05-26 19:19:26 +03:00
instance ( Monad m ) => MonadResolveSource ( PGMetadataStorageAppT m ) where
2022-01-04 14:53:50 +03:00
getPGSourceResolver = mkPgSourceResolver <$> asks snd
getMSSQLSourceResolver = return mkMSSQLSourceResolver
2020-12-28 15:56:00 +03:00
2021-07-29 11:29:12 +03:00
instance ( Monad m ) => EB . MonadQueryTags ( PGMetadataStorageAppT m ) where
2021-09-23 15:37:56 +03:00
createQueryTags _attributes _qtSourceConfig = return $ emptyQueryTagsComment
2021-07-29 11:29:12 +03:00
2022-09-09 11:26:44 +03:00
instance ( Monad m ) => MonadEventLogCleanup ( PGMetadataStorageAppT m ) where
2022-09-13 11:33:44 +03:00
runLogCleaner _ = pure $ throw400 NotSupported " Event log cleanup feature is enterprise edition only "
2022-09-15 14:45:14 +03:00
generateCleanupSchedules _ _ _ = pure $ Right ()
2023-02-03 15:27:53 +03:00
updateTriggerCleanupSchedules _ _ _ _ = pure $ Right ()
2022-09-09 11:26:44 +03:00
2021-09-24 01:56:37 +03:00
runInSeparateTx ::
( MonadIO m ) =>
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
PG . TxE QErr a ->
2023-02-03 04:03:23 +03:00
PGMetadataStorageAppT m ( Either QErr a )
2020-11-25 13:56:44 +03:00
runInSeparateTx tx = do
2023-02-03 04:03:23 +03:00
pool <- asks fst
liftIO $ runExceptT $ PG . runTx pool ( PG . RepeatableRead , Nothing ) tx
2020-11-25 13:56:44 +03:00
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
notifySchemaCacheSyncTx :: MetadataResourceVersion -> InstanceId -> CacheInvalidations -> PG . TxE QErr ()
2021-04-06 06:25:02 +03:00
notifySchemaCacheSyncTx ( MetadataResourceVersion resourceVersion ) instanceId invalidations = do
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
PG . Discard () <-
PG . withQE
2021-09-24 01:56:37 +03:00
defaultTxErrorHandler
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
[ PG . sql |
2021-04-06 06:25:02 +03:00
INSERT INTO hdb_catalog . hdb_schema_notifications ( id , notification , resource_version , instance_id )
VALUES ( 1 , $ 1 :: json , $ 2 , $ 3 :: uuid )
ON CONFLICT ( id ) DO UPDATE SET
notification = $ 1 :: json ,
resource_version = $ 2 ,
instance_id = $ 3 :: uuid
2021-09-24 01:56:37 +03:00
| ]
2022-09-21 21:40:41 +03:00
( PG . ViaJSON invalidations , resourceVersion , instanceId )
2021-09-24 01:56:37 +03:00
True
2020-12-14 07:30:19 +03:00
pure ()
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
getCatalogStateTx :: PG . TxE QErr CatalogState
2021-01-07 12:04:22 +03:00
getCatalogStateTx =
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
mkCatalogState . PG . getRow
<$> PG . withQE
2021-09-24 01:56:37 +03:00
defaultTxErrorHandler
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
[ PG . sql |
2021-01-07 12:04:22 +03:00
SELECT hasura_uuid :: text , cli_state :: json , console_state :: json
FROM hdb_catalog . hdb_version
2021-09-24 01:56:37 +03:00
| ]
()
False
2021-01-07 12:04:22 +03:00
where
2022-09-21 21:40:41 +03:00
mkCatalogState ( dbId , PG . ViaJSON cliState , PG . ViaJSON consoleState ) =
2021-01-07 12:04:22 +03:00
CatalogState dbId cliState consoleState
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
setCatalogStateTx :: CatalogStateType -> A . Value -> PG . TxE QErr ()
2021-01-07 12:04:22 +03:00
setCatalogStateTx stateTy stateValue =
case stateTy of
CSTCli ->
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
PG . unitQE
2021-09-24 01:56:37 +03:00
defaultTxErrorHandler
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
[ PG . sql |
2021-01-07 12:04:22 +03:00
UPDATE hdb_catalog . hdb_version
SET cli_state = $ 1
2021-09-24 01:56:37 +03:00
| ]
2022-09-21 21:40:41 +03:00
( Identity $ PG . ViaJSON stateValue )
2021-09-24 01:56:37 +03:00
False
2021-01-07 12:04:22 +03:00
CSTConsole ->
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
PG . unitQE
2021-09-24 01:56:37 +03:00
defaultTxErrorHandler
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
[ PG . sql |
2021-01-07 12:04:22 +03:00
UPDATE hdb_catalog . hdb_version
SET console_state = $ 1
2021-09-24 01:56:37 +03:00
| ]
2022-09-21 21:40:41 +03:00
( Identity $ PG . ViaJSON stateValue )
2021-09-24 01:56:37 +03:00
False
2021-02-18 19:46:14 +03:00
2020-11-25 13:56:44 +03:00
-- | Each of the function in the type class is executed in a totally separate transaction.
2023-02-03 04:03:23 +03:00
instance ( MonadIO m ) => MonadMetadataStorage ( PGMetadataStorageAppT m ) where
2021-09-24 01:56:37 +03:00
fetchMetadataResourceVersion = runInSeparateTx fetchMetadataResourceVersionFromCatalog
fetchMetadata = runInSeparateTx fetchMetadataAndResourceVersionFromCatalog
2021-04-06 06:25:02 +03:00
fetchMetadataNotifications a b = runInSeparateTx $ fetchMetadataNotificationsFromCatalog a b
2022-02-18 15:46:55 +03:00
setMetadata r = runInSeparateTx . setMetadataInCatalog r
2021-09-24 01:56:37 +03:00
notifySchemaCacheSync a b c = runInSeparateTx $ notifySchemaCacheSyncTx a b c
getCatalogState = runInSeparateTx getCatalogStateTx
2021-01-07 12:04:22 +03:00
setCatalogState a b = runInSeparateTx $ setCatalogStateTx a b
2020-12-14 07:30:19 +03:00
2022-06-15 11:02:29 +03:00
getMetadataDbUid = runInSeparateTx getDbId
2022-06-07 14:23:16 +03:00
checkMetadataStorageHealth = runInSeparateTx $ checkDbConnection
2020-12-28 15:56:00 +03:00
2021-09-24 01:56:37 +03:00
getDeprivedCronTriggerStats = runInSeparateTx . getDeprivedCronTriggerStatsTx
getScheduledEventsForDelivery = runInSeparateTx getScheduledEventsForDeliveryTx
insertCronEvents = runInSeparateTx . insertCronEventsTx
insertOneOffScheduledEvent = runInSeparateTx . insertOneOffScheduledEventTx
2020-11-25 13:56:44 +03:00
insertScheduledEventInvocation a b = runInSeparateTx $ insertInvocationTx a b
2021-09-24 01:56:37 +03:00
setScheduledEventOp a b c = runInSeparateTx $ setScheduledEventOpTx a b c
unlockScheduledEvents a b = runInSeparateTx $ unlockScheduledEventsTx a b
unlockAllLockedScheduledEvents = runInSeparateTx unlockAllLockedScheduledEventsTx
clearFutureCronEvents = runInSeparateTx . dropFutureCronEventsTx
2022-09-15 22:10:53 +03:00
getOneOffScheduledEvents a b c = runInSeparateTx $ getOneOffScheduledEventsTx a b c
getCronEvents a b c d = runInSeparateTx $ getCronEventsTx a b c d
2022-11-03 13:21:56 +03:00
getScheduledEventInvocations a = runInSeparateTx $ getScheduledEventInvocationsTx a
2021-09-24 01:56:37 +03:00
deleteScheduledEvent a b = runInSeparateTx $ deleteScheduledEventTx a b
insertAction a b c d = runInSeparateTx $ insertActionTx a b c d
fetchUndeliveredActionEvents = runInSeparateTx fetchUndeliveredActionEventsTx
setActionStatus a b = runInSeparateTx $ setActionStatusTx a b
fetchActionResponse = runInSeparateTx . fetchActionResponseTx
clearActionData = runInSeparateTx . clearActionDataTx
setProcessingActionLogsToPending = runInSeparateTx . setProcessingActionLogsToPendingTx
2020-11-25 13:56:44 +03:00
2023-02-03 04:03:23 +03:00
instance MonadIO m => MonadMetadataStorageQueryAPI ( PGMetadataStorageAppT m )
2021-05-26 19:19:26 +03:00
2020-06-16 18:23:06 +03:00
--- helper functions ---
2023-02-08 04:46:21 +03:00
mkConsoleHTML :: Text -> AuthMode -> TelemetryStatus -> Maybe Text -> Maybe Text -> Either String Text
2022-09-27 17:50:32 +03:00
mkConsoleHTML path authMode enableTelemetry consoleAssetsDir consoleSentryDsn =
2019-11-26 15:14:21 +03:00
renderHtmlTemplate consoleTmplt $
2021-09-24 01:56:37 +03:00
-- variables required to render the template
A . object
[ " isAdminSecretSet " A ..= isAdminSecretSet authMode ,
" consolePath " A ..= consolePath ,
2023-02-08 04:46:21 +03:00
" enableTelemetry " A ..= boolToText ( isTelemetryEnabled enableTelemetry ) ,
2021-09-24 01:56:37 +03:00
" cdnAssets " A ..= boolToText ( isNothing consoleAssetsDir ) ,
2022-09-27 17:50:32 +03:00
" consoleSentryDsn " A ..= fromMaybe " " consoleSentryDsn ,
2021-09-24 01:56:37 +03:00
" assetsVersion " A ..= consoleAssetsVersion ,
2022-09-15 19:59:00 +03:00
" serverVersion " A ..= currentVersion ,
" consoleSentryDsn " A ..= ( " " :: Text )
2021-09-24 01:56:37 +03:00
]
where
consolePath = case path of
" " -> " /console "
r -> " /console/ " <> r
consoleTmplt = $ ( makeRelativeToProject " src-rsr/console.html " >>= M . embedSingleTemplate )
2019-11-26 15:14:21 +03:00
2022-11-29 04:00:28 +03:00
telemetryNotice :: Text
2019-11-26 15:14:21 +03:00
telemetryNotice =
" Help us improve Hasura! The graphql-engine server collects anonymized "
2021-09-24 01:56:37 +03:00
<> " usage stats which allows us to keep improving Hasura at warp speed. "
<> " To read more or opt-out, visit https://hasura.io/docs/latest/graphql/core/guides/telemetry.html "
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
mkPgSourceResolver :: PG . PGLogger -> SourceResolver ( 'Postgres 'Vanilla )
2023-02-20 16:43:34 +03:00
mkPgSourceResolver pgLogger env _ config = runExceptT do
Clean metadata arguments
## Description
Thanks to #1664, the Metadata API types no longer require a `ToJSON` instance. This PR follows up with a cleanup of the types of the arguments to the metadata API:
- whenever possible, it moves those argument types to where they're used (RQL.DDL.*)
- it removes all unrequired instances (mostly `ToJSON`)
This PR does not attempt to do it for _all_ such argument types. For some of the metadata operations, the type used to describe the argument to the API and used to represent the value in the metadata are one and the same (like for `CreateEndpoint`). Sometimes, the two types are intertwined in complex ways (`RemoteRelationship` and `RemoteRelationshipDef`). In the spirit of only doing uncontroversial cleaning work, this PR only moves types that are not used outside of RQL.DDL.
Furthermore, this is a small step towards separating the different types all jumbled together in RQL.Types.
## Notes
This PR also improves several `FromJSON` instances to make use of `withObject`, and to use a human readable string instead of a type name in error messages whenever possible. For instance:
- before: `expected Object for Object, but encountered X`
after: `expected Object for add computed field, but encountered X`
- before: `Expecting an object for update query`
after: `expected Object for update query, but encountered X`
This PR also renames `CreateFunctionPermission` to `FunctionPermissionArgument`, to remove the quite surprising `type DropFunctionPermission = CreateFunctionPermission`.
This PR also deletes some dead code, mostly in RQL.DML.
This PR also moves a PG-specific source resolving function from DDL.Schema.Source to the only place where it is used: App.hs.
https://github.com/hasura/graphql-engine-mono/pull/1844
GitOrigin-RevId: a594521194bb7fe6a111b02a9e099896f9fed59c
2021-07-27 13:41:42 +03:00
let PostgresSourceConnInfo urlConf poolSettings allowPrepare isoLevel _ = _pccConnectionInfo config
-- If the user does not provide values for the pool settings, then use the default values
let ( maxConns , idleTimeout , retries ) = getDefaultPGPoolSettingIfNotExists poolSettings defaultPostgresPoolSettings
urlText <- resolveUrlConf env urlConf
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
let connInfo = PG . ConnInfo retries $ PG . CDDatabaseURI $ txtToBs urlText
2021-09-24 01:56:37 +03:00
connParams =
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
PG . defaultConnParams
{ PG . cpIdleTime = idleTimeout ,
PG . cpConns = maxConns ,
PG . cpAllowPrepare = allowPrepare ,
PG . cpMbLifetime = _ppsConnectionLifetime =<< poolSettings ,
PG . cpTimeout = _ppsPoolTimeout =<< poolSettings
2021-09-24 01:56:37 +03:00
}
2022-10-17 11:04:54 +03:00
pgPool <- liftIO $ Q . initPGPool connInfo connParams pgLogger
let pgExecCtx = mkPGExecCtx isoLevel pgPool NeverResizePool
2023-01-25 10:12:53 +03:00
pure $ PGSourceConfig pgExecCtx connInfo Nothing mempty ( _pccExtensionsSchema config ) mempty Nothing
2022-01-04 14:53:50 +03:00
mkMSSQLSourceResolver :: SourceResolver ( 'MSSQL )
2023-02-20 16:43:34 +03:00
mkMSSQLSourceResolver env _name ( MSSQLConnConfiguration connInfo _ ) = runExceptT do
2022-10-17 11:04:54 +03:00
let MSSQLConnectionInfo iConnString MSSQLPoolSettings { .. } = connInfo
connOptions =
MSPool . ConnectionOptions
{ _coConnections = fromMaybe defaultMSSQLMaxConnections _mpsMaxConnections ,
_coStripes = 1 ,
_coIdleTime = _mpsIdleTimeout
}
( connString , mssqlPool ) <- createMSSQLPool iConnString connOptions env
let mssqlExecCtx = mkMSSQLExecCtx mssqlPool NeverResizePool
2022-01-04 14:53:50 +03:00
pure $ MSSQLSourceConfig connString mssqlExecCtx