Skip to content

Commit

Permalink
Add monitoring to CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed May 8, 2024
1 parent bce55b8 commit e076777
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 32 deletions.
71 changes: 71 additions & 0 deletions lib/local-cluster/lib/Cardano/Wallet/Launch/Cluster/CommandLine.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Wallet.Launch.Cluster.CommandLine
( CommandLineOptions (..)
Expand All @@ -16,14 +17,31 @@ import Cardano.Wallet.Launch.Cluster.FileOf
, FileOf (..)
, newAbsolutizer
)
import Cardano.Wallet.Launch.Cluster.Monitoring.Monitor
( MonitorConfiguration (..)
)
import Cardano.Wallet.Network.Ports
( PortNumber
)
import Control.Monad
( unless
)
import Control.Monitoring.Tracing
( MonitorState (..)
)
import Data.Maybe
( fromMaybe
)
import Options.Applicative
( Parser
, auto
, execParser
, help
, helper
, info
, long
, metavar
, option
, optional
, progDesc
, strOption
Expand All @@ -38,6 +56,7 @@ data CommandLineOptions = CommandLineOptions
, clusterDir :: Maybe (DirOf "cluster")
, clusterLogs :: Maybe (FileOf "cluster-logs")
, nodeToClientSocket :: FileOf "node-to-client-socket"
, monitoring :: MonitorConfiguration
}
deriving stock (Show)

Expand All @@ -51,10 +70,62 @@ parseCommandLineOptions = do
<*> clusterDirParser absolutizer
<*> clusterLogsParser absolutizer
<*> nodeToClientSocketParser absolutizer
<*> monitoringParser
<**> helper
)
(progDesc "Local Cluster for testing")

monitoringParser :: Parser MonitorConfiguration
monitoringParser =
mkMonitorConfiguration
<$> httpApiPortParser
<*> controlInitalStateParser
where
mkMonitorConfiguration port mstate =
MonitorConfiguration port
$ fromMaybe Run mstate

controlInitalStateParser :: Parser (Maybe MonitorState)
controlInitalStateParser =
optional
$ option
parse
( long "control-initial-state"
<> metavar "CONTROL_INITIAL_STATE"
<> help "Initial state of the control, wait, step or run"
)
where
parse = do
s :: String <- auto
case s of
"wait" -> pure Wait
"step" -> pure Step
"run" -> pure Run
_ -> fail "Invalid control initial state"

httpApiPortParser :: Parser (Maybe PortNumber)
httpApiPortParser = do
optional
$ option
parse
( long "monitoring-port"
<> metavar "MONITORING_PORT"
<> help "Port for the monitoring HTTP server"
)
where
parse = do
p <- auto
unless (p `elem` validPorts)
$ fail
$ "Invalid port number. Must be inside: "
++ show (head validPorts)
++ ".."
++ show (last validPorts)
pure p

validPorts :: [PortNumber]
validPorts = [1024 .. 65535]

nodeToClientSocketParser :: Absolutizer -> Parser (FileOf "node-to-client-socket")
nodeToClientSocketParser (Absolutizer absOf) =
FileOf . absOf . absRel
Expand Down
47 changes: 15 additions & 32 deletions lib/local-cluster/local-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,28 @@ maintainer: hal@cardanofoundation.org
copyright: 2023 Cardano Foundation
category: Web
build-type: Simple
data-files:
data/swagger.json
data-files: data/swagger.json

common language
default-language: Haskell2010
default-extensions:
NoImplicitPrelude
OverloadedStrings

ghc-options:
-fhelpful-errors
-fprint-expanded-synonyms
-freverse-errors
-fwarn-incomplete-uni-patterns
-fwarn-unused-do-bind
-Wall
-Wcompat
-Werror=incomplete-patterns
-Widentities
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-deriving-strategies
-Wmissing-local-signatures
-Wpartial-fields
-Wredundant-constraints
-Wtabs
-Wunused-foralls
-fhelpful-errors -fprint-expanded-synonyms -freverse-errors
-fwarn-incomplete-uni-patterns -fwarn-unused-do-bind -Wall -Wcompat
-Werror=incomplete-patterns -Widentities
-Wincomplete-record-updates -Wincomplete-uni-patterns
-Wmissing-deriving-strategies -Wmissing-local-signatures
-Wpartial-fields -Wredundant-constraints -Wtabs -Wunused-foralls
-Wunused-packages

flag release
description: Enable optimization and `-Werror`
default: False
manual: True


library
import: language
hs-source-dirs: lib
Expand Down Expand Up @@ -97,9 +85,9 @@ library
Cardano.Wallet.Launch.Cluster.Tx
Cardano.Wallet.Launch.Cluster.UnsafeInterval
Control.Monitoring.Concurrent
Control.Monitoring.Folder
Control.Monitoring.Monitor
Control.Monitoring.Tracing
Control.Monitoring.Folder

if flag(release)
ghc-options: -O2 -Werror
Expand Down Expand Up @@ -145,7 +133,6 @@ library
, lens
, machines
, memory
, network
, mtl
, network
, OddWord
Expand Down Expand Up @@ -175,33 +162,29 @@ executable local-cluster
import: language
main-is: local-cluster.hs
hs-source-dirs: exe
ghc-options: -threaded -rtsopts
ghc-options: -threaded -rtsopts
build-depends:
, base
, cardano-addresses
, cardano-wallet-application-extras
, cardano-wallet-launcher
, cardano-wallet-primitive
, contra-tracer
, directory
, iohk-monitoring
, iohk-monitoring-extra
, lens
, local-cluster
, mtl
, pathtype
, temporary-extra
, text-class
, unliftio
, with-utf8

test-suite test
import: language
type: exitcode-stdio-1.0
main-is: test.hs
ghc-options: -threaded -rtsopts
hs-source-dirs: test/unit

import: language
type: exitcode-stdio-1.0
main-is: test.hs
ghc-options: -threaded -rtsopts
hs-source-dirs: test/unit
build-depends:
, aeson
, base
Expand Down

0 comments on commit e076777

Please sign in to comment.