Skip to content

Commit

Permalink
SCB: Moving the EKG config into the YAML file.
Browse files Browse the repository at this point in the history
To date, it's been something you enable or disable with a command line
flag, but I think you probably either always want it or never want it,
so putting in the config file makes more sense.
  • Loading branch information
Kris Jenkins authored and krisajenkins committed Jul 1, 2020
1 parent ad7fb6a commit d067aa8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
23 changes: 7 additions & 16 deletions plutus-scb/app/Main.hs
Expand Up @@ -38,7 +38,7 @@ import Language.Plutus.Contract.Effects.ExposeEndpoint (EndpointDescri
import Options.Applicative (CommandFields, Mod, Parser, argument, auto, command,
customExecParser, disambiguate, eitherReader, flag,
fullDesc, help, helper, idm, info, infoOption, long,
metavar, option, optional, prefs, progDesc, short,
metavar, option, prefs, progDesc, short,
showHelpOnEmpty, showHelpOnError, str, strArgument,
strOption, subparser, value)
import Plutus.SCB.App (App, runApp)
Expand All @@ -47,8 +47,8 @@ import qualified Plutus.SCB.Core as Core
import qualified Plutus.SCB.Core.ContractInstance as Instance
import Plutus.SCB.Events.Contract (ContractInstanceId (..), ContractInstanceState)
import Plutus.SCB.Types (Config (Config), ContractExe (..), chainIndexConfig,
nodeServerConfig, signingProcessConfig,
walletServerConfig)
monitoringConfig, monitoringPort, nodeServerConfig,
signingProcessConfig, walletServerConfig)
import Plutus.SCB.Utils (logErrorS, render)
import qualified Plutus.SCB.Webserver.Server as SCBServer
import qualified PSGenerator
Expand Down Expand Up @@ -91,17 +91,8 @@ logLevelFlag =
LevelDebug
(short 'v' <> long "verbose" <> help "Enable debugging output.")

commandLineParser :: Parser (Maybe Int, LogLevel, FilePath, Command)
commandLineParser =
(,,,) <$> optional ekgPortParser <*> logLevelFlag <*> configFileParser <*>
commandParser

ekgPortParser :: Parser Int
ekgPortParser =
option
auto
(long "monitoring-port" <>
short 'p' <> metavar "PORT" <> help "Open an EKG server on PORT")
commandLineParser :: Parser (LogLevel, FilePath, Command)
commandLineParser = (,,) <$> logLevelFlag <*> configFileParser <*> commandParser

configFileParser :: Parser FilePath
configFileParser =
Expand Down Expand Up @@ -365,12 +356,12 @@ runCliCommand _ _ _ PSGenerator {_outputDir} =

main :: IO ()
main = do
(ekgPort, minLogLevel, configPath, cmd) <-
(minLogLevel, configPath, cmd) <-
customExecParser
(prefs $ disambiguate <> showHelpOnEmpty <> showHelpOnError)
(info (helper <*> versionOption <*> commandLineParser) idm)
config <- liftIO $ decodeFileThrow configPath
traverse_ (EKG.forkServer "localhost") ekgPort
traverse_ (EKG.forkServer "localhost") (monitoringPort <$> monitoringConfig config)
serviceAvailability <- newToken
result <-
runApp minLogLevel config $ do
Expand Down
9 changes: 7 additions & 2 deletions plutus-scb/plutus-scb.yaml.sample
Expand Up @@ -28,5 +28,10 @@ chainIndexConfig:

signingProcessConfig:
spBaseUrl: http://localhost:8084
spWallet:
getWallet: 1
spWallet:
getWallet: 1

# Optional EKG Server Config
# ----
# monitoringConfig:
# monitoringPort: 8090
7 changes: 7 additions & 0 deletions plutus-scb/src/Plutus/SCB/Types.hs
Expand Up @@ -72,6 +72,13 @@ data Config =
, scbWebserverConfig :: WebserverConfig
, chainIndexConfig :: ChainIndex.ChainIndexConfig
, signingProcessConfig :: SigningProcess.SigningProcessConfig
, monitoringConfig :: Maybe MonitoringConfig
}
deriving (Show, Eq, Generic, FromJSON)

data MonitoringConfig =
MonitoringConfig
{ monitoringPort :: Int
}
deriving (Show, Eq, Generic, FromJSON)

Expand Down

0 comments on commit d067aa8

Please sign in to comment.