2022-03-16 03:39:21 +03:00
|
|
|
module Main
|
|
|
|
( main,
|
|
|
|
)
|
|
|
|
where
|
2019-03-12 08:46:27 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Control.Concurrent.Extended qualified as C
|
|
|
|
import Control.Exception
|
|
|
|
import Control.Monad.Trans.Managed (ManagedT (..), lowerManagedT)
|
|
|
|
import Data.ByteString.Char8 qualified as BC
|
|
|
|
import Data.Environment qualified as Env
|
|
|
|
import Data.Int (Int64)
|
|
|
|
import Data.Kind (Type)
|
|
|
|
import Data.Text.Conversions (convertText)
|
|
|
|
import Data.Time.Clock (getCurrentTime)
|
|
|
|
import Data.Time.Clock.POSIX (getPOSIXTime)
|
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
|
2023-02-09 01:41:09 +03:00
|
|
|
import GHC.Debug.Stub
|
2021-09-24 01:56:37 +03:00
|
|
|
import GHC.TypeLits (Symbol)
|
|
|
|
import Hasura.App
|
2023-02-24 21:09:36 +03:00
|
|
|
import Hasura.App.State
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.Backends.Postgres.Connection.MonadTx
|
|
|
|
import Hasura.Backends.Postgres.Connection.Settings
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GC qualified as GC
|
|
|
|
import Hasura.Logging (Hasura, LogLevel (..), defaultEnabledEngineLogTypes)
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.DDL.Schema
|
|
|
|
import Hasura.Server.Init
|
|
|
|
import Hasura.Server.Metrics (ServerMetricsSpec, createServerMetrics)
|
|
|
|
import Hasura.Server.Migrate (downgradeCatalog)
|
2022-07-24 00:18:01 +03:00
|
|
|
import Hasura.Server.Prometheus (makeDummyPrometheusMetrics)
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Server.Version
|
2022-11-22 04:36:35 +03:00
|
|
|
import Hasura.ShutdownLatch
|
Rewrite `Tracing` to allow for only one `TraceT` in the entire stack.
This PR is on top of #7789.
### Description
This PR entirely rewrites the API of the Tracing library, to make `interpTraceT` a thing of the past. Before this change, we ran traces by sticking a `TraceT` on top of whatever we were doing. This had several major drawbacks:
- we were carrying a bunch of `TraceT` across the codebase, and the entire codebase had to know about it
- we needed to carry a second class constraint around (`HasReporterM`) to be able to run all of those traces
- we kept having to do stack rewriting with `interpTraceT`, which went from inconvenient to horrible
- we had to declare several behavioral instances on `TraceT m`
This PR rewrite all of `Tracing` using a more conventional model: there is ONE `TraceT` at the bottom of the stack, and there is an associated class constraint `MonadTrace`: any part of the code that happens to satisfy `MonadTrace` is able to create new traces. We NEVER have to do stack rewriting, `interpTraceT` is gone, and `TraceT` and `Reporter` become implementation details that 99% of the code is blissfully unaware of: code that needs to do tracing only needs to declare that the monad in which it operates implements `MonadTrace`.
In doing so, this PR revealed **several bugs in the codebase**: places where we were expecting to trace something, but due to the default instance of `HasReporterM IO` we would actually not do anything. This PR also splits the code of `Tracing` in more byte-sized modules, with the goal of potentially moving to `server/lib` down the line.
### Remaining work
This PR is a draft; what's left to do is:
- [x] make Pro compile; i haven't updated `HasuraPro/Main` yet
- [x] document Tracing by writing a note that explains how to use the library, and the meaning of "reporter", "trace" and "span", as well as the pitfalls
- [x] discuss some of the trade-offs in the implementation, which is why i'm opening this PR already despite it not fully building yet
- [x] it depends on #7789 being merged first
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7791
GitOrigin-RevId: cadd32d039134c93ddbf364599a2f4dd988adea8
2023-03-13 20:37:16 +03:00
|
|
|
import Hasura.Tracing (ignoreTraceT, sampleAlways)
|
2023-02-20 16:43:34 +03:00
|
|
|
import System.Environment (getEnvironment, lookupEnv, unsetEnv)
|
2021-09-24 01:56:37 +03:00
|
|
|
import System.Exit qualified as Sys
|
|
|
|
import System.Metrics qualified as EKG
|
|
|
|
import System.Posix.Signals qualified as Signals
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2023-02-24 00:43:08 +03:00
|
|
|
{-# ANN main ("HLINT: ignore Use env_from_function_argument" :: String) #-}
|
2018-06-27 16:11:32 +03:00
|
|
|
main :: IO ()
|
2023-02-09 01:41:09 +03:00
|
|
|
main = maybeWithGhcDebug $ do
|
2022-03-14 21:31:46 +03:00
|
|
|
catch
|
|
|
|
do
|
|
|
|
env <- Env.getEnvironment
|
2023-02-20 16:43:34 +03:00
|
|
|
clearEnvironment
|
|
|
|
args <- parseArgs env
|
2022-03-14 21:31:46 +03:00
|
|
|
runApp env args
|
|
|
|
(\(ExitException _code msg) -> BC.putStrLn msg >> Sys.exitFailure)
|
2023-02-20 16:43:34 +03:00
|
|
|
where
|
|
|
|
-- Since the handling of environment variables works differently between the
|
|
|
|
-- Cloud version and the OSSS version we clear the process environment to
|
|
|
|
-- avoid accidentally reading directly from the operating system environment
|
|
|
|
-- variables.
|
|
|
|
clearEnvironment :: IO ()
|
|
|
|
clearEnvironment = getEnvironment >>= traverse_ \(v, _) -> unsetEnv v
|
2018-07-27 12:34:50 +03:00
|
|
|
|
2022-07-01 06:39:39 +03:00
|
|
|
runApp :: Env.Environment -> HGEOptions (ServeOptions Hasura) -> IO ()
|
Rewrite `Tracing` to allow for only one `TraceT` in the entire stack.
This PR is on top of #7789.
### Description
This PR entirely rewrites the API of the Tracing library, to make `interpTraceT` a thing of the past. Before this change, we ran traces by sticking a `TraceT` on top of whatever we were doing. This had several major drawbacks:
- we were carrying a bunch of `TraceT` across the codebase, and the entire codebase had to know about it
- we needed to carry a second class constraint around (`HasReporterM`) to be able to run all of those traces
- we kept having to do stack rewriting with `interpTraceT`, which went from inconvenient to horrible
- we had to declare several behavioral instances on `TraceT m`
This PR rewrite all of `Tracing` using a more conventional model: there is ONE `TraceT` at the bottom of the stack, and there is an associated class constraint `MonadTrace`: any part of the code that happens to satisfy `MonadTrace` is able to create new traces. We NEVER have to do stack rewriting, `interpTraceT` is gone, and `TraceT` and `Reporter` become implementation details that 99% of the code is blissfully unaware of: code that needs to do tracing only needs to declare that the monad in which it operates implements `MonadTrace`.
In doing so, this PR revealed **several bugs in the codebase**: places where we were expecting to trace something, but due to the default instance of `HasReporterM IO` we would actually not do anything. This PR also splits the code of `Tracing` in more byte-sized modules, with the goal of potentially moving to `server/lib` down the line.
### Remaining work
This PR is a draft; what's left to do is:
- [x] make Pro compile; i haven't updated `HasuraPro/Main` yet
- [x] document Tracing by writing a note that explains how to use the library, and the meaning of "reporter", "trace" and "span", as well as the pitfalls
- [x] discuss some of the trade-offs in the implementation, which is why i'm opening this PR already despite it not fully building yet
- [x] it depends on #7789 being merged first
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7791
GitOrigin-RevId: cadd32d039134c93ddbf364599a2f4dd988adea8
2023-03-13 20:37:16 +03:00
|
|
|
runApp env (HGEOptions rci metadataDbUrl hgeCmd) = ignoreTraceT do
|
2020-11-24 09:10:04 +03:00
|
|
|
initTime <- liftIO getCurrentTime
|
|
|
|
|
2021-10-13 19:38:56 +03:00
|
|
|
case hgeCmd of
|
2023-03-23 00:40:26 +03:00
|
|
|
HCServe serveOptions@ServeOptions {..} -> do
|
|
|
|
let poolSettings =
|
|
|
|
PostgresPoolSettings
|
|
|
|
{ _ppsMaxConnections = Just $ PG.cpConns soConnParams,
|
|
|
|
_ppsTotalMaxConnections = Nothing,
|
|
|
|
_ppsIdleTimeout = Just $ PG.cpIdleTime soConnParams,
|
|
|
|
_ppsRetries = _pciRetries rci <|> Just 1,
|
|
|
|
_ppsPoolTimeout = PG.cpTimeout soConnParams,
|
|
|
|
_ppsConnectionLifetime = PG.cpMbLifetime soConnParams
|
|
|
|
}
|
|
|
|
basicConnectionInfo <-
|
|
|
|
initBasicConnectionInfo
|
|
|
|
env
|
|
|
|
metadataDbUrl
|
|
|
|
rci
|
|
|
|
(Just poolSettings)
|
|
|
|
(PG.cpAllowPrepare soConnParams)
|
|
|
|
soTxIso
|
2021-08-06 00:07:17 +03:00
|
|
|
(ekgStore, serverMetrics) <- liftIO $ do
|
|
|
|
store <- EKG.newStore @AppMetricsSpec
|
2021-09-22 18:34:53 +03:00
|
|
|
void $ EKG.register (EKG.subset GcSubset store) EKG.registerGcMetrics
|
2020-11-12 12:25:48 +03:00
|
|
|
|
2020-09-08 21:13:35 +03:00
|
|
|
let getTimeMs :: IO Int64
|
|
|
|
getTimeMs = (round . (* 1000)) `fmap` getPOSIXTime
|
2021-09-22 18:34:53 +03:00
|
|
|
void $ EKG.register store $ EKG.registerCounter ServerTimestampMs () getTimeMs
|
2020-09-08 21:13:35 +03:00
|
|
|
|
2021-08-06 00:07:17 +03:00
|
|
|
serverMetrics <-
|
|
|
|
liftIO $ createServerMetrics $ EKG.subset ServerSubset store
|
|
|
|
|
|
|
|
pure (EKG.subset EKG.emptyOf store, serverMetrics)
|
2020-11-12 12:25:48 +03:00
|
|
|
|
Rewrite `Tracing` to allow for only one `TraceT` in the entire stack.
This PR is on top of #7789.
### Description
This PR entirely rewrites the API of the Tracing library, to make `interpTraceT` a thing of the past. Before this change, we ran traces by sticking a `TraceT` on top of whatever we were doing. This had several major drawbacks:
- we were carrying a bunch of `TraceT` across the codebase, and the entire codebase had to know about it
- we needed to carry a second class constraint around (`HasReporterM`) to be able to run all of those traces
- we kept having to do stack rewriting with `interpTraceT`, which went from inconvenient to horrible
- we had to declare several behavioral instances on `TraceT m`
This PR rewrite all of `Tracing` using a more conventional model: there is ONE `TraceT` at the bottom of the stack, and there is an associated class constraint `MonadTrace`: any part of the code that happens to satisfy `MonadTrace` is able to create new traces. We NEVER have to do stack rewriting, `interpTraceT` is gone, and `TraceT` and `Reporter` become implementation details that 99% of the code is blissfully unaware of: code that needs to do tracing only needs to declare that the monad in which it operates implements `MonadTrace`.
In doing so, this PR revealed **several bugs in the codebase**: places where we were expecting to trace something, but due to the default instance of `HasReporterM IO` we would actually not do anything. This PR also splits the code of `Tracing` in more byte-sized modules, with the goal of potentially moving to `server/lib` down the line.
### Remaining work
This PR is a draft; what's left to do is:
- [x] make Pro compile; i haven't updated `HasuraPro/Main` yet
- [x] document Tracing by writing a note that explains how to use the library, and the meaning of "reporter", "trace" and "span", as well as the pitfalls
- [x] discuss some of the trade-offs in the implementation, which is why i'm opening this PR already despite it not fully building yet
- [x] it depends on #7789 being merged first
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7791
GitOrigin-RevId: cadd32d039134c93ddbf364599a2f4dd988adea8
2023-03-13 20:37:16 +03:00
|
|
|
prometheusMetrics <- lift makeDummyPrometheusMetrics
|
2022-07-24 00:18:01 +03:00
|
|
|
|
2020-12-21 21:56:00 +03:00
|
|
|
-- It'd be nice if we didn't have to call runManagedT twice here, but
|
|
|
|
-- there is a data dependency problem since the call to runPGMetadataStorageApp
|
2023-02-24 21:09:36 +03:00
|
|
|
-- below depends on appCtx.
|
2023-03-23 00:40:26 +03:00
|
|
|
runManagedT (initialiseContext env basicConnectionInfo serveOptions Nothing serverMetrics prometheusMetrics sampleAlways) $ \(appStateRef, appEnv) -> do
|
2020-12-21 21:56:00 +03:00
|
|
|
-- Catches the SIGTERM signal and initiates a graceful shutdown.
|
|
|
|
-- Graceful shutdown for regular HTTP requests is already implemented in
|
|
|
|
-- Warp, and is triggered by invoking the 'closeSocket' callback.
|
|
|
|
-- We only catch the SIGTERM signal once, that is, if the user hits CTRL-C
|
|
|
|
-- once again, we terminate the process immediately.
|
2021-02-12 04:34:00 +03:00
|
|
|
|
2023-01-06 12:33:13 +03:00
|
|
|
liftIO $ do
|
2023-02-24 21:09:36 +03:00
|
|
|
void $ Signals.installHandler Signals.sigTERM (Signals.CatchOnce (shutdownGracefully $ appEnvShutdownLatch appEnv)) Nothing
|
|
|
|
void $ Signals.installHandler Signals.sigINT (Signals.CatchOnce (shutdownGracefully $ appEnvShutdownLatch appEnv)) Nothing
|
2020-12-28 15:56:00 +03:00
|
|
|
|
2023-02-24 21:09:36 +03:00
|
|
|
let Loggers _ logger _ = appEnvLoggers appEnv
|
2021-04-06 06:25:02 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
_idleGCThread <-
|
Rewrite `Tracing` to allow for only one `TraceT` in the entire stack.
This PR is on top of #7789.
### Description
This PR entirely rewrites the API of the Tracing library, to make `interpTraceT` a thing of the past. Before this change, we ran traces by sticking a `TraceT` on top of whatever we were doing. This had several major drawbacks:
- we were carrying a bunch of `TraceT` across the codebase, and the entire codebase had to know about it
- we needed to carry a second class constraint around (`HasReporterM`) to be able to run all of those traces
- we kept having to do stack rewriting with `interpTraceT`, which went from inconvenient to horrible
- we had to declare several behavioral instances on `TraceT m`
This PR rewrite all of `Tracing` using a more conventional model: there is ONE `TraceT` at the bottom of the stack, and there is an associated class constraint `MonadTrace`: any part of the code that happens to satisfy `MonadTrace` is able to create new traces. We NEVER have to do stack rewriting, `interpTraceT` is gone, and `TraceT` and `Reporter` become implementation details that 99% of the code is blissfully unaware of: code that needs to do tracing only needs to declare that the monad in which it operates implements `MonadTrace`.
In doing so, this PR revealed **several bugs in the codebase**: places where we were expecting to trace something, but due to the default instance of `HasReporterM IO` we would actually not do anything. This PR also splits the code of `Tracing` in more byte-sized modules, with the goal of potentially moving to `server/lib` down the line.
### Remaining work
This PR is a draft; what's left to do is:
- [x] make Pro compile; i haven't updated `HasuraPro/Main` yet
- [x] document Tracing by writing a note that explains how to use the library, and the meaning of "reporter", "trace" and "span", as well as the pitfalls
- [x] discuss some of the trade-offs in the implementation, which is why i'm opening this PR already despite it not fully building yet
- [x] it depends on #7789 being merged first
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7791
GitOrigin-RevId: cadd32d039134c93ddbf364599a2f4dd988adea8
2023-03-13 20:37:16 +03:00
|
|
|
lift $
|
|
|
|
C.forkImmortal "ourIdleGC" logger $
|
|
|
|
GC.ourIdleGC logger (seconds 0.3) (seconds 10) (seconds 60)
|
2020-12-28 15:56:00 +03:00
|
|
|
|
2023-03-17 13:29:07 +03:00
|
|
|
runPGMetadataStorageAppT appEnv $
|
Rewrite `Tracing` to allow for only one `TraceT` in the entire stack.
This PR is on top of #7789.
### Description
This PR entirely rewrites the API of the Tracing library, to make `interpTraceT` a thing of the past. Before this change, we ran traces by sticking a `TraceT` on top of whatever we were doing. This had several major drawbacks:
- we were carrying a bunch of `TraceT` across the codebase, and the entire codebase had to know about it
- we needed to carry a second class constraint around (`HasReporterM`) to be able to run all of those traces
- we kept having to do stack rewriting with `interpTraceT`, which went from inconvenient to horrible
- we had to declare several behavioral instances on `TraceT m`
This PR rewrite all of `Tracing` using a more conventional model: there is ONE `TraceT` at the bottom of the stack, and there is an associated class constraint `MonadTrace`: any part of the code that happens to satisfy `MonadTrace` is able to create new traces. We NEVER have to do stack rewriting, `interpTraceT` is gone, and `TraceT` and `Reporter` become implementation details that 99% of the code is blissfully unaware of: code that needs to do tracing only needs to declare that the monad in which it operates implements `MonadTrace`.
In doing so, this PR revealed **several bugs in the codebase**: places where we were expecting to trace something, but due to the default instance of `HasReporterM IO` we would actually not do anything. This PR also splits the code of `Tracing` in more byte-sized modules, with the goal of potentially moving to `server/lib` down the line.
### Remaining work
This PR is a draft; what's left to do is:
- [x] make Pro compile; i haven't updated `HasuraPro/Main` yet
- [x] document Tracing by writing a note that explains how to use the library, and the meaning of "reporter", "trace" and "span", as well as the pitfalls
- [x] discuss some of the trade-offs in the implementation, which is why i'm opening this PR already despite it not fully building yet
- [x] it depends on #7789 being merged first
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7791
GitOrigin-RevId: cadd32d039134c93ddbf364599a2f4dd988adea8
2023-03-13 20:37:16 +03:00
|
|
|
lowerManagedT $
|
2023-03-21 18:49:48 +03:00
|
|
|
runHGEServer (const $ pure ()) appStateRef initTime Nothing ekgStore
|
2018-12-19 14:38:33 +03:00
|
|
|
HCExport -> do
|
2023-03-23 00:40:26 +03:00
|
|
|
metadataConnection <- initMetadataConnectionInfo env metadataDbUrl rci
|
|
|
|
res <- runTxWithMinimalPool metadataConnection fetchMetadataFromCatalog
|
2022-03-14 21:31:46 +03:00
|
|
|
either (throwErrJExit MetadataExportError) printJSON res
|
2018-12-19 14:38:33 +03:00
|
|
|
HCClean -> do
|
2023-03-23 00:40:26 +03:00
|
|
|
metadataConnection <- initMetadataConnectionInfo env metadataDbUrl rci
|
|
|
|
res <- runTxWithMinimalPool metadataConnection dropHdbCatalogSchema
|
2020-11-24 09:10:04 +03:00
|
|
|
let cleanSuccessMsg = "successfully cleaned graphql-engine related data"
|
2022-03-14 21:31:46 +03:00
|
|
|
either (throwErrJExit MetadataCleanError) (const $ liftIO $ putStrLn cleanSuccessMsg) res
|
2020-02-07 14:03:12 +03:00
|
|
|
HCDowngrade opts -> do
|
2023-03-23 00:40:26 +03:00
|
|
|
let poolSettings = setPostgresPoolSettings {_ppsRetries = _pciRetries rci <|> Just 1}
|
|
|
|
BasicConnectionInfo {..} <- initBasicConnectionInfo env metadataDbUrl rci (Just poolSettings) False PG.ReadCommitted
|
|
|
|
res <- runTxWithMinimalPool bciMetadataConnInfo $ downgradeCatalog bciDefaultPostgres opts initTime
|
2022-03-14 21:31:46 +03:00
|
|
|
either (throwErrJExit DowngradeProcessError) (liftIO . print) res
|
2020-01-23 00:55:55 +03:00
|
|
|
HCVersion -> liftIO $ putStrLn $ "Hasura GraphQL Engine: " ++ convertText currentVersion
|
2019-11-26 15:14:21 +03:00
|
|
|
where
|
2020-12-21 21:56:00 +03:00
|
|
|
runTxWithMinimalPool connInfo tx = lowerManagedT $ do
|
2020-11-24 09:10:04 +03:00
|
|
|
minimalPool <- mkMinimalPool connInfo
|
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
|
|
|
liftIO $ runExceptT $ PG.runTx minimalPool (PG.ReadCommitted, Nothing) tx
|
2020-11-24 09:10:04 +03:00
|
|
|
|
|
|
|
mkMinimalPool connInfo = do
|
|
|
|
pgLogger <- _lsPgLogger <$> mkLoggers defaultEnabledEngineLogTypes LevelInfo
|
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 connParams = PG.defaultConnParams {PG.cpConns = 1}
|
|
|
|
liftIO $ PG.initPGPool connInfo connParams pgLogger
|
2021-08-06 00:07:17 +03:00
|
|
|
|
|
|
|
-- | A specification of all EKG metrics tracked in `runApp`.
|
2021-09-24 01:56:37 +03:00
|
|
|
data
|
|
|
|
AppMetricsSpec ::
|
|
|
|
Symbol -> -- Metric name
|
|
|
|
EKG.MetricType -> -- Metric type, e.g. Counter, Gauge
|
|
|
|
Type -> -- Tag structure
|
|
|
|
Type
|
2021-08-06 00:07:17 +03:00
|
|
|
where
|
2021-09-24 01:56:37 +03:00
|
|
|
ServerSubset ::
|
|
|
|
ServerMetricsSpec name metricType tags ->
|
|
|
|
AppMetricsSpec name metricType tags
|
|
|
|
GcSubset ::
|
|
|
|
EKG.GcMetrics name metricType tags ->
|
|
|
|
AppMetricsSpec name metricType tags
|
|
|
|
ServerTimestampMs ::
|
|
|
|
AppMetricsSpec "ekg.server_timestamp_ms" 'EKG.CounterType ()
|
2023-02-09 01:41:09 +03:00
|
|
|
|
|
|
|
-- | 'withGhcDebug' but conditional on the environment variable
|
|
|
|
-- @HASURA_GHC_DEBUG=true@. When this is set a debug socket will be opened,
|
|
|
|
-- otherwise the server will start normally. This must only be called once and
|
|
|
|
-- it's argument should be the program's @main@
|
|
|
|
maybeWithGhcDebug :: IO a -> IO a
|
|
|
|
maybeWithGhcDebug theMain = do
|
|
|
|
lookupEnv "HASURA_GHC_DEBUG" >>= \case
|
|
|
|
Just "true" -> do
|
|
|
|
putStrLn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
|
|
putStrLn "!!!!! Opening a ghc-debug socket !!!!!"
|
|
|
|
putStrLn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
|
|
withGhcDebug theMain
|
|
|
|
_ -> theMain
|