Skip to content
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
8 changes: 4 additions & 4 deletions bench/tx-generator/src/Cardano/Benchmarking/Tracer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Cardano.Benchmarking.Version as Version
import Cardano.Logging
import qualified Cardano.Logging.Types as Net
import Cardano.Node.Startup
import Cardano.Node.Tracing.NodeInfo () -- MetaTrace NodeInfo
import Cardano.Node.Tracing.NodeInfo ()
import Ouroboros.Network.IOManager (IOManager)

import Control.Monad (forM, guard)
Expand All @@ -49,7 +49,7 @@ import qualified Data.Text as Text
import Data.Time.Clock
import GHC.Generics

import Trace.Forward.Utils.DataPoint
import Trace.Forward.Forwarding (initForwardingDelayed)
import Trace.Forward.Utils.TraceObject

pattern TracerNameBench :: Text
Expand Down Expand Up @@ -121,7 +121,7 @@ initTxGenTracers mbForwarding = do
prepareForwardingTracer = forM mbForwarding $
\(iomgr, networkId, tracerSocket) -> do
let forwardingConf = fromMaybe defaultForwarder (tcForwarder initialTraceConfig)
(forwardSink :: ForwardSink TraceObject, dpStore, kickoffForwarder) <-
(forwardSink, dpStore, kickoffForwarder) <-
initForwardingDelayed iomgr forwardingConf (toNetworkMagic networkId) Nothing $ Just (Net.LocalPipe tracerSocket, Initiator)

-- we need to provide NodeInfo DataPoint, to forward generator's name
Expand All @@ -134,7 +134,7 @@ initTxGenTracers mbForwarding = do
traceWith nodeInfoTracer genInfo

kickoffForwarder
pure $ forwardTracer forwardSink
pure $ forwardTracer (writeToSink forwardSink)

prepareGenInfo :: IO NodeInfo
prepareGenInfo =
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ library
, sop-extras
, text >= 2.0
, time
, trace-dispatcher ^>= 2.9.2
, trace-forward ^>= 2.2.11
, trace-dispatcher ^>= 2.10.0
, trace-forward ^>= 2.3.0
, trace-resources ^>= 0.2.3
, tracer-transformers
, transformers
Expand Down
7 changes: 5 additions & 2 deletions cardano-node/src/Cardano/Node/Tracing/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module Cardano.Node.Tracing.API
) where

import Cardano.Logging hiding (traceWith)
import qualified Cardano.Logging.Types as Net
import Cardano.Logging.Prometheus.TCPServer (runPrometheusSimple)
import qualified Cardano.Logging.Types as Net
import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable)
import Cardano.Node.Configuration.NodeAddress (PortNumber)
import Cardano.Node.Configuration.POM (NodeConfiguration (..))
Expand Down Expand Up @@ -52,6 +52,9 @@ import Network.Mux.Trace (TraceLabelPeer (..))
import Network.Socket (HostName)
import System.Metrics as EKG

import Trace.Forward.Forwarding (initForwardingDelayed)
import Trace.Forward.Utils.TraceObject (writeToSink)


initTraceDispatcher ::
forall blk p2p.
Expand Down Expand Up @@ -137,7 +140,7 @@ initTraceDispatcher nc p networkMagic nodeKernel p2pMode noBlockForging = do
forwardingConf :: TraceOptionForwarder
forwardingConf = fromMaybe defaultForwarder (tcForwarder trConfig)
initForwardingDelayed iomgr forwardingConf networkMagic (Just ekgStore) tracerSocketMode
pure (forwardTracer forwardSink, dataPointTracer dpStore, kickoffForwarder)
pure (forwardTracer (writeToSink forwardSink), dataPointTracer dpStore, kickoffForwarder)
else
-- Since 'Forwarder' backend isn't enabled, there is no forwarding.
-- So we use nullTracers to ignore 'TraceObject's and 'DataPoint's.
Expand Down
2 changes: 0 additions & 2 deletions cardano-node/src/Cardano/Node/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ import Data.Proxy (Proxy (..))
import Network.Mux.Trace (TraceLabelPeer (..))
import Network.Socket (SockAddr)

import Trace.Forward.Utils.DataPoint (DataPoint)

-- | Construct tracers for all system components.
--
mkDispatchTracers
Expand Down
3 changes: 2 additions & 1 deletion cardano-tracer/bench/cardano-tracer-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Cardano.Tracer.MetaTrace
import Cardano.Tracer.Types
import Cardano.Tracer.Utils


import Control.Concurrent.Extra (newLock)
#if RTVIEW
import Control.Concurrent.STM.TVar (newTVarIO)
Expand Down Expand Up @@ -55,7 +56,7 @@ main = do
currentLogLock <- newLock
currentDPLock <- newLock
#if RTVIEW
eventsQueues <- initEventsQueues Nothing connectedNodesNames dpRequestors currentDPLock
eventsQueues <- initEventsQueues mempty Nothing connectedNodesNames dpRequestors currentDPLock

rtViewPageOpened <- newTVarIO False
#endif
Expand Down
6 changes: 3 additions & 3 deletions cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 3.0

name: cardano-tracer
version: 0.3.3
version: 0.3.4
synopsis: A service for logging and monitoring over Cardano nodes
description: A service for logging and monitoring over Cardano nodes.
category: Cardano,
Expand Down Expand Up @@ -197,8 +197,8 @@ library
, string-qq
, text
, time
, trace-dispatcher ^>= 2.9.2
, trace-forward ^>= 2.2.11
, trace-dispatcher ^>= 2.10.0
, trace-forward ^>= 2.3.0
, trace-resources ^>= 0.2.3
, wai ^>= 3.2
, warp ^>= 3.4
Expand Down
34 changes: 30 additions & 4 deletions cardano-tracer/docs/cardano-tracer.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
- [Build and run](#build-and-run)
- [Configuration](#configuration)
- [Distributed Scenario](#distributed-scenario)
- [Important](#important)
- [Local Scenario](#local-scenario)
- [Forwarding over TCP](#forwarding-over-tcp)
- [Network Magic](#network-magic)
- [Requests](#requests)
- [Logging](#logging)
Expand All @@ -27,7 +27,7 @@

## Motivation

Previously, the node handled all the logging by itself. Moreover, it provided monitoring tools as well: two web-servers, for Prometheus and for EKG monitoring page. `cardano-tracer` is a result of _moving_ all the logging/monitoring-related stuff from the node to a separate service. As a result, the node became smaller, faster, and simpler.
Previously, the node handled all the logging by itself. Moreover, it provided monitoring tools as well: two web-servers, for Prometheus and for EKG monitoring page. `cardano-tracer` is a result of _moving_ all logging and monitoring related functionality from the node to a separate service. As a result, the node becomes smaller, more efficient, and simpler.

## Overview

Expand Down Expand Up @@ -82,8 +82,6 @@ Distributed scenario is for real-life case: for example, you have `N` nodes work

Local scenario is for testing case: for example, you want to try your new infrastructure from scratch, so you run `N` nodes and one `cardano-tracer` process on your machine.

**IMPORTANT NOTICE**: Please note that `cardano-tracer` **does not** support connection via IP-address and port, to avoid unauthorized connections. The **only** way to establish connection with the node is the local socket (Unix sockets or Windows named pipes).

## Distributed Scenario

This is an example with 3 nodes and one `cardano-tracer`:
Expand Down Expand Up @@ -251,8 +249,36 @@ There is another way to connect `cardano-tracer` to your nodes: the `cardano-tra

As you see, the tag in `network` field is `ConnectTo` now, which means that `cardano-tracer` works as a client: it _establishes_ network connections with your local nodes via the local sockets `/tmp/cardano-node-*.sock`. In this case each socket is used by a particular node.

`AcceptTo` and `ConnectTo` are mirrored by the reciprocal CLI option on the node `--tracer-socket-path-connect` / `--tracer-socket-path-accept`. If you choose one on the node, you choose the opposite on the tracer. This only makes a difference to which entity initiates the handshake; after the handshake the configuration is identical

Please use `ConnectTo`-based scenario only if you really need it. Otherwise, it is **highly recommended** to use `AcceptAt`-based scenario. The reason is easier maintainance. Suppose you have 3 working nodes, and they are connected to the same `cardano-tracer`. And then you want to connect 4-th node to it. If `cardano-tracer` is configured using `AcceptAt`, you shouldn't change its configuration - you just connect your 4-th node to it. But if `cardano-tracer` is configured using `ConnectTo`, you should add path to 4-th socket in its configuration file and then restart `cardano-tracer` process.

## Forwarding over TCP

In addition to forwarding over sockets, forwarding over TCP/IP is supported. In both cases, the 'forwarding protocol' is identical. For TCP forwarding, adjust the following (only showing the `AcceptAt` scenario here):

Change node CLI option:
```bash
--tracer-socket-network-connect 10.0.0.2:34567
```

Adjust value for `network` in `cardano-tracer`'s configuration:
```yaml
network:
tag: AcceptAt
contents: "0.0.0.0:34567"
```

In this example, `cardano-tracer` listens on port 34567. Nodes can connect via IPv4 for forwarding, with `10.0.0.2` being `cardano-tracer`'s IP in that example.

### Important

On same-host setups sockets are always preferrable due to **less overhead and better performance**. On multi-host setups, socket connection via SSH tunnels is always preferrable due to **increased security**.

Use TCP forwarding **if and only if** you control each and every aspect of the environment, such as port mapping or firewalls, or virtual network setup - the 'forwarding protocol' does not implement encrypting traffic nor authentication methods.



## Network Magic

The field `networkMagic` specifies the value of network magic. It is an integer constant from the genesis file, the node uses this value for the network handshake with peers. Since `cardano-tracer` should be connected to the node, it needs that network magic.
Expand Down
29 changes: 12 additions & 17 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,39 @@ module Cardano.Tracer.Acceptors.Client

import Cardano.Logging (TraceObject)
import qualified Cardano.Logging.Types as Net
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 Cardano.Tracer.Acceptors.Utils
import qualified Cardano.Tracer.Configuration as TC
import Cardano.Tracer.Environment
import Cardano.Tracer.Handlers.Logs.TraceObjects (deregisterNodeId, traceObjectsHandler)
import Cardano.Tracer.MetaTrace
import Cardano.Tracer.Utils (connIdToNodeId)
import qualified Network.Mux as Mux
import Ouroboros.Network.Context (MinimalInitiatorContext (..), ResponderContext (..))
import Ouroboros.Network.Driver.Limits (ProtocolTimeLimits)
import Ouroboros.Network.IOManager (withIOManager)
import Ouroboros.Network.Magic (NetworkMagic (..))
import Ouroboros.Network.Mux (MiniProtocol (..), MiniProtocolLimits (..),
MiniProtocolNum (..), OuroborosApplication (..),
RunMiniProtocol (..), miniProtocolLimits, miniProtocolNum, miniProtocolRun,
OuroborosApplicationWithMinimalCtx)
OuroborosApplicationWithMinimalCtx, RunMiniProtocol (..), miniProtocolLimits,
miniProtocolNum, miniProtocolRun)
import Ouroboros.Network.Protocol.Handshake.Codec (cborTermVersionDataCodec,
codecHandshake, timeLimitsHandshake, noTimeLimitsHandshake)
codecHandshake, noTimeLimitsHandshake, timeLimitsHandshake)
import Ouroboros.Network.Protocol.Handshake.Type (Handshake)
import Ouroboros.Network.Protocol.Handshake.Version (acceptableVersion, queryVersion,
simpleSingletonVersions)
import Ouroboros.Network.Snocket (LocalAddress, LocalSocket, Snocket,
localAddressFromPath, localSnocket, socketSnocket, makeSocketBearer, makeLocalBearer)
import Ouroboros.Network.Socket (ConnectionId (..), ConnectToArgs (..),
localAddressFromPath, localSnocket, makeLocalBearer, makeSocketBearer,
socketSnocket)
import Ouroboros.Network.Socket (ConnectToArgs (..), ConnectionId (..),
HandshakeCallbacks (..), connectToNode, nullNetworkConnectTracers)

import Codec.CBOR.Term (Term)
import Control.Exception (throwIO)
import qualified Data.ByteString.Lazy as LBS
import Data.List.NonEmpty (NonEmpty((:|)))
import Data.Void (Void, absurd)
import Data.List.NonEmpty (NonEmpty ((:|)))
import qualified Data.Text as Text
import Data.Void (Void, absurd)
import Data.Word (Word32)
import qualified Network.Mux as Mux
import qualified Network.Socket as Socket
import qualified System.Metrics.Configuration as EKGF
import System.Metrics.Network.Acceptor (acceptEKGMetricsInit)
Expand All @@ -54,6 +47,8 @@ import qualified Trace.Forward.Configuration.DataPoint as DPF
import qualified Trace.Forward.Configuration.TraceObject as TF
import Trace.Forward.Run.DataPoint.Acceptor (acceptDataPointsInit)
import Trace.Forward.Run.TraceObject.Acceptor (acceptTraceObjectsInit)
import Trace.Forward.Utils.Version (ForwardingVersion (..), ForwardingVersionData (..),
forwardingCodecCBORTerm, forwardingVersionCodec)

runAcceptorsClient
:: TracerEnv
Expand Down
23 changes: 9 additions & 14 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,41 @@ module Cardano.Tracer.Acceptors.Server

import Cardano.Logging (TraceObject)
import qualified Cardano.Logging.Types as Net
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 Cardano.Tracer.Acceptors.Utils
import qualified Cardano.Tracer.Configuration as TC
import Cardano.Tracer.Environment
import Cardano.Tracer.Handlers.Logs.TraceObjects (deregisterNodeId, traceObjectsHandler)
import Cardano.Tracer.MetaTrace
import Cardano.Tracer.Utils (connIdToNodeId)
import qualified Network.Mux as Mux
import Ouroboros.Network.Context (MinimalInitiatorContext (..), ResponderContext (..))
import Ouroboros.Network.Driver.Limits (ProtocolTimeLimits)
import Ouroboros.Network.ErrorPolicy (nullErrorPolicies)
import Ouroboros.Network.IOManager (withIOManager)
import Ouroboros.Network.Magic (NetworkMagic (..))
import Ouroboros.Network.Mux (MiniProtocol (..), MiniProtocolLimits (..),
MiniProtocolNum (..), OuroborosApplication (..),
RunMiniProtocol (..), OuroborosApplicationWithMinimalCtx,
miniProtocolLimits, miniProtocolNum, miniProtocolRun)
OuroborosApplicationWithMinimalCtx, RunMiniProtocol (..), miniProtocolLimits,
miniProtocolNum, miniProtocolRun)
import Ouroboros.Network.Protocol.Handshake.Codec (cborTermVersionDataCodec,
codecHandshake, noTimeLimitsHandshake, timeLimitsHandshake)
import Ouroboros.Network.Protocol.Handshake.Type (Handshake)
import Ouroboros.Network.Protocol.Handshake.Version (acceptableVersion, queryVersion,
simpleSingletonVersions)
import Ouroboros.Network.Snocket (LocalAddress, LocalSocket, Snocket,
localAddressFromPath, localSnocket, socketSnocket, makeSocketBearer, makeLocalBearer)
localAddressFromPath, localSnocket, makeLocalBearer, makeSocketBearer,
socketSnocket)
import Ouroboros.Network.Socket (AcceptedConnectionsLimit (..), ConnectionId (..),
HandshakeCallbacks (..), SomeResponderApplication (..), cleanNetworkMutableState,
newNetworkMutableState, nullNetworkServerTracers, withServerNode)

import Codec.CBOR.Term (Term)
import Control.Concurrent.Async (race_, wait)
import qualified Data.ByteString.Lazy as LBS
import Data.List.NonEmpty (NonEmpty((:|)))
import Data.List.NonEmpty (NonEmpty ((:|)))
import qualified Data.Text as Text
import Data.Void (Void)
import Data.Word (Word32)
import qualified Network.Mux as Mux
import qualified Network.Socket as Socket
import qualified System.Metrics.Configuration as EKGF
import System.Metrics.Network.Acceptor (acceptEKGMetricsResp)
Expand All @@ -56,6 +49,8 @@ import qualified Trace.Forward.Configuration.DataPoint as DPF
import qualified Trace.Forward.Configuration.TraceObject as TF
import Trace.Forward.Run.DataPoint.Acceptor (acceptDataPointsResp)
import Trace.Forward.Run.TraceObject.Acceptor (acceptTraceObjectsResp)
import Trace.Forward.Utils.Version (ForwardingVersion (..), ForwardingVersionData (..),
forwardingCodecCBORTerm, forwardingVersionCodec)


runAcceptorsServer
Expand Down
6 changes: 3 additions & 3 deletions cardano-tracer/src/Cardano/Tracer/Handlers/ReForwarder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Cardano.Tracer.Handlers.ReForwarder
( initReForwarder
) where

import Cardano.Logging.Forwarding
import Cardano.Logging.Trace
import Cardano.Logging.Tracer.DataPoint
import qualified Cardano.Logging.Types as Log
Expand All @@ -29,8 +28,9 @@ import Control.Monad (when)
import Data.List (isPrefixOf)
import qualified Data.Text as Text

import Trace.Forward.Utils.DataPoint
import Trace.Forward.Utils.TraceObject (ForwardSink, writeToSink)
import Trace.Forward.Forwarding
import Trace.Forward.Utils.ForwardSink (ForwardSink)
import Trace.Forward.Utils.TraceObject (writeToSink)

-- | Initialize the reforwarding service if configured to be active.
-- Returns
Expand Down
Loading
Loading