Skip to content

Commit

Permalink
add 'startTime' to Ogmios' Health
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Feb 19, 2021
1 parent c280b5d commit bb62010
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ogmios-server/src/Ogmios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import Ogmios.Control.Exception
import Ogmios.Control.MonadAsync
( MonadAsync (..), MonadFork, MonadThread )
import Ogmios.Control.MonadClock
( MonadClock, withDebouncer, _10s )
( MonadClock, getCurrentTime, withDebouncer, _10s )
import Ogmios.Control.MonadLog
( HasSeverityAnnotation (..)
, Logger
Expand Down Expand Up @@ -137,7 +137,7 @@ newEnvironment
-> Options
-> IO (Env App)
newEnvironment tr network options = do
health <- atomically $ newTVar emptyHealth
health <- getCurrentTime >>= atomically . newTVar . emptyHealth
sensors <- newSensors
sampler <- newSampler (contramap OgmiosMetrics tr)
pure $ Env{health,sensors,sampler,network,options}
Expand Down
7 changes: 4 additions & 3 deletions ogmios-server/src/Ogmios/App/Health.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Ogmios.App.Health
) where

import Relude hiding
( STM, TVar, atomically, writeTVar )
( STM, TVar, atomically, readTVar, writeTVar )

import Ogmios.App.Metrics
( RuntimeStats, Sampler, Sensors )
Expand Down Expand Up @@ -58,7 +58,7 @@ import Ogmios.Control.MonadMetrics
import Ogmios.Control.MonadOuroboros
( MonadOuroboros )
import Ogmios.Control.MonadSTM
( MonadSTM (..), TVar, writeTVar )
( MonadSTM (..), TVar, readTVar, writeTVar )
import Ogmios.Data.Health
( Health (..), emptyHealth )

Expand Down Expand Up @@ -144,8 +144,9 @@ healthCheck readTip tvar sensors sampler = do
lastTipUpdate <- Just <$> getCurrentTime
metrics <- Metrics.sample sampler sensors
atomically $ do
Health{startTime} <- readTVar tvar
lastKnownTip <- readTip
let health = Health{ lastKnownTip, lastTipUpdate, metrics }
let health = Health{ startTime, lastKnownTip, lastTipUpdate, metrics }
health <$ writeTVar tvar health

connectHealthCheckClient
Expand Down
11 changes: 7 additions & 4 deletions ogmios-server/src/Ogmios/Data/Health.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import qualified Data.Aeson as Json
-- - A metric store which measure runtime statistics.
-- - An Ouroboros local chain-sync client which follows the chain's tip.
data Health block = Health
{ lastKnownTip :: !(Tip block)
{ startTime :: UTCTime
-- ^ Time at which the application was started
, lastKnownTip :: !(Tip block)
-- ^ Last known tip of the core node.
, lastTipUpdate :: !(Maybe UTCTime)
-- ^ Date at which the last update was received.
Expand All @@ -41,9 +43,10 @@ data Health block = Health
instance ToJSON (Tip block) => ToJSON (Health block) where
toJSON = genericToJSON Json.defaultOptions

emptyHealth :: Health block
emptyHealth = Health
{ lastKnownTip = TipGenesis
emptyHealth :: UTCTime -> Health block
emptyHealth startTime = Health
{ startTime
, lastKnownTip = TipGenesis
, lastTipUpdate = Nothing
, metrics = emptyMetrics
}

0 comments on commit bb62010

Please sign in to comment.