-
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 to gundeck
- Loading branch information
1 parent
ff18847
commit baac32d
Showing
8 changed files
with
98 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Gundeck.Run where | ||
|
||
import Imports hiding (head) | ||
import Cassandra (runClient, shutdown) | ||
import Cassandra.Schema (versionCheck) | ||
import Control.Exception (finally) | ||
import Control.Lens hiding (enum) | ||
import Data.Metrics.Middleware | ||
import Data.Metrics.Middleware.Prometheus (waiPrometheusMiddleware) | ||
import Data.Metrics.WaiRoute (treeToPaths) | ||
import Data.Text (unpack) | ||
import Gundeck.API (sitemap) | ||
import Gundeck.Env | ||
import Gundeck.Monad | ||
import Gundeck.Options | ||
import Gundeck.React | ||
import Network.Wai as Wai | ||
import Network.Wai.Utilities.Server hiding (serverPort) | ||
import Util.Options | ||
|
||
import qualified Control.Concurrent.Async as Async | ||
import qualified Gundeck.Aws as Aws | ||
import qualified Network.Wai.Middleware.Gzip as GZip | ||
import qualified Network.Wai.Middleware.Gunzip as GZip | ||
import qualified System.Logger as Log | ||
|
||
run :: Opts -> IO () | ||
run o = do | ||
m <- metrics | ||
e <- createEnv m o | ||
runClient (e^.cstate) $ | ||
versionCheck schemaVersion | ||
let l = e^.applog | ||
s <- newSettings $ defaultServer (unpack $ o^.optGundeck.epHost) (o^.optGundeck.epPort) l m | ||
lst <- Async.async $ Aws.execute (e^.awsEnv) (Aws.listen (runDirect e . onEvent)) | ||
runSettingsWithShutdown s (middleware e $ app e) 5 `finally` do | ||
Log.info l $ Log.msg (Log.val "Shutting down ...") | ||
shutdown (e^.cstate) | ||
Async.cancel lst | ||
Log.close (e^.applog) | ||
where | ||
middleware :: Env -> Wai.Middleware | ||
middleware e = waiPrometheusMiddleware sitemap | ||
. measureRequests (e^.monitor) (treeToPaths routes) | ||
. catchErrors (e^.applog) (e^.monitor) | ||
. GZip.gunzip . GZip.gzip GZip.def | ||
app :: Env -> Wai.Application | ||
app e r k = runGundeck e r (route routes r k) | ||
routes = compile sitemap |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
module Main (main) where | ||
|
||
import Imports | ||
import Gundeck.API | ||
import Gundeck.Run (run) | ||
import OpenSSL (withOpenSSL) | ||
|
||
import Util.Options | ||
|
||
main :: IO () | ||
main = withOpenSSL $ do | ||
options <- getOptions desc Nothing defaultPath | ||
runServer options | ||
run options | ||
where | ||
desc = "Gundeck - Push Notification Hub Service" | ||
defaultPath = "/etc/wire/gundeck/conf/gundeck.yaml" |
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,29 @@ | ||
module Metrics where | ||
|
||
import Imports | ||
import TestSetup | ||
import Bilge | ||
import Bilge.Assert | ||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
import Control.Lens ((^.)) | ||
|
||
type TestSignature a = Gundeck -> Http a | ||
|
||
test :: IO TestSetup -> TestName -> (TestSignature a) -> TestTree | ||
test setup n h = testCase n runTest | ||
where | ||
runTest = do | ||
s <- setup | ||
void $ runHttpT (s ^. tsManager) (h (s ^. tsGundeck)) | ||
|
||
tests :: IO TestSetup -> TestTree | ||
tests s = testGroup "Metrics" [test s "prometheus" testPrometheusMetrics] | ||
|
||
testPrometheusMetrics :: Gundeck -> Http () | ||
testPrometheusMetrics gundeck = do | ||
get (runGundeck gundeck . path "/i/metrics") !!! do | ||
const 200 === statusCode | ||
-- Should contain the request duration metric in its output | ||
const (Just "TYPE http_request_duration_seconds histogram") =~= responseBody | ||
|
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