Skip to content

Commit

Permalink
cardano-tracer: correct node full id.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Shevchenko committed Sep 22, 2021
1 parent 3f68a4c commit a1c8c3d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 1 addition & 3 deletions cardano-tracer/src/Cardano/Tracer/Handlers/Logs/File.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'

Expand Down
17 changes: 12 additions & 5 deletions cardano-tracer/src/Cardano/Tracer/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Cardano.Tracer.Types
, initAcceptedMetrics
, initAcceptedNodeInfo
, prepareAcceptedMetrics
, printNodeFullId
) where

import Control.Concurrent.STM (atomically)
Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit a1c8c3d

Please sign in to comment.