Skip to content

Commit

Permalink
Make ports configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Ospald committed Nov 17, 2020
1 parent fe856ee commit 02b2ac4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
13 changes: 11 additions & 2 deletions lib/cli/src/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ import System.Directory
, doesFileExist
, getXdgDirectory
)
import System.Environment
( lookupEnv )
import System.Exit
( exitFailure, exitSuccess )
import System.FilePath
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/shelley/cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ library
, ouroboros-consensus-shelley
, ouroboros-network
, ouroboros-network-framework
, port-utils
, process
, random
, retry
Expand Down
7 changes: 7 additions & 0 deletions lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions nix/.stack.nix/cardano-wallet.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion nix/.stack.nix/default.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 02b2ac4

Please sign in to comment.