-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Prometheus middleware for gundeck, cannon, cargohold, brig, proxy (…
…#672) * Add prometheus middleware to remaining services (all except galley) REFACTOR: refactor tests to use TestSetup module REFACTOR: refactor services to use 'Run' module
- Loading branch information
1 parent
c63d592
commit 1be7003
Showing
31 changed files
with
366 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Brig.Run (run) where | ||
|
||
import Imports hiding (head) | ||
import Brig.App | ||
import Brig.API (sitemap) | ||
import Brig.AWS (sesQueue) | ||
import Brig.API.Handler | ||
import Brig.Options hiding (internalEvents, sesQueue) | ||
import Control.Monad.Catch (finally) | ||
import Control.Lens ((^.)) | ||
import Data.Metrics.WaiRoute (treeToPaths) | ||
import Data.Text (unpack) | ||
import Network.Wai.Utilities.Server | ||
import Util.Options | ||
|
||
import qualified Control.Concurrent.Async as Async | ||
import qualified Brig.Queue as Queue | ||
import qualified Brig.AWS as AWS | ||
import qualified Brig.AWS.SesNotification as SesNotification | ||
import qualified Brig.InternalEvent.Process as Internal | ||
import qualified Network.Wai as Wai | ||
import qualified Network.Wai.Middleware.Gzip as GZip | ||
import qualified Network.Wai.Middleware.Gunzip as GZip | ||
import qualified Data.Metrics.Middleware.Prometheus as Metrics | ||
import qualified Network.Wai.Utilities.Server as Server | ||
|
||
|
||
run :: Opts -> IO () | ||
run o = do | ||
e <- newEnv o | ||
s <- Server.newSettings (server e) | ||
emailListener <- for (e^.awsEnv.sesQueue) $ \q -> | ||
Async.async $ | ||
AWS.execute (e^.awsEnv) $ | ||
AWS.listen q (runAppT e . SesNotification.onEvent) | ||
internalEventListener <- Async.async $ | ||
runAppT e $ Queue.listen (e^.internalEvents) Internal.onEvent | ||
runSettingsWithShutdown s (middleware e $ serve e) 5 `finally` do | ||
mapM_ Async.cancel emailListener | ||
Async.cancel internalEventListener | ||
closeEnv e | ||
where | ||
rtree = compile (sitemap o) | ||
endpoint = brig o | ||
server e = defaultServer (unpack $ endpoint^.epHost) (endpoint^.epPort) (e^.applog) (e^.metrics) | ||
middleware :: Env -> Wai.Middleware | ||
middleware e = Metrics.waiPrometheusMiddleware (sitemap o) | ||
. measureRequests (e^.metrics) (treeToPaths rtree) | ||
. catchErrors (e^.applog) (e^.metrics) | ||
. GZip.gunzip . GZip.gzip GZip.def | ||
serve e r k = runHandler e r (Server.route rtree r k) k | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.