Skip to content

Commit

Permalink
Share EKG Store
Browse files Browse the repository at this point in the history
  • Loading branch information
Naveenaidu committed Aug 11, 2020
1 parent db88603 commit 8f296f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion server/src-exec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import qualified Database.PG.Query as Q
import qualified Hasura.Tracing as Tracing
import qualified System.Exit as Sys
import qualified System.Posix.Signals as Signals
import qualified System.Metrics as EKG


main :: IO ()
main = do
Expand All @@ -40,6 +42,7 @@ runApp env (HGEOptionsG rci hgeCmd) =
withVersion $$(getVersionFromEnvironment) $ case hgeCmd of
HCServe serveOptions -> do
(initCtx, initTime) <- initialiseCtx env hgeCmd rci
ekgStore <- liftIO EKG.newStore
let shutdownApp = return ()
-- Catches the SIGTERM signal and initiates a graceful shutdown.
-- Graceful shutdown for regular HTTP requests is already implemented in
Expand All @@ -50,7 +53,7 @@ runApp env (HGEOptionsG rci hgeCmd) =
Signals.sigTERM
(Signals.CatchOnce (shutdownGracefully initCtx))
Nothing
runHGEServer env serveOptions initCtx Nothing initTime shutdownApp Nothing
runHGEServer env serveOptions initCtx Nothing initTime shutdownApp Nothing ekgStore

HCExport -> do
(initCtx, _) <- initialiseCtx env hgeCmd rci
Expand Down
6 changes: 5 additions & 1 deletion server/src-lib/Hasura/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ import Hasura.Session
import qualified Hasura.GraphQL.Execute.LiveQuery.Poll as EL
import qualified Hasura.GraphQL.Transport.WebSocket.Server as WS
import qualified Hasura.Tracing as Tracing
import qualified System.Metrics as EKG


data ExitCode
= InvalidEnvironmentVariableOptionsError
Expand Down Expand Up @@ -308,8 +310,9 @@ runHGEServer
-> IO ()
-- ^ shutdown function
-> Maybe EL.LiveQueryPostPollHook
-> EKG.Store
-> m ()
runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp postPollHook = do
runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp postPollHook ekgStore = do
-- Comment this to enable expensive assertions from "GHC.AssertNF". These
-- will log lines to STDOUT containing "not in normal form". In the future we
-- could try to integrate this into our tests. For now this is a development
Expand Down Expand Up @@ -351,6 +354,7 @@ runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp pos
soResponseInternalErrorsConfig
postPollHook
_icSchemaCache
ekgStore

-- log inconsistent schema objects
inconsObjs <- scInconsistentObjs <$> liftIO (getSCFromRef cacheRef)
Expand Down
5 changes: 2 additions & 3 deletions server/src-lib/Hasura/Server/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,10 @@ mkWaiApp
-> ResponseInternalErrorsConfig
-> Maybe EL.LiveQueryPostPollHook
-> (RebuildableSchemaCache Run, Maybe UTCTime)
-> EKG.Store
-> m HasuraApp
mkWaiApp env isoLevel logger sqlGenCtx enableAL pool pgExecCtxCustom ci httpManager mode corsCfg enableConsole consoleAssetsDir
enableTelemetry instanceId apis lqOpts planCacheOptions responseErrorsConfig liveQueryHook (schemaCache, cacheBuiltTime) = do
enableTelemetry instanceId apis lqOpts planCacheOptions responseErrorsConfig liveQueryHook (schemaCache, cacheBuiltTime) ekgStore = do

(planCache, schemaCacheRef) <- initialiseCache
let getSchemaCache = first lastBuiltSchemaCache <$> readIORef (_scrCache schemaCacheRef)
Expand All @@ -619,8 +620,6 @@ mkWaiApp env isoLevel logger sqlGenCtx enableAL pool pgExecCtxCustom ci httpMana
wsServerEnv <- WS.createWSServerEnv logger pgExecCtx lqState getSchemaCache httpManager
corsPolicy sqlGenCtx enableAL planCache

ekgStore <- liftIO EKG.newStore

let serverCtx = ServerCtx
{ scPGExecCtx = pgExecCtx
, scConnInfo = ci
Expand Down

0 comments on commit 8f296f8

Please sign in to comment.