Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging and tracing to shelley integration tests #1754

Merged
merged 5 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions lib/cli/src/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module Cardano.CLI
, helperTracing
, loggingOptions
, loggingSeverities
, parseLoggingSeverity
, loggingSeverityOrOffReader
, loggingSeverityReader

Expand Down Expand Up @@ -1783,25 +1784,19 @@ forceNtpCheckOption = flag False True $ mempty
<> help "When set, will block and force an NTP check with the server. \
\Otherwise, uses an available cached result."

-- | The lower-case names of all 'Severity' values.
loggingSeverities :: [(String, Severity)]
loggingSeverities =
[ ("debug", Debug)
, ("info", Info)
, ("notice", Notice)
, ("warning", Warning)
, ("error", Error)
, ("critical", Critical)
, ("alert", Alert)
, ("emergency", Emergency)
]
loggingSeverities = [(toLower <$> show s, s) | s <- [minBound .. maxBound]]

loggingSeverityReader :: ReadM Severity
loggingSeverityReader = do
arg <- readerAsk
parseLoggingSeverity :: String -> Either String Severity
parseLoggingSeverity arg =
case lookup (map toLower arg) loggingSeverities of
Just sev -> pure sev
Nothing -> fail $ "unknown logging severity: " ++ arg

loggingSeverityReader :: ReadM Severity
loggingSeverityReader = eitherReader parseLoggingSeverity

loggingSeverityOrOffReader :: ReadM (Maybe Severity)
loggingSeverityOrOffReader = do
arg <- readerAsk
Expand Down
5 changes: 4 additions & 1 deletion lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,11 @@ mkShelleyWallet
)
=> MkApiWallet ctx s ApiWallet
mkShelleyWallet ctx wid cp meta pending progress = do
-- TODO: issue #1750 re-enable querying reward balance when it's faster
reward <- withWorkerCtx @_ @s @k ctx wid liftE liftE $ \wrk -> liftHandler $
W.fetchRewardBalance @_ @s @t @k wrk wid
if False
then W.fetchRewardBalance @_ @s @t @k wrk wid
else pure $ Quantity 0
pure ApiWallet
{ addressPoolGap = ApiT $ getState cp ^. #externalPool . #gap
, balance = ApiT $ WalletBalance
Expand Down
20 changes: 20 additions & 0 deletions lib/core/src/Cardano/Wallet/Logging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module Cardano.Wallet.Logging
, trMessageText
, filterTraceSeverity
, stdoutTextTracer
, BracketLog (..)
, bracketTracer
) where

import Prelude
Expand All @@ -40,6 +42,8 @@ import Control.Monad.IO.Class
( MonadIO (..) )
import Control.Tracer
( Tracer (..), contramap, nullTracer, traceWith )
import Control.Tracer.Observe
( ObserveIndicator (..) )
import Data.Text
( Text )
import Data.Text.Class
Expand Down Expand Up @@ -131,3 +135,19 @@ filterNonEmpty tr = Tracer $ \arg -> do
-- debugging functions in the REPL, when you need a 'Tracer' object.
stdoutTextTracer :: (MonadIO m, ToText a) => Tracer m a
stdoutTextTracer = Tracer $ liftIO . B8.putStrLn . T.encodeUtf8 . toText

data BracketLog = BracketLog Text ObserveIndicator
deriving (Show)

instance ToText BracketLog where
toText (BracketLog name b) =
name <> ": " <> case b of
ObserveBefore -> "start"
ObserveAfter -> "finish"

bracketTracer :: Monad m => Tracer m BracketLog -> Text -> m a -> m a
bracketTracer tr name action = do
traceWith tr $ BracketLog name ObserveBefore
res <- action
traceWith tr $ BracketLog name ObserveAfter
pure res
2 changes: 2 additions & 0 deletions lib/shelley/cardano-wallet-shelley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,14 @@ test-suite integration
, cardano-wallet-launcher
, cardano-wallet-shelley
, cardano-wallet-test-utils
, contra-tracer
, hspec
, http-client
, iohk-monitoring
, random
, temporary
, text
, text-class
build-tools:
cardano-wallet-shelley
type:
Expand Down
Loading