Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Icelandjack committed May 20, 2024
1 parent 71d13c3 commit 9b2145a
Show file tree
Hide file tree
Showing 35 changed files with 544 additions and 365 deletions.
47 changes: 26 additions & 21 deletions cardano-tracer/bench/cardano-tracer-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,30 @@ main = do
tr <- mkTracerTracer $ SeverityF $ Just Warning

let te :: TracerConfig -> HandleRegistry -> TracerEnv
te c r =
TracerEnv
{ teConfig = c
, teConnectedNodes = connectedNodes
, teConnectedNodesNames = connectedNodesNames
, teAcceptedMetrics = acceptedMetrics
, teSavedTO = savedTO
, teBlockchainHistory = chainHistory
, teResourcesHistory = resourcesHistory
, teTxHistory = txHistory
, teCurrentLogLock = currentLogLock
, teCurrentDPLock = currentDPLock
, teEventsQueues = eventsQueues
, teDPRequestors = dpRequestors
, teProtocolsBrake = protocolsBrake
, teRTViewPageOpened = rtViewPageOpened
, teRTViewStateDir = Nothing
, teTracer = tr
, teReforwardTraceObjects = \_-> pure ()
, teRegistry = r
}
te c r = TracerEnv
{ teConfig = c
, teConnectedNodes = connectedNodes
, teConnectedNodesNames = connectedNodesNames
, teAcceptedMetrics = acceptedMetrics
, teCurrentLogLock = currentLogLock
, teCurrentDPLock = currentDPLock
, teDPRequestors = dpRequestors
, teProtocolsBrake = protocolsBrake
, teTracer = tr
, teReforwardTraceObjects = \_-> pure ()
, teRegistry = r
}

tracerEnvRTView :: TracerEnvRTView
tracerEnvRTView = TracerEnvRTView
{ teSavedTO = savedTO
, teBlockchainHistory = chainHistory
, teResourcesHistory = resourcesHistory
, teTxHistory = txHistory
, teEventsQueues = eventsQueues
, teRTViewPageOpened = rtViewPageOpened
, teRTViewStateDir = Nothing
}

removePathForcibly root

Expand Down Expand Up @@ -129,7 +132,9 @@ main = do
, ekgRequestFreq = Nothing
, hasEKG = Nothing
, hasPrometheus = Nothing
#if RTVIEW
, hasRTView = Nothing
#endif
, logging = NE.fromList [LoggingParams root FileMode format]
, rotation = Nothing
, verbosity = Nothing
Expand Down
11 changes: 7 additions & 4 deletions cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build-type: Simple
extra-doc-files: README.md
CHANGELOG.md

flag has_rtview
flag rtview
Description: Enable RTView
Manual: True
Default: True
Expand All @@ -32,9 +32,10 @@ common project-config
, ImportQualifiedPost
, InstanceSigs
, ScopedTypeVariables
, StandaloneKindSignatures
, TypeApplications

if flag(has_rtview)
if flag(rtview)
CPP-Options: -DRTVIEW=1
else
CPP-Options: -DRTVIEW=0
Expand All @@ -55,7 +56,7 @@ library

hs-source-dirs: src

if flag(has_rtview)
if flag(rtview)
exposed-modules:

Cardano.Tracer.Handlers.Metrics.Monitoring
Expand Down Expand Up @@ -117,7 +118,7 @@ library
Cardano.Tracer.Handlers.RTView.Update.Reload
Cardano.Tracer.Handlers.RTView.Update.Resources
Cardano.Tracer.Handlers.RTView.Update.Transactions
Cardano.Tracer.Handlers.RTView.Update.Utils
-- Cardano.Tracer.Handlers.RTView.Update.Utils

Cardano.Tracer.Handlers.RTView.Utils

Expand Down Expand Up @@ -147,6 +148,8 @@ library
Cardano.Tracer.Types
Cardano.Tracer.Utils

Cardano.Tracer.Handlers.RTView.Update.Utils

other-modules: Paths_cardano_tracer
autogen-modules: Paths_cardano_tracer

Expand Down
29 changes: 24 additions & 5 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ module Cardano.Tracer.Acceptors.Client
import Cardano.Logging (TraceObject)
import Cardano.Logging.Version (ForwardingVersion (..), ForwardingVersionData (..),
forwardingCodecCBORTerm, forwardingVersionCodec)
#if RTVIEW
import Cardano.Tracer.Acceptors.Utils (notifyAboutNodeDisconnected,
prepareDataPointRequestor, prepareMetricsStores, removeDisconnectedNode)
#else
import Cardano.Tracer.Acceptors.Utils (
prepareDataPointRequestor, prepareMetricsStores, removeDisconnectedNode)
#endif
import qualified Cardano.Tracer.Configuration as TC
import Cardano.Tracer.Environment
import Cardano.Tracer.Handlers.Logs.TraceObjects (deregisterNodeId, traceObjectsHandler)
Expand Down Expand Up @@ -45,13 +50,20 @@ import Trace.Forward.Run.TraceObject.Acceptor (acceptTraceObjectsInit)

runAcceptorsClient
:: TracerEnv
#if RTVIEW
-> TracerEnvRTView
#endif
-> FilePath
-> ( EKGF.AcceptorConfiguration
, TF.AcceptorConfiguration TraceObject
, DPF.AcceptorConfiguration
)
-> IO ()
runAcceptorsClient tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager $ \iocp -> do
#if RTVIEW
runAcceptorsClient tracerEnv tracerEnvRTView p (ekgConfig, tfConfig, dpfConfig) = withIOManager \iocp -> do
#else
runAcceptorsClient tracerEnv p (ekgConfig, dpfConfig) = withIOManager \iocp -> do
#endif
traceWith (teTracer tracerEnv) $ TracerSockConnecting p
doConnectToForwarder
(localSnocket iocp)
Expand All @@ -62,7 +74,9 @@ runAcceptorsClient tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager
-- there is no mechanism to disable some of them.
appInitiator
[ (runEKGAcceptorInit tracerEnv ekgConfig errorHandler, 1)
, (runTraceObjectsAcceptorInit tracerEnv tfConfig errorHandler, 2)
#if RTVIEW
, (runTraceObjectsAcceptorInit tracerEnv tracerEnvRTView tfConfig errorHandler, 2)
#endif
, (runDataPointsAcceptorInit tracerEnv dpfConfig errorHandler, 3)
]
where
Expand All @@ -78,7 +92,9 @@ runAcceptorsClient tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager
errorHandler connId = do
deregisterNodeId tracerEnv (connIdToNodeId connId)
removeDisconnectedNode tracerEnv connId
notifyAboutNodeDisconnected tracerEnv connId
#if RTVIEW
notifyAboutNodeDisconnected tracerEnvRTView connId
#endif

doConnectToForwarder
:: Snocket IO LocalSocket LocalAddress
Expand Down Expand Up @@ -122,19 +138,22 @@ runEKGAcceptorInit tracerEnv ekgConfig errorHandler =
(prepareMetricsStores tracerEnv . micConnectionId)
(errorHandler . micConnectionId)

#if RTVIEW
runTraceObjectsAcceptorInit
:: TracerEnv
-> TracerEnvRTView
-> TF.AcceptorConfiguration TraceObject
-> (ConnectionId LocalAddress -> IO ())
-> RunMiniProtocol 'InitiatorMode
(MinimalInitiatorContext LocalAddress)
responderCtx
LBS.ByteString IO () Void
runTraceObjectsAcceptorInit tracerEnv tfConfig errorHandler =
runTraceObjectsAcceptorInit tracerEnv tracerEnvRTView tfConfig errorHandler =
acceptTraceObjectsInit
tfConfig
(traceObjectsHandler tracerEnv . connIdToNodeId . micConnectionId)
(traceObjectsHandler tracerEnv tracerEnvRTView . connIdToNodeId . micConnectionId)
(errorHandler . micConnectionId)
#endif

runDataPointsAcceptorInit
:: TracerEnv
Expand Down
10 changes: 6 additions & 4 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ import qualified Trace.Forward.Protocol.TraceObject.Type as TOF
-- There are two "network modes" for acceptors:
-- 1. Server mode, when the tracer accepts connections from any number of nodes.
-- 2. Client mode, when the tracer initiates connections to specified number of nodes.
runAcceptors :: TracerEnv -> IO ()
runAcceptors tracerEnv@TracerEnv{teTracer} = do
runAcceptors :: TracerEnv -> TracerEnvRTView -> IO ()
runAcceptors tracerEnv@TracerEnv{teTracer} tracerEnvRTView = do
traceWith teTracer $ TracerStartedAcceptors network
case network of
AcceptAt (LocalSocket p) ->
-- Run one server that accepts connections from the nodes.
runInLoop
(runAcceptorsServer tracerEnv p $ acceptorsConfigs p)
(runAcceptorsServer tracerEnv tracerEnvRTView p $ acceptorsConfigs p)
verbosity p initialPauseInSec
ConnectTo localSocks ->
-- Run N clients that initiate connections to the nodes.
forConcurrently_ (NE.nub localSocks) $ \(LocalSocket p) ->
runInLoop
(runAcceptorsClient tracerEnv p $ acceptorsConfigs p)
(runAcceptorsClient tracerEnv tracerEnvRTView p $ acceptorsConfigs p)
verbosity p initialPauseInSec
where
TracerConfig{network, ekgRequestFreq, loRequestNum, verbosity} = teConfig tracerEnv
Expand All @@ -55,12 +55,14 @@ runAcceptors tracerEnv@TracerEnv{teTracer} = do
, EKGF.whatToRequest = EKGF.GetAllMetrics
, EKGF.shouldWeStop = teProtocolsBrake tracerEnv
}
#if RTVIEW
, TOF.AcceptorConfiguration
{ TOF.acceptorTracer = mkVerbosity verbosity
, TOF.forwarderEndpoint = p
, TOF.whatToRequest = TOF.NumberOfTraceObjects $ fromMaybe 100 loRequestNum
, TOF.shouldWeStop = teProtocolsBrake tracerEnv
}
#endif
, DPF.AcceptorConfiguration
{ DPF.acceptorTracer = mkVerbosity verbosity
, DPF.forwarderEndpoint = p
Expand Down
89 changes: 64 additions & 25 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ module Cardano.Tracer.Acceptors.Server
( runAcceptorsServer
) where

#if RTVIEW
import Cardano.Logging (TraceObject)
#endif
import Cardano.Logging.Version (ForwardingVersion (..), ForwardingVersionData (..),
forwardingCodecCBORTerm, forwardingVersionCodec)
#if RTVIEW
import Cardano.Tracer.Acceptors.Utils (notifyAboutNodeDisconnected,
prepareDataPointRequestor, prepareMetricsStores, removeDisconnectedNode)
#else
import Cardano.Tracer.Acceptors.Utils (prepareDataPointRequestor, prepareMetricsStores,
removeDisconnectedNode)
#endif
import qualified Cardano.Tracer.Configuration as TC
import Cardano.Tracer.Environment
#if RTVIEW
import Cardano.Tracer.Handlers.Logs.TraceObjects (deregisterNodeId, traceObjectsHandler)
#else
import Cardano.Tracer.Handlers.Logs.TraceObjects (deregisterNodeId)
#endif
import Cardano.Tracer.MetaTrace
import Cardano.Tracer.Utils (connIdToNodeId)
import Ouroboros.Network.Context (MinimalInitiatorContext (..), ResponderContext (..))
Expand Down Expand Up @@ -44,19 +55,38 @@ import qualified System.Metrics.Configuration as EKGF
import System.Metrics.Network.Acceptor (acceptEKGMetricsResp)

import qualified Trace.Forward.Configuration.DataPoint as DPF
#if RTVIEW
import qualified Trace.Forward.Configuration.TraceObject as TF
#endif
import Trace.Forward.Run.DataPoint.Acceptor (acceptDataPointsResp)
#if RTVIEW
import Trace.Forward.Run.TraceObject.Acceptor (acceptTraceObjectsResp)
#endif

runAcceptorsServer
:: TracerEnv
#if RTVIEW
-> TracerEnvRTView
#endif
-> FilePath
-> ( EKGF.AcceptorConfiguration
#if RTVIEW
, TF.AcceptorConfiguration TraceObject
#endif
, DPF.AcceptorConfiguration
)
-> IO ()
runAcceptorsServer tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager $ \iocp -> do
runAcceptorsServer tracerEnv
#if RTVIEW
tracerEnvRTView
#endif
p
( ekgConfig
#if RTVIEW
, tfConfig
#endif
, dpfConfig
) = withIOManager \iocp -> do
traceWith (teTracer tracerEnv) $ TracerSockListen p
doListenToForwarder
(localSnocket iocp)
Expand All @@ -67,7 +97,9 @@ runAcceptorsServer tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager
-- there is no mechanism to disable some of them.
appResponder
[ (runEKGAcceptor tracerEnv ekgConfig errorHandler, 1)
, (runTraceObjectsAcceptor tracerEnv tfConfig errorHandler, 2)
#if RTVIEW
, (runTraceObjectsAcceptor tracerEnv tracerEnvRTView tfConfig errorHandler, 2)
#endif
, (runDataPointsAcceptor tracerEnv dpfConfig errorHandler, 3)
]
where
Expand All @@ -83,7 +115,9 @@ runAcceptorsServer tracerEnv p (ekgConfig, tfConfig, dpfConfig) = withIOManager
errorHandler connId = do
deregisterNodeId tracerEnv (connIdToNodeId connId)
removeDisconnectedNode tracerEnv connId
notifyAboutNodeDisconnected tracerEnv connId
#if RTVIEW
notifyAboutNodeDisconnected tracerEnvRTView connId
#endif

doListenToForwarder
:: Snocket IO LocalSocket LocalAddress
Expand All @@ -97,26 +131,26 @@ doListenToForwarder
-> IO ()
doListenToForwarder snocket address netMagic timeLimits app = do
networkState <- newNetworkMutableState
race_ (cleanNetworkMutableState networkState)
$ withServerNode
snocket
makeLocalBearer
mempty -- LocalSocket does not need to be configured
nullNetworkServerTracers
networkState
(AcceptedConnectionsLimit maxBound maxBound 0)
address
(codecHandshake forwardingVersionCodec)
timeLimits
(cborTermVersionDataCodec forwardingCodecCBORTerm)
(HandshakeCallbacks acceptableVersion queryVersion)
(simpleSingletonVersions
ForwardingV_1
(ForwardingVersionData $ NetworkMagic netMagic)
(SomeResponderApplication app)
)
nullErrorPolicies
$ \_ serverAsync -> wait serverAsync -- Block until async exception.
race_ (cleanNetworkMutableState networkState) do
withServerNode
snocket
makeLocalBearer
mempty -- LocalSocket does not need to be configured
nullNetworkServerTracers
networkState
(AcceptedConnectionsLimit maxBound maxBound 0)
address
(codecHandshake forwardingVersionCodec)
timeLimits
(cborTermVersionDataCodec forwardingCodecCBORTerm)
(HandshakeCallbacks acceptableVersion queryVersion)
(simpleSingletonVersions
ForwardingV_1
(ForwardingVersionData $ NetworkMagic netMagic)
(SomeResponderApplication app)
)
nullErrorPolicies
$ \_ serverAsync -> wait serverAsync -- Block until async exception.

runEKGAcceptor
:: TracerEnv
Expand All @@ -129,19 +163,24 @@ runEKGAcceptor tracerEnv ekgConfig errorHandler =
(prepareMetricsStores tracerEnv . rcConnectionId)
(errorHandler . rcConnectionId)

#if RTVIEW
runTraceObjectsAcceptor
:: TracerEnv
-> TracerEnvRTView
-> TF.AcceptorConfiguration TraceObject
-> (ConnectionId LocalAddress -> IO ())
-> RunMiniProtocol 'ResponderMode
initiatorCtx
(ResponderContext LocalAddress)
LBS.ByteString IO Void ()
runTraceObjectsAcceptor tracerEnv tfConfig errorHandler =
runTraceObjectsAcceptor tracerEnv
tracerEnvRTView
tfConfig errorHandler =
acceptTraceObjectsResp
tfConfig
(traceObjectsHandler tracerEnv . connIdToNodeId . rcConnectionId)
(traceObjectsHandler tracerEnv tracerEnvRTView . connIdToNodeId . rcConnectionId)
(errorHandler . rcConnectionId)
#endif

runDataPointsAcceptor
:: TracerEnv
Expand Down
Loading

0 comments on commit 9b2145a

Please sign in to comment.