Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #55 from input-output-hk/ksaric/CAD-1471
Browse files Browse the repository at this point in the history
[CAD-1471] Query pool id along with hash when looking for pool info.
  • Loading branch information
ksaric committed Aug 13, 2020
2 parents 8e65add + edb1b9c commit ada32e0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
3 changes: 2 additions & 1 deletion smash.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license: Apache-2.0
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
README.rst
ChangeLog.md

source-repository head
Expand All @@ -37,6 +37,7 @@ library
, DbSyncPlugin
-- DbSync
, Cardano.SmashDbSync
, Cardano.Metrics
-- Migration
, Cardano.Db.Database
, Cardano.Db.Migration
Expand Down
3 changes: 2 additions & 1 deletion src/Cardano/Db/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import Control.Monad.Trans.Except.Extra (left, newExceptT, runExceptT)
import Cardano.Slotting.Slot (SlotNo)

import qualified DB as DB
import Cardano.Metrics

import Cardano.DbSync.DbAction
import Cardano.DbSync.Error
import Cardano.DbSync.Metrics
import Cardano.DbSync.Plugin
import Cardano.DbSync.Types
import Cardano.DbSync.Util
Expand Down
4 changes: 2 additions & 2 deletions src/Cardano/Db/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Database.Esqueleto (Entity, PersistField, SqlExpr,
Value, countRows, desc, entityVal,
from, isNothing, just, limit, not_,
orderBy, select, unValue, val,
where_, (==.), (^.))
where_, (&&.), (==.), (^.))
import Database.Persist.Sql (SqlBackend, selectList)

import Cardano.Db.Error
Expand All @@ -45,7 +45,7 @@ import qualified Cardano.Db.Types as Types
queryPoolMetadata :: MonadIO m => Types.PoolId -> Types.PoolMetadataHash -> ReaderT SqlBackend m (Either DBFail PoolMetadata)
queryPoolMetadata poolId poolMetadataHash = do
res <- select . from $ \ poolMetadata -> do
where_ (poolMetadata ^. PoolMetadataHash ==. val poolMetadataHash)
where_ (poolMetadata ^. PoolMetadataPoolId ==. val poolId &&. poolMetadata ^. PoolMetadataHash ==. val poolMetadataHash)
pure poolMetadata
pure $ maybeToEither (DbLookupPoolMetadataHash poolId poolMetadataHash) entityVal (listToMaybe res)

Expand Down
42 changes: 42 additions & 0 deletions src/Cardano/Metrics.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

module Cardano.Metrics
( Metrics (..)
, makeMetrics
, registerMetricsServer
) where

import Cardano.Prelude

import System.Metrics.Prometheus.Concurrent.RegistryT (RegistryT (..), registerGauge,
runRegistryT, unRegistryT)
import System.Metrics.Prometheus.Metric.Gauge (Gauge)
import System.Metrics.Prometheus.Http.Scrape (serveHttpTextMetricsT)


data Metrics = Metrics
{ mDbHeight :: !Gauge
, mNodeHeight :: !Gauge
, mQueuePre :: !Gauge
, mQueuePost :: !Gauge
, mQueuePostWrite :: !Gauge
}

registerMetricsServer :: Int -> IO (Metrics, Async ())
registerMetricsServer portNumber =
runRegistryT $ do
metrics <- makeMetrics
registry <- RegistryT ask
server <- liftIO . async $ runReaderT (unRegistryT $ serveHttpTextMetricsT portNumber []) registry
pure (metrics, server)

makeMetrics :: RegistryT IO Metrics
makeMetrics =
Metrics
<$> registerGauge "db_block_height" mempty
<*> registerGauge "remote_tip_height" mempty
<*> registerGauge "action_queue_length_pre" mempty
<*> registerGauge "action_queue_length_post" mempty
<*> registerGauge "action_queue_length_post_write" mempty

5 changes: 3 additions & 2 deletions src/Cardano/SmashDbSync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ import Cardano.Client.Subscription (subscrib
import qualified DB as DB

import Cardano.Db.Database
import Cardano.Metrics

import Cardano.DbSync.Config
import Cardano.DbSync.Era
import Cardano.DbSync.Error
import Cardano.DbSync.Metrics
import Cardano.DbSync.Plugin (DbSyncNodePlugin (..))
import Cardano.DbSync.Tracing.ToObjectOrphans ()
import Cardano.DbSync.Types (ConfigFile (..),
Expand Down Expand Up @@ -403,7 +404,7 @@ dbSyncProtocols trce env plugin _version codecs _connectionId =
currentTip <- getCurrentTipBlockNo
logDbState trce
actionQueue <- newDbActionQueue
(metrics, server) <- registerMetricsServer
(metrics, server) <- registerMetricsServer 8080
race_
(race_
(runDbThread trce env plugin metrics actionQueue)
Expand Down

0 comments on commit ada32e0

Please sign in to comment.