Skip to content

Configurable metrics port in submit-api #4281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2022
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
2 changes: 1 addition & 1 deletion cardano-submit-api/src/Cardano/TxSubmit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ runTxSubmitWebapi :: TxSubmitNodeParams -> IO ()
runTxSubmitWebapi tsnp = do
tsnc <- readTxSubmitNodeConfig (unConfigFile $ tspConfigFile tsnp)
trce <- mkTracer tsnc
(metrics, metricsServer) <- registerMetricsServer
(metrics, metricsServer) <- registerMetricsServer (tspMetricsPort tsnp)
txSubmitServer <- Async.async $
runTxSubmitServer trce metrics tspWebserverConfig tspProtocol tspNetworkId tspSocketPath
void $ Async.waitAnyCancel
Expand Down
10 changes: 10 additions & 0 deletions cardano-submit-api/src/Cardano/TxSubmit/CLI/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Cardano.TxSubmit.Rest.Parsers (pWebserverConfig)
import Control.Applicative (Alternative (..), Applicative (..), (<**>))
import Data.Function ((.))
import Data.Functor (Functor (fmap), (<$>))
import Data.Int
import Data.Semigroup (Semigroup ((<>)))
import Data.Word (Word64)
import Options.Applicative (Parser, ParserInfo)
Expand All @@ -37,6 +38,7 @@ pTxSubmitNodeParams = TxSubmitNodeParams
<*> pNetworkId
<*> pSocketPath
<*> pWebserverConfig 8090
<*> pMetricsPort 8081

pConfigFile :: Parser ConfigFile
pConfigFile = ConfigFile <$> Opt.strOption
Expand Down Expand Up @@ -122,3 +124,11 @@ pSocketPath = SocketPath <$> Opt.strOption
<> Opt.completer (Opt.bashCompleter "file")
<> Opt.metavar "FILEPATH"
)

pMetricsPort :: Int -> Parser Int
pMetricsPort defaultValue = Opt.option Opt.auto
( Opt.long "metrics-port"
<> Opt.help "Metrics port"
<> Opt.metavar "PORT"
<> Opt.value defaultValue
)
2 changes: 2 additions & 0 deletions cardano-submit-api/src/Cardano/TxSubmit/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Cardano.TxSubmit.CLI.Types

import Cardano.Api (AnyConsensusModeParams, NetworkId (..))
import Cardano.TxSubmit.Rest.Types (WebserverConfig)
import Data.Int
import System.IO (FilePath)

-- | The product type of all command line arguments
Expand All @@ -16,6 +17,7 @@ data TxSubmitNodeParams = TxSubmitNodeParams
, tspNetworkId :: !NetworkId
, tspSocketPath :: !SocketPath
, tspWebserverConfig :: !WebserverConfig
, tspMetricsPort :: !Int
}

newtype ConfigFile = ConfigFile
Expand Down
7 changes: 4 additions & 3 deletions cardano-submit-api/src/Cardano/TxSubmit/Metrics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Control.Applicative (Applicative (pure), (<$>))
import Control.Concurrent.Async (Async, async)
import Control.Monad.Reader (MonadIO (liftIO), MonadReader (ask), ReaderT (runReaderT))
import Data.Function (($), (.))
import Data.Int
import Data.Monoid (Monoid (mempty))
import System.IO (IO)
import System.Metrics.Prometheus.Concurrent.RegistryT (RegistryT (..), registerGauge,
Expand All @@ -22,12 +23,12 @@ newtype TxSubmitMetrics = TxSubmitMetrics
{ tsmCount :: Gauge
}

registerMetricsServer :: IO (TxSubmitMetrics, Async ())
registerMetricsServer =
registerMetricsServer :: Int -> IO (TxSubmitMetrics, Async ())
registerMetricsServer metricsPort =
runRegistryT $ do
metrics <- makeMetrics
registry <- RegistryT ask
server <- liftIO . async $ runReaderT (unRegistryT $ serveMetricsT 8081 []) registry
server <- liftIO . async $ runReaderT (unRegistryT $ serveMetricsT metricsPort []) registry
pure (metrics, server)

makeMetrics :: RegistryT IO TxSubmitMetrics
Expand Down