diff --git a/lib/cli/src/Cardano/CLI.hs b/lib/cli/src/Cardano/CLI.hs index f0d71ff8e9f..6b2928638fa 100644 --- a/lib/cli/src/Cardano/CLI.hs +++ b/lib/cli/src/Cardano/CLI.hs @@ -294,6 +294,8 @@ import System.Directory , doesFileExist , getXdgDirectory ) +import System.Environment + ( lookupEnv ) import System.Exit ( exitFailure, exitSuccess ) import System.FilePath @@ -314,6 +316,8 @@ import System.IO , stdin , stdout ) +import Text.Read + ( readMaybe ) import qualified Cardano.BM.Backend.EKGView as EKG import qualified Cardano.BM.Configuration.Model as CM @@ -1554,14 +1558,18 @@ initTracer -> [LogOutput] -> IO (Switchboard Text, (CM.Configuration, Trace IO Text)) initTracer loggerName outputs = do + ekg_port <- fromMaybe 13788 . (>>= readMaybe @Int) + <$> lookupEnv "CARDANO_WALLET_EKG_PORT" + prometheus_port <- fromMaybe 13798 . (>>= readMaybe @Int) + <$> lookupEnv "CARDANO_WALLET_PROMETHEUS_PORT" cfg <- do c <- defaultConfigStdout CM.setSetupBackends c [CM.KatipBK, CM.AggregationBK, CM.EKGViewBK, CM.EditorBK] CM.setDefaultBackends c [CM.KatipBK, CM.EKGViewBK] CM.setSetupScribes c $ map mkScribe outputs CM.setDefaultScribes c $ map mkScribeId outputs - CM.setEKGBindAddr c $ Just (Endpoint ("127.0.0.1", 13788)) - CM.setPrometheusBindAddr c $ Just ("127.0.0.1", 13798) + CM.setEKGBindAddr c $ Just (Endpoint ("127.0.0.1", ekg_port)) + CM.setPrometheusBindAddr c $ Just ("127.0.0.1", prometheus_port) CM.setBackends c "cardano-wallet.metrics" (Just [CM.EKGViewBK]) pure c (tr, sb) <- setupTrace_ cfg loggerName @@ -1570,6 +1578,7 @@ initTracer loggerName outputs = do pure (sb, (cfg, tr)) where + -- https://github.com/input-output-hk/cardano-node/blob/f7d57e30c47028ba2aeb306a4f21b47bb41dec01/cardano-node/src/Cardano/Node/Configuration/Logging.hs#L224 startCapturingMetrics :: Trace IO Text -> IO () startCapturingMetrics trace0 = do let trace = appendName "metrics" trace0 diff --git a/lib/shelley/cardano-wallet.cabal b/lib/shelley/cardano-wallet.cabal index b8509e2db36..ec78d5ffae0 100644 --- a/lib/shelley/cardano-wallet.cabal +++ b/lib/shelley/cardano-wallet.cabal @@ -70,6 +70,7 @@ library , ouroboros-consensus-shelley , ouroboros-network , ouroboros-network-framework + , port-utils , process , random , retry diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs index c0c16c23c5c..281646fbc95 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs @@ -164,6 +164,8 @@ import Data.Time.Clock.POSIX ( posixSecondsToUTCTime, utcTimeToPOSIXSeconds ) import GHC.TypeLits ( KnownNat, Nat, SomeNat (..), someNatVal ) +import Network.Socket.Free + ( getFreePort ) import Options.Applicative ( Parser, flag', help, long, metavar, (<|>) ) import Ouroboros.Consensus.Shelley.Node @@ -513,6 +515,11 @@ withCluster -> IO a withCluster tr severity poolConfigs dir logFile onByron onFork onClusterStart = bracketTracer' tr "withCluster" $ do + ekg_port <- getFreePort + prometheus_port <- getFreePort + setEnv "CARDANO_WALLET_EKG_PORT" (show ekg_port) + setEnv "CARDANO_WALLET_PROMETHEUS_PORT" (show prometheus_port) + traceWith tr $ MsgStartingCluster dir let poolCount = length poolConfigs (port0:ports) <- randomUnusedTCPPorts (poolCount + 2) diff --git a/nix/.stack.nix/cardano-wallet.nix b/nix/.stack.nix/cardano-wallet.nix index 652e1092525..fbcd5809144 100644 --- a/nix/.stack.nix/cardano-wallet.nix +++ b/nix/.stack.nix/cardano-wallet.nix @@ -67,9 +67,8 @@ (hsPkgs."ouroboros-consensus-shelley" or (errorHandler.buildDepError "ouroboros-consensus-shelley")) (hsPkgs."ouroboros-network" or (errorHandler.buildDepError "ouroboros-network")) (hsPkgs."ouroboros-network-framework" or (errorHandler.buildDepError "ouroboros-network-framework")) + (hsPkgs."port-utils" or (errorHandler.buildDepError "port-utils")) (hsPkgs."process" or (errorHandler.buildDepError "process")) - (hsPkgs."prometheus-client" or (errorHandler.buildDepError "prometheus-client")) - (hsPkgs."prometheus-metrics-ghc" or (errorHandler.buildDepError "prometheus-metrics-ghc")) (hsPkgs."random" or (errorHandler.buildDepError "random")) (hsPkgs."retry" or (errorHandler.buildDepError "retry")) (hsPkgs."servant-server" or (errorHandler.buildDepError "servant-server")) diff --git a/nix/.stack.nix/default.nix b/nix/.stack.nix/default.nix index 657632af829..611cc42ace9 100644 --- a/nix/.stack.nix/default.nix +++ b/nix/.stack.nix/default.nix @@ -15,7 +15,6 @@ "directory" = (((hackage.directory)."1.3.3.0").revisions).default; "process" = (((hackage.process)."1.6.5.0").revisions).default; "time" = (((hackage.time)."1.8.0.2").revisions).default; - "prometheus-metrics-ghc" = (((hackage.prometheus-metrics-ghc)."1.0.1.1").revisions).default; "base16" = (((hackage.base16)."0.1.2.1").revisions).default; "base58-bytestring" = (((hackage.base58-bytestring)."0.1.0").revisions).default; "base64" = (((hackage.base64)."0.4.2").revisions).default;