Skip to content

Commit

Permalink
Late fixes
Browse files Browse the repository at this point in the history
Build fixes


Hlint fix


Build patch


cardano-tracer: test-ext


More fixes
  • Loading branch information
jutaro committed Jan 20, 2023
1 parent 03b7836 commit 3b70450
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 65 deletions.
3 changes: 2 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ import Ouroboros.Consensus.Util.Enclose

import qualified Ouroboros.Network.AnchoredFragment as AF

-- {-# ANN module ("HLint: ignore Redundant bracket" :: Text) #-}
{-# ANN module ("HLint: ignore Redundant bracket" :: Text) #-}

-- TODO implement differently so that it uses configuration
withAddedToCurrentChainEmptyLimited
:: Trace IO (ChainDB.TraceEvent blk)
Expand Down
3 changes: 3 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/NodeToClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

module Cardano.Node.Tracing.Tracers.NodeToClient () where


import Cardano.Logging
import Cardano.Prelude hiding (Show, show)
import Data.Aeson (Value (String), (.=))
Expand All @@ -24,6 +25,8 @@ import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as LSQ
import qualified Ouroboros.Network.Protocol.LocalTxMonitor.Type as LTM
import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Type as LTS

{-# ANN module ("HLint: ignore Redundant bracket" :: Text) #-}


instance LogFormatting (AnyMessageAndAgency ps)
=> LogFormatting (TraceSendRecv ps) where
Expand Down
1 change: 0 additions & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers/NonP2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

{-# OPTIONS_GHC -Wno-orphans #-}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Cardano.Logging
config1 :: TraceConfig
config1 = emptyTraceConfig {
tcOptions = fromList
[([] :: Namespace,
[([],
[ ConfSeverity (SeverityF (Just Debug))
, ConfDetail DNormal
, ConfBackend [Stdout HumanFormatColoured, Forwarder, EKGBackend]
Expand All @@ -28,7 +28,7 @@ config1 = emptyTraceConfig {
config2 :: TraceConfig
config2 = emptyTraceConfig {
tcOptions = fromList
[ ([] :: Namespace,
[ ([],
[ ConfSeverity (SeverityF (Just Debug))
, ConfDetail DNormal
, ConfBackend [Stdout HumanFormatColoured, Forwarder, EKGBackend]
Expand All @@ -50,7 +50,7 @@ config2 = emptyTraceConfig {
config3 :: TraceConfig
config3 = emptyTraceConfig {
tcOptions = fromList
[ ([] :: Namespace,
[ ([],
[ ConfSeverity (SeverityF (Just Debug))
, ConfDetail DNormal
, ConfBackend [Stdout HumanFormatColoured, Forwarder, EKGBackend]
Expand All @@ -73,7 +73,7 @@ config3 = emptyTraceConfig {
config4 :: TraceConfig
config4 = emptyTraceConfig {
tcOptions = fromList
[([] :: Namespace,
[([],
[ ConfSeverity (SeverityF (Just Debug))
, ConfDetail DNormal
, ConfBackend [EKGBackend]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
module Cardano.Tracer.Test.ForwardingStressTest.Messages (
namesForMessage
, severityForMessage
, privacyForMessage
, docMessage
, getMessageID
getMessageID
, setMessageID
) where

import Data.Text

import Cardano.Logging
import Cardano.Tracer.Test.ForwardingStressTest.Types
Expand All @@ -22,33 +17,35 @@ setMessageID (Message1 _ v) mid = Message1 mid v
setMessageID (Message2 _ v) mid = Message2 mid v
setMessageID (Message3 _ v) mid = Message3 mid v

namesForMessage :: Message -> [Text]
namesForMessage Message1 {} = ["Message1"]
namesForMessage Message2 {} = ["Message2"]
namesForMessage Message3 {} = ["Message3"]

severityForMessage :: Message -> SeverityS
severityForMessage Message1 {} = Debug
severityForMessage Message2 {} = Info
severityForMessage Message3 {} = Error

privacyForMessage :: Message -> Privacy
privacyForMessage Message1 {} = Public
privacyForMessage Message2 {} = Confidential
privacyForMessage Message3 {} = Public

docMessage :: Documented Message
docMessage = Documented [
DocMsg
["Message1"]
[]
"The first message."
, DocMsg
["Message2"]
[]
"The second message."
, DocMsg
["Message3"]
[("Metrics1", "A number")]
"The third message."
]
instance MetaTrace Message where
namespaceFor Message1 {} = Namespace [] ["Message1"]
namespaceFor Message2 {} = Namespace [] ["Message2"]
namespaceFor Message3 {} = Namespace [] ["Message3"]

severityFor (Namespace _ ["Message1"]) _ = Just Debug
severityFor (Namespace _ ["Message2"]) _ = Just Info
severityFor (Namespace _ ["Message3"]) _ = Just Error
severityFor _ns _ = Nothing

privacyFor (Namespace _ ["Message1"]) _ = Just Public
privacyFor (Namespace _ ["Message2"]) _ = Just Confidential
privacyFor (Namespace _ ["Message3"]) _ = Just Public
privacyFor _ns _ = Nothing

documentFor (Namespace _ ["Message1"]) = Just "The first message."
documentFor (Namespace _ ["Message2"]) = Just "The second message."
documentFor (Namespace _ ["Message3"]) = Just "The third message."
documentFor _ns = Nothing

metricsDocFor (Namespace _ ["Message1"]) =
[ ("Metrics1", "A number")
, ("Metrics2", "A number")
, ("Metrics3", "A number")
, ("Metrics4", "A number")
, ("Metrics5", "A number")
]
metricsDocFor _ = []

allNamespaces = [ Namespace [] ["Message1"]
, Namespace [] ["Message2"]
, Namespace [] ["Message3"]]
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Cardano.Tracer.Test.Utils
simpleTestConfig :: TraceConfig
simpleTestConfig = emptyTraceConfig {
tcOptions = fromList
[([] :: Namespace,
[([],
[ ConfSeverity (SeverityF (Just Debug))
, ConfDetail DNormal
, ConfBackend [Forwarder]
Expand All @@ -50,29 +50,25 @@ runScriptForwarding ::
-> IORef Int
-> IO (Trace IO Message)
-> Property
runScriptForwarding ts@TestSetup{..} msgCounter tracerGetter =
trace ("Test setup " ++ show ts) $ do
runScriptForwarding TestSetup{..} msgCounter tracerGetter = do
let generator :: Gen [Script] = vectorOf (unI tsThreads) $
case unI tsMessages of
Nothing -> scale (* 1000) arbitrary
Just numMsg -> Script <$> vectorOf numMsg arbitrary
forAll generator (\ (scripts :: [Script])
-> ioProperty $ do
tr <- tracerGetter
configureTracers simpleTestConfig docMessage [tr]
let scripts' = map (\ (Script sc) -> Script
$ filter (\(ScriptedMessage _ msg) ->
namesForMessage msg /= ["Message2"]) sc) scripts
scripts'' = map (\ (Script sc) -> Script (sort sc)) scripts'
scripts''' = zipWith (\ (Script sc) ind -> Script (
withMessageIds (unI tsThreads) ind sc)) scripts'' [0..]
scripts'''' = map (\ (Script sc) -> Script
$ map (withTimeFactor (unI tsTime)) sc) scripts'''
configureTracers simpleTestConfig [tr]
let scripts' = map (\ (Script sc) -> Script (sort sc)) scripts
scripts'' = zipWith (\ (Script sc) ind -> Script (
withMessageIds (unI tsThreads) ind sc)) scripts' [0..]
scripts''' = map (\ (Script sc) -> Script
$ map (withTimeFactor (unI tsTime)) sc) scripts''


-- putStrLn ("runTest " ++ show scripts)
children :: MVar [MVar (Either SomeException ())] <- newMVar []
mapM_ (\sc -> forkChild children (playIt sc tr 0.0)) scripts''''
mapM_ (\sc -> forkChild children (playIt sc tr 0.0)) scripts'''
res <- waitForChildren children []
let resErr = mapMaybe
(\case
Expand All @@ -82,7 +78,7 @@ runScriptForwarding ts@TestSetup{..} msgCounter tracerGetter =
if not (null resErr)
then throw (head resErr)
else -- Oracle
let numMsg = sum (map (\ (Script sc) -> length sc) scripts'''')
let numMsg = sum (map (\ (Script sc) -> length sc) scripts''')
in if numMsg > 0 then do
-- TODO mutiple files
let logfileGlobPattern = unI tsWorkDir <> "/logs/*sock@*/node-*.json"
Expand Down
4 changes: 1 addition & 3 deletions cardano-tracer/test/cardano-tracer-test-ext.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Test.Tasty
import Test.Tasty.QuickCheck

import Cardano.Logging
import Cardano.Tracer.Test.ForwardingStressTest.Messages
import Cardano.Tracer.Test.ForwardingStressTest.Script
import Cardano.Tracer.Test.ForwardingStressTest.Types
import Cardano.Tracer.Test.Utils
Expand All @@ -38,7 +37,7 @@ main = do
, tsSockInternal = Last $ Just "tracer.sock"
, tsSockExternal = Last $ Just "tracer.sock"
, tsNetworkMagic = Last $ Just $ NetworkMagic 42
, tsWorkDir = Last $ Just "./test"
, tsWorkDir = Last $ Just "/tmp/testTracerExt"
}

-- 1. Prepare directory hierarchy
Expand Down Expand Up @@ -96,7 +95,6 @@ getExternalTracerState TestSetup{..} ref = do
tr <- mkCardanoTracer
stdTr fwdTr Nothing
["Test"]
namesForMessage severityForMessage privacyForMessage
let st = (procHdl, tr)
writeIORef ref $ Just st
pure st
Expand Down
8 changes: 8 additions & 0 deletions cardano-tracer/test/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
networkMagic: 42
network:
tag: AcceptAt
contents: "tracer.sock"
logging:
- logRoot: "/tmp/logs"
logMode: FileMode
logFormat: ForMachine
1 change: 0 additions & 1 deletion trace-dispatcher/src/Cardano/Logging/FrequencyLimiter.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

Expand Down
1 change: 0 additions & 1 deletion trace-dispatcher/trace-dispatcher.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ benchmark trace-dispatcher-bench
Cardano.Logging.Test.Oracles
Cardano.Logging.Test.Config
Cardano.Logging.Test.Tracer
Cardano.Logging.Test.Messages
Cardano.Logging.Test.Script
build-depends: base >=4.12 && <5
, aeson >= 2.1.0.0
Expand Down
5 changes: 1 addition & 4 deletions trace-resources/test/trace-resources-test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ playScript = ioProperty $ do
forwardTracer'
(Just ekgTracer')
["Test"]
(const ["ResourceStats"])
(const Info)
(const Public)
configureTracers emptyTraceConfig docResourceStats [tr]
configureTracers emptyTraceConfig [tr]
traceIt tr 10

traceIt :: Trace IO ResourceStats -> Int -> IO Bool
Expand Down

0 comments on commit 3b70450

Please sign in to comment.