Skip to content

Commit b6553af

Browse files
committed
cardano-tracer: add tracing & fix the hang in getXdgDirectory
1 parent af4bc8e commit b6553af

File tree

21 files changed

+320
-95
lines changed

21 files changed

+320
-95
lines changed

Diff for: cardano-tracer/bench/cardano-tracer-bench.hs

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Cardano.Tracer.Utils
1717
import Cardano.Tracer.Configuration
1818
import Cardano.Tracer.Environment
1919
import Cardano.Tracer.Handlers.Logs.TraceObjects
20+
import Cardano.Tracer.MetaTrace
2021
import Cardano.Tracer.Types
2122

2223
main :: IO ()
@@ -48,6 +49,8 @@ main = do
4849

4950
rtViewPageOpened <- newTVarIO False
5051

52+
tr <- mkTracerTracer $ SeverityF $ Just Warning
53+
5154
let te1 =
5255
TracerEnv
5356
{ teConfig = c1
@@ -65,6 +68,7 @@ main = do
6568
, teProtocolsBrake = protocolsBrake
6669
, teRTViewPageOpened = rtViewPageOpened
6770
, teRTViewStateDir = Nothing
71+
, teTracer = tr
6872
}
6973
te2 =
7074
TracerEnv
@@ -83,6 +87,7 @@ main = do
8387
, teProtocolsBrake = protocolsBrake
8488
, teRTViewPageOpened = rtViewPageOpened
8589
, teRTViewStateDir = Nothing
90+
, teTracer = tr
8691
}
8792

8893
removePathForcibly root

Diff for: cardano-tracer/cardano-tracer.cabal

+29-6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ library
111111
Cardano.Tracer.CLI
112112
Cardano.Tracer.Configuration
113113
Cardano.Tracer.Environment
114+
Cardano.Tracer.MetaTrace
114115
Cardano.Tracer.Run
115116
Cardano.Tracer.Types
116117
Cardano.Tracer.Utils
@@ -186,23 +187,30 @@ library demo-forwarder-lib
186187

187188
hs-source-dirs: test
188189

190+
other-modules: Cardano.Tracer.Test.TestSetup
191+
Cardano.Tracer.Test.Utils
192+
189193
exposed-modules: Cardano.Tracer.Test.Forwarder
190194

191195
build-depends: aeson
192196
, async
193197
, bytestring
194-
, cborg
195198
, cardano-tracer
199+
, cborg
196200
, contra-tracer
201+
, directory
197202
, ekg-core
198203
, ekg-forward
204+
, extra
205+
, filepath
206+
, generic-data
207+
, optparse-applicative-fork
199208
, ouroboros-network
200209
, ouroboros-network-framework
210+
, tasty-quickcheck
201211
, time
202212
, trace-dispatcher
203213
, trace-forward
204-
if os(windows)
205-
buildable: False
206214

207215
executable demo-forwarder
208216
import: base, project-config
@@ -216,24 +224,32 @@ executable demo-forwarder
216224
ghc-options: -threaded
217225
-rtsopts
218226
-with-rtsopts=-T
227+
if os(windows)
228+
buildable: False
219229

220230
library demo-acceptor-lib
221231
import: base, project-config
222232

223233
hs-source-dirs: test
224234

235+
other-modules: Cardano.Tracer.Test.TestSetup
236+
Cardano.Tracer.Test.Utils
237+
225238
exposed-modules: Cardano.Tracer.Test.Acceptor
226239

227240
build-depends: async-extras
228241
, bytestring
229242
, cardano-tracer
230243
, containers
231244
, extra
245+
, filepath
246+
, generic-data
247+
, optparse-applicative-fork
248+
, ouroboros-network
232249
, stm
233250
, text
251+
, tasty-quickcheck
234252
, trace-forward
235-
if os(windows)
236-
buildable: False
237253

238254
executable demo-acceptor
239255
import: base, project-config
@@ -247,6 +263,8 @@ executable demo-acceptor
247263
ghc-options: -threaded
248264
-rtsopts
249265
-with-rtsopts=-T
266+
if os(windows)
267+
buildable: False
250268

251269
test-suite cardano-tracer-test
252270
import: base, project-config
@@ -262,15 +280,20 @@ test-suite cardano-tracer-test
262280
Cardano.Tracer.Test.Logs.Tests
263281
Cardano.Tracer.Test.Restart.Tests
264282
Cardano.Tracer.Test.TestSetup
265-
Cardano.Tracer.Test.Queue.Tests
266283
Cardano.Tracer.Test.Utils
284+
Cardano.Tracer.Test.Queue.Tests
267285
Cardano.Tracer.Test.ForwardingStressTest.Script
268286
Cardano.Tracer.Test.ForwardingStressTest.Config
269287
Cardano.Tracer.Test.ForwardingStressTest.Messages
270288
Cardano.Tracer.Test.ForwardingStressTest.Types
271289

272290
build-tool-depends: cardano-tracer:cardano-tracer
273291

292+
-- Sadly, this no longer works on Windows, because of the last external-tracer test:
293+
-- *** Failed! Exception: 'cardano-tracer: spawnProcess: failed (Success)' (after 1 test):
294+
if os(windows)
295+
buildable: False
296+
274297
build-depends: aeson
275298
, async
276299
, bytestring

Diff for: cardano-tracer/src/Cardano/Tracer/Acceptors/Client.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import Cardano.Tracer.Acceptors.Utils (notifyAboutNodeDisconnected,
4040
import qualified Cardano.Tracer.Configuration as TC
4141
import Cardano.Tracer.Environment
4242
import Cardano.Tracer.Handlers.Logs.TraceObjects (traceObjectsHandler)
43+
import Cardano.Tracer.MetaTrace
4344
import Cardano.Tracer.Utils (connIdToNodeId)
4445

4546
runAcceptorsClient
@@ -50,7 +51,8 @@ runAcceptorsClient
5051
, DPF.AcceptorConfiguration
5152
)
5253
-> IO ()
53-
runAcceptorsClient tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager $ \iocp ->
54+
runAcceptorsClient tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager $ \iocp -> do
55+
traceWith (teTracer tracerEnv) $ TracerSockConnecting p
5456
doConnectToForwarder
5557
(localSnocket iocp)
5658
(localAddressFromPath p)

Diff for: cardano-tracer/src/Cardano/Tracer/Acceptors/Server.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import Cardano.Tracer.Acceptors.Utils (notifyAboutNodeDisconnected,
4343
import qualified Cardano.Tracer.Configuration as TC
4444
import Cardano.Tracer.Environment
4545
import Cardano.Tracer.Handlers.Logs.TraceObjects (traceObjectsHandler)
46+
import Cardano.Tracer.MetaTrace
4647
import Cardano.Tracer.Utils (connIdToNodeId)
4748

4849
runAcceptorsServer
@@ -53,7 +54,8 @@ runAcceptorsServer
5354
, DPF.AcceptorConfiguration
5455
)
5556
-> IO ()
56-
runAcceptorsServer tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager $ \iocp ->
57+
runAcceptorsServer tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager $ \iocp -> do
58+
traceWith (teTracer tracerEnv) $ TracerSockListen p
5759
doListenToForwarder
5860
(localSnocket iocp)
5961
(localAddressFromPath p)

Diff for: cardano-tracer/src/Cardano/Tracer/CLI.hs

+11
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ module Cardano.Tracer.CLI
55

66
import Options.Applicative
77

8+
import Cardano.Logging
9+
10+
811
-- | CLI parameters required for the tracer.
912
data TracerParams = TracerParams
1013
{ tracerConfig :: !FilePath
1114
, stateDir :: !(Maybe FilePath)
15+
, logSeverity :: !(Maybe SeverityS)
1216
}
1317

1418
-- | Parse CLI parameters for the tracer.
@@ -30,3 +34,10 @@ parseTracerParams = TracerParams
3034
<> completer (bashCompleter "file")
3135
)
3236
)
37+
<*> optional
38+
( option auto
39+
( long "min-log-severity"
40+
<> metavar "SEVERITY"
41+
<> help "Drop messages less severe than this. One of: Debug. Info. Notice. Warning. Error. Critical. Alert. Emergency."
42+
)
43+
)

Diff for: cardano-tracer/src/Cardano/Tracer/Configuration.hs

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Cardano.Tracer.Configuration
1717
, readTracerConfig
1818
) where
1919

20-
import Data.Aeson (FromJSON)
20+
import Data.Aeson (FromJSON, ToJSON)
2121
import Data.Fixed (Pico)
2222
import Data.List (intercalate)
2323
import Data.List.NonEmpty (NonEmpty)
@@ -31,53 +31,53 @@ import System.Exit (die)
3131

3232
-- | Only local socket is supported, to avoid unauthorized connections.
3333
newtype Address = LocalSocket FilePath
34-
deriving (Eq, Generic, FromJSON, Show)
34+
deriving (Eq, Generic, FromJSON, ToJSON, Show)
3535

3636
-- | Endpoint for internal services.
3737
data Endpoint = Endpoint
3838
{ epHost :: !String
3939
, epPort :: !Word16
40-
} deriving (Eq, Generic, FromJSON, Show)
40+
} deriving (Eq, Generic, FromJSON, ToJSON, Show)
4141

4242
-- | Parameters of rotation mechanism for logs.
4343
data RotationParams = RotationParams
4444
{ rpFrequencySecs :: !Word32 -- ^ Rotation period, in seconds.
4545
, rpLogLimitBytes :: !Word64 -- ^ Max size of log file in bytes.
4646
, rpMaxAgeHours :: !Word16 -- ^ Max age of log file in hours.
4747
, rpKeepFilesNum :: !Word32 -- ^ Number of log files to keep in any case.
48-
} deriving (Eq, Generic, FromJSON, Show)
48+
} deriving (Eq, Generic, FromJSON, ToJSON, Show)
4949

5050
-- | Logging mode.
5151
data LogMode
5252
= FileMode -- ^ Store items in log file.
5353
| JournalMode -- ^ Store items in Linux journal service.
54-
deriving (Eq, Generic, FromJSON, Show)
54+
deriving (Eq, Generic, FromJSON, ToJSON, Show)
5555

5656
-- | Format of log files.
5757
data LogFormat
5858
= ForHuman -- ^ For human (text)
5959
| ForMachine -- ^ For machine (JSON)
60-
deriving (Eq, Generic, FromJSON, Show)
60+
deriving (Eq, Generic, FromJSON, ToJSON, Show)
6161

6262
-- | Logging parameters.
6363
data LoggingParams = LoggingParams
6464
{ logRoot :: !FilePath -- ^ Root directory where all subdirs with logs are created.
6565
, logMode :: !LogMode -- ^ Log mode.
6666
, logFormat :: !LogFormat -- ^ Log format.
67-
} deriving (Eq, Generic, FromJSON, Show)
67+
} deriving (Eq, Generic, FromJSON, ToJSON, Show)
6868

6969
-- | Connection mode.
7070
data Network
7171
= AcceptAt !Address -- ^ Server mode: accepts connections.
7272
| ConnectTo !(NonEmpty Address) -- ^ Client mode: initiates connections.
73-
deriving (Eq, Generic, FromJSON, Show)
73+
deriving (Eq, Generic, FromJSON, ToJSON, Show)
7474

7575
-- | Tracer's verbosity.
7676
data Verbosity
7777
= Minimum -- ^ Display minimum of messages.
7878
| ErrorsOnly -- ^ Display errors only.
7979
| Maximum -- ^ Display all the messages (protocols tracing, errors).
80-
deriving (Eq, Generic, FromJSON, Show)
80+
deriving (Eq, Generic, FromJSON, ToJSON, Show)
8181

8282
-- | Tracer configuration.
8383
data TracerConfig = TracerConfig
@@ -91,7 +91,7 @@ data TracerConfig = TracerConfig
9191
, logging :: !(NonEmpty LoggingParams) -- ^ Logging parameters.
9292
, rotation :: !(Maybe RotationParams) -- ^ Rotation parameters.
9393
, verbosity :: !(Maybe Verbosity) -- ^ Verbosity of the tracer itself.
94-
} deriving (Eq, Generic, FromJSON, Show)
94+
} deriving (Eq, Generic, FromJSON, ToJSON, Show)
9595

9696
-- | Read the tracer's configuration file.
9797
readTracerConfig :: FilePath -> IO TracerConfig

Diff for: cardano-tracer/src/Cardano/Tracer/Environment.hs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Cardano.Tracer.Handlers.RTView.Notifications.Types
99
import Cardano.Tracer.Handlers.RTView.State.Historical
1010
import Cardano.Tracer.Handlers.RTView.State.TraceObjects
1111
import Cardano.Tracer.Handlers.RTView.UI.Types
12+
import Cardano.Tracer.MetaTrace
1213
import Cardano.Tracer.Types
1314

1415
-- | Environment for all functions.
@@ -28,4 +29,5 @@ data TracerEnv = TracerEnv
2829
, teProtocolsBrake :: !ProtocolsBrake
2930
, teRTViewPageOpened :: !WebPageStatus
3031
, teRTViewStateDir :: !(Maybe FilePath)
32+
, teTracer :: !(Trace IO TracerTrace)
3133
}

Diff for: cardano-tracer/src/Cardano/Tracer/Handlers/RTView/Notifications/Utils.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ initEventsQueues
3232
initEventsQueues rtvSD nodesNames dpReqs curDPLock = do
3333
emailSettings <- readSavedEmailSettings rtvSD
3434

35-
newTVarIO =<< M.fromList <$>
35+
newTVarIO . M.fromList =<<
3636
if incompleteEmailSettings emailSettings
3737
then pure []
3838
else do

0 commit comments

Comments
 (0)