diff --git a/cardano-tracer/src/Cardano/Tracer/Handlers/Logs/File.hs b/cardano-tracer/src/Cardano/Tracer/Handlers/Logs/File.hs index 6256757f856..6796128725c 100644 --- a/cardano-tracer/src/Cardano/Tracer/Handlers/Logs/File.hs +++ b/cardano-tracer/src/Cardano/Tracer/Handlers/Logs/File.hs @@ -94,9 +94,7 @@ prepareLogsStructure nodeId nodeName rootDir format = do return pathToCurrentLog where subDirForLogs = rootDir nodeFullId - nodeFullId = if T.null nodeName - then show nodeId - else T.unpack nodeName <> "-" <> show nodeId + nodeFullId = T.unpack $ printNodeFullId nodeName nodeId -- This is a symlink to the current log file, please see rotation parameters. pathToCurrentLog = subDirForLogs symLinkName format diff --git a/cardano-tracer/src/Cardano/Tracer/Handlers/Metrics/Prometheus.hs b/cardano-tracer/src/Cardano/Tracer/Handlers/Metrics/Prometheus.hs index cb5bab3509f..c51407ac1ef 100644 --- a/cardano-tracer/src/Cardano/Tracer/Handlers/Metrics/Prometheus.hs +++ b/cardano-tracer/src/Cardano/Tracer/Handlers/Metrics/Prometheus.hs @@ -65,7 +65,7 @@ runPrometheusServer (Endpoint host port) acceptedMetrics acceptedNodeInfo = fore mkListOfHrefs :: [(NodeId, NodeInfo)] -> IO Html mkListOfHrefs ni = do nodeHrefs <- forM ni $ \(nodeId, NodeInfo{niName}) -> do - let nodeFullId = T.unpack niName <> "-" <> show nodeId + let nodeFullId = T.unpack $ printNodeFullId niName nodeId return $ a ! href (mkURL nodeFullId) $ toHtml nodeFullId return $ mkPage nodeHrefs @@ -106,7 +106,7 @@ getMetricsFromNode (nodeFullId':_) acceptedMetrics = do let (ekgStore, _) = metrics HM.! nodeId sampleAll ekgStore >>= return . renderListOfMetrics . getListOfMetrics where - -- For example, "127.0.0.1-17890" is suffix of "node-1-127.0.0.1-17890" + -- For example, "run-user-1000-core.sock" is suffix of "core-1--run-user-1000-core.sock" nodeIdWeNeed nodeId = T.pack (show nodeId) `T.isSuffixOf` nodeFullId nodeFullId = decodeUtf8 nodeFullId' diff --git a/cardano-tracer/src/Cardano/Tracer/Types.hs b/cardano-tracer/src/Cardano/Tracer/Types.hs index b77695a8b1f..be27a8e9815 100644 --- a/cardano-tracer/src/Cardano/Tracer/Types.hs +++ b/cardano-tracer/src/Cardano/Tracer/Types.hs @@ -12,6 +12,7 @@ module Cardano.Tracer.Types , initAcceptedMetrics , initAcceptedNodeInfo , prepareAcceptedMetrics + , printNodeFullId ) where import Control.Concurrent.STM (atomically) @@ -20,7 +21,8 @@ import Control.Monad (unless) import Data.Hashable (Hashable) import Data.HashMap.Strict (HashMap) import qualified Data.HashMap.Strict as HM -import Data.Text (Text, replace, pack) +import Data.Text (Text) +import qualified Data.Text as T import GHC.Generics (Generic) import qualified System.Metrics as EKG @@ -40,12 +42,17 @@ connIdToNodeId ConnectionId{remoteAddress} = NodeId preparedAddress -- We have to remove "wrong" symbols from 'NodeId', -- to make it appropriate for the name of the subdirectory. preparedAddress = - replace " " "-" - . replace "\"" "" - . replace "/" "-" - . pack + T.replace "LocalAddress" "" -- There are only local addresses by design. + . T.replace " " "-" + . T.replace "\"" "" + . T.replace "/" "-" + . T.pack $ show remoteAddress +printNodeFullId :: Text -> NodeId -> Text +printNodeFullId "" (NodeId p) = T.drop 2 p -- In this case '--' in the beginning is useless. +printNodeFullId nodeName (NodeId p) = nodeName <> p + -- | We have to create EKG.Store and MetricsLocalStore -- to keep the metrics accepted from the node. type Metrics = (EKG.Store, TVar MetricsLocalStore)