Skip to content

Commit

Permalink
feat(sut): add queue depth and errors to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 10, 2022
1 parent 67ee633 commit 53e8810
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/journal/src/Journal/Internal/Metrics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ incrCounter (Metrics cbuf _) label value = do
where
offset = sizeOfACounter * fromEnum label

decrCounter_ :: (Enum c) => Metrics c h -> c -> Int -> IO ()
decrCounter_ metrics label i = incrCounter metrics label (-i)

getCounter :: (Enum c) => Metrics c h -> c -> IO Int
getCounter (Metrics cbuf _) label = do
readIntOffArrayIx cbuf offset
Expand Down
27 changes: 17 additions & 10 deletions src/sut/dumblog/src/Dumblog/Journal/FrontEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ data FrontEndInfo = FrontEndInfo
{ blockers :: Blocker (Either Response Response)
}

httpFrontend :: Journal -> FrontEndInfo -> Wai.Application
httpFrontend journal (FrontEndInfo blocker) req respond = do
httpFrontend :: Journal -> DumblogMetrics -> FrontEndInfo -> Wai.Application
httpFrontend journal metrics (FrontEndInfo blocker) req respond = do
body <- Wai.strictRequestBody req
let mmethod = case parseMethod $ Wai.requestMethod req of
Left err -> Left $ LBS.fromStrict err
Expand All @@ -48,7 +48,9 @@ httpFrontend journal (FrontEndInfo blocker) req respond = do
Right POST -> Right $ Write (LBS.toStrict body)
_ -> Left $ "Unknown method type require GET/POST"
case mmethod of
Left err -> respond $ Wai.responseLBS status400 [] err
Left err -> do
incrCounter metrics ErrorsEncountered 1
respond $ Wai.responseLBS status400 [] err
Right cmd -> do
key <- newKey blocker
let env = encode (Envelope (sequenceNumber key) cmd)
Expand All @@ -62,29 +64,34 @@ httpFrontend journal (FrontEndInfo blocker) req respond = do
Left err -> do
putStrLn ("httpFrontend, append error 2: " ++ show err)
cancel blocker key
incrCounter metrics ErrorsEncountered 1
respond $ Wai.responseLBS status400 [] (LBS8.pack (show err))
Right () -> do
incrCounter metrics QueueDepth 1
mResp <- timeout (3*1000*1000) (blockUntil key)
-- Journal.dumpJournal journal
case mResp of
Nothing -> do
cancel blocker key
incrCounter metrics ErrorsEncountered 1
respond $ Wai.responseLBS status400 [] "MVar timeout"
Just (Left errMsg) -> respond $ Wai.responseLBS status400 [] errMsg
Just (Left errMsg) -> do
incrCounter metrics ErrorsEncountered 1
respond $ Wai.responseLBS status400 [] errMsg
Just (Right msg) -> respond $ Wai.responseLBS status200 [] msg

runFrontEnd :: Port -> Journal -> DumblogMetrics -> FrontEndInfo -> Maybe (MVar ()) -> IO ()
runFrontEnd port journal metrics feInfo mReady =
runSettings settings (httpFrontend journal feInfo)
runSettings settings (httpFrontend journal metrics feInfo)
where
settings
= setPort port
$ setOnOpen (\_addr -> incrCounter metrics CurrentNumberTransactions 1 >> return True)
$ setOnClose (\_addr -> incrCounter metrics CurrentNumberTransactions (-1))
$ setLogger (\req status _mSize ->
when (status /= status200) $ do
putStrLn ("warp, request: " ++ show req)
putStrLn ("warp, status: " ++ show status)
print =<< Wai.strictRequestBody req)
-- $ setLogger (\req status _mSize ->
-- when (status /= status200) $ do
-- putStrLn ("warp, request: " ++ show req)
-- putStrLn ("warp, status: " ++ show status)
-- print =<< Wai.strictRequestBody req)
$ maybe id (\ready -> setBeforeMainLoop (putMVar ready ())) mReady
$ defaultSettings
1 change: 1 addition & 0 deletions src/sut/dumblog/src/Dumblog/Journal/Metrics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import qualified Journal.Internal.Metrics as Metrics

data DumblogCounters
= CurrentNumberTransactions
| QueueDepth
| ErrorsEncountered
deriving (Eq, Show, Enum, Bounded)

Expand Down
1 change: 1 addition & 0 deletions src/sut/dumblog/src/Dumblog/Journal/Worker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ worker journal metrics (WorkerInfo blocker snapshotFile eventCount untilSnapshot
; (ev', s') <- case val of
{ Nothing -> return (ev, s)
; Just entry -> do
Metrics.decrCounter_ metrics QueueDepth 1
let Envelope key cmd = decode entry
timeIt metrics cmd $ do
{- // in case of decode error
Expand Down
14 changes: 14 additions & 0 deletions src/sut/dumblog/src/Dumblog/Metrics/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ metricsMain = do
eMeta <- journalMetadata dUMBLOG_JOURNAL dumblogOptions
putStrLn ansiClearScreen
displayServiceTime metrics
displayQueueDepth metrics
displayThroughput metrics startTime
displayJournalMetadata eMeta
displayConcurrentConnections metrics
displayErrors metrics
threadDelay 1_000_000

ansiClearScreen :: String
Expand Down Expand Up @@ -67,6 +69,12 @@ displayServiceTime metrics = do
writeCnt (realToFrac writeCnt / totalCnt * 100)
readCnt (realToFrac readCnt / totalCnt * 100)

displayQueueDepth :: DumblogMetrics -> IO ()
displayQueueDepth metrics = do
putStr "\nSaturation (queue depth):"
depth <- getCounter metrics QueueDepth
printf " %d\n" depth

displayThroughput :: DumblogMetrics -> UTCTime -> IO ()
displayThroughput metrics startTime = do
now <- getCurrentTime
Expand Down Expand Up @@ -106,3 +114,9 @@ displayConcurrentConnections metrics = do
putStr "\nConcurrent number of transactions:"
cnt <- getCounter metrics CurrentNumberTransactions
printf " %d\n" cnt

displayErrors :: DumblogMetrics -> IO ()
displayErrors metrics = do
putStr "\nErrors:"
errors <- getCounter metrics ErrorsEncountered
printf " %d\n" errors

0 comments on commit 53e8810

Please sign in to comment.