Skip to content

Commit

Permalink
test app: monitor Application under different routes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeier authored and Icelandjack committed Sep 20, 2024
1 parent 14d6a8d commit c8ef498
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
41 changes: 31 additions & 10 deletions bench/ekg-restart-test/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import Network.Wai
import Network.Wai.Handler.Warp
import Network.Wai.Handler.Warp
import System.Metrics
import System.Random
import Network.Wai.Middleware.RequestLogger
import System.Remote.Monitoring.Wai
import Network.HTTP.Types
import qualified Data.Map as Map
import Data.Map (Map)
import Data.Time.Clock.POSIX (getPOSIXTime)

main = m 8000

Expand All @@ -44,12 +46,31 @@ connectedNodes = unsafePerformIO do

m :: Int -> IO ()
m port = do
stores :: [Store] <-
replicateM 5 newStore
say
"run port"
stores :: [Store] <- genStores 5

say $
"run port: " ++ show port

run port do logStdout do app stores

--_ <- forkServerWith (head stores) "localhost" port
--forever $ threadDelay $ 1000 * 1000


genStores :: Int -> IO [Store]
genStores count = do
mapM genStore [1 .. fromIntegral count]
where
getTimeMs = (round . (* 1000)) `fmap` getPOSIXTime

genStore ix = do
let base = ix * 1000
s <- newStore
registerCounter "ekg.server_timestamp_ms" getTimeMs s
registerGauge "myval" ((base +) <$> randomRIO (1, 10)) s
pure s


app :: [Store] -> Application
app stores req send = do
let
Expand All @@ -59,15 +80,15 @@ app stores req send = do
print (queryString req)

case pathInfo req of
[] -> do
print req
monitor (stores !! 2) req send
[] ->
-- ok "Home page"
monitor (head stores) req send
["0"] -> do
ok "/0"
["1"] -> ok "/1"
["2"] -> monitor (stores !! 2) req send
["3"] -> monitor (stores !! 3) req send
["4"] -> monitor (stores !! 4) req send
["2"] -> monitor (stores !! 2) req { pathInfo = tail (pathInfo req) } send
["3"] -> monitor (stores !! 3) req { pathInfo = tail (pathInfo req) } send
["4"] -> monitor (stores !! 4) req { pathInfo = tail (pathInfo req) } send
path -> send do
responseBuilder
do status404
Expand Down
4 changes: 2 additions & 2 deletions bench/ekg-restart-test/ekg-restart-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extra-source-files: CHANGELOG.md

executable ekg-restart-test
main-is: Main.hs
other-modules:
-- other-modules: ImportHidden

-- Modules included in this executable, other than Main.
-- other-modules:
Expand All @@ -48,7 +48,7 @@ executable ekg-restart-test
, text
, containers
, unordered-containers
ghc-options: -threaded
ghc-options: -threaded "-with-rtsopts=-T"

hs-source-dirs: app
default-language: Haskell2010

0 comments on commit c8ef498

Please sign in to comment.