Skip to content

Commit

Permalink
feat!: Split telemetry http from inspect
Browse files Browse the repository at this point in the history
telemetry:
- node:       10000
- evm-reader: 10001
- advancer:   10002
- validator:  10003
- claimer:    10004

APIs:
- inspect:    10012
  • Loading branch information
mpolitzer committed Dec 17, 2024
1 parent c9ab4fa commit 55e21fd
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 183 deletions.
12 changes: 9 additions & 3 deletions cmd/cartesi-rollups-advancer/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ var (
createInfo = advancer.CreateInfo{
CreateInfo: service.CreateInfo{
Name: "advancer",
ProcOwner: true,
EnableSignalHandling: true,
TelemetryCreate: true,
TelemetryAddress: ":10001",
TelemetryAddress: ":10002",
Impl: &advancerService,
},
MaxStartupTime: 10 * time.Second,
InspectAddress: ":10012",
}
)

Expand All @@ -36,6 +36,9 @@ var Cmd = &cobra.Command{

func init() {
createInfo.LoadEnv()
Cmd.Flags().StringVar(&createInfo.TelemetryAddress,
"telemetry-address", createInfo.TelemetryAddress,
"telemetry address")
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Expand All @@ -45,10 +48,13 @@ func init() {
Cmd.Flags().DurationVar(&createInfo.MaxStartupTime,
"max-startup-time", createInfo.MaxStartupTime,
"maximum startup time in seconds")
Cmd.Flags().StringVar(&createInfo.InspectAddress,
"inspect-address", createInfo.InspectAddress,
"inspect address")
}

func run(cmd *cobra.Command, args []string) {
cobra.CheckErr(advancer.Create(&createInfo, &advancerService))
advancerService.CreateDefaultHandlers("/" + advancerService.Name)
advancerService.CreateDefaultHandlers("")
cobra.CheckErr(advancerService.Serve())
}
17 changes: 8 additions & 9 deletions cmd/cartesi-rollups-claimer/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ var (
createInfo = claimer.CreateInfo{
CreateInfo: service.CreateInfo{
Name: "claimer",
ProcOwner: true,
EnableSignalHandling: true,
TelemetryCreate: true,
TelemetryAddress: ":10003",
TelemetryAddress: ":10004",
Impl: &claimerService,
},
EnableSubmission: true,
Expand All @@ -42,18 +41,18 @@ func init() {
Cmd.Flags().StringVar(&createInfo.TelemetryAddress,
"telemetry-address", createInfo.TelemetryAddress,
"health check and metrics address and port")
Cmd.Flags().StringVar(&createInfo.BlockchainHttpEndpoint.Value,
"blockchain-http-endpoint", createInfo.BlockchainHttpEndpoint.Value,
"blockchain http endpoint")
Cmd.Flags().DurationVar(&createInfo.PollInterval,
"poll-interval", createInfo.PollInterval,
"poll interval")
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Cmd.Flags().BoolVar(&createInfo.LogPretty,
"log-color", createInfo.LogPretty,
"tint the logs (colored output)")
Cmd.Flags().StringVar(&createInfo.BlockchainHttpEndpoint.Value,
"blockchain-http-endpoint", createInfo.BlockchainHttpEndpoint.Value,
"blockchain http endpoint")
Cmd.Flags().DurationVar(&createInfo.PollInterval,
"poll-interval", createInfo.PollInterval,
"poll interval")
Cmd.Flags().DurationVar(&createInfo.MaxStartupTime,
"max-startup-time", createInfo.MaxStartupTime,
"maximum startup time in seconds")
Expand All @@ -64,6 +63,6 @@ func init() {

func run(cmd *cobra.Command, args []string) {
cobra.CheckErr(claimer.Create(&createInfo, &claimerService))
claimerService.CreateDefaultHandlers("/" + claimerService.Name)
claimerService.CreateDefaultHandlers("")
cobra.CheckErr(claimerService.Serve())
}
30 changes: 12 additions & 18 deletions cmd/cartesi-rollups-evm-reader/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ var (
createInfo = evmreader.CreateInfo{
CreateInfo: service.CreateInfo{
Name: "evm-reader",
ProcOwner: true,
EnableSignalHandling: true,
TelemetryCreate: true,
TelemetryAddress: ":10000",
TelemetryAddress: ":10001",
Impl: &readerService,
},
EvmReaderPersistentConfig: model.EvmReaderPersistentConfig{
Expand All @@ -47,45 +46,40 @@ var Cmd = &cobra.Command{

func init() {
createInfo.LoadEnv()

Cmd.Flags().StringVar(&createInfo.TelemetryAddress,
"telemetry-address", createInfo.TelemetryAddress,
"telemetry address")
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Cmd.Flags().BoolVar(&createInfo.LogPretty,
"log-color", createInfo.LogPretty,
"tint the logs (colored output)")
Cmd.Flags().StringVarP(&DefaultBlockString,
"default-block", "d", DefaultBlockString,
`Default block to be used when fetching new blocks.
One of 'latest', 'safe', 'pending', 'finalized'`)

Cmd.Flags().StringVarP(&createInfo.PostgresEndpoint.Value,
"postgres-endpoint",
"p",
createInfo.PostgresEndpoint.Value,
"Postgres endpoint")

Cmd.Flags().StringVarP(&createInfo.BlockchainHttpEndpoint.Value,
"blockchain-http-endpoint",
"b",
createInfo.BlockchainHttpEndpoint.Value,
"Blockchain HTTP Endpoint")

Cmd.Flags().StringVarP(&createInfo.BlockchainWsEndpoint.Value,
"blockchain-ws-endpoint",
"w",
createInfo.BlockchainWsEndpoint.Value,
"Blockchain WS Endpoint")

Cmd.Flags().Var(&inputBoxAddress,
"inputbox-address",
"Input Box contract address")

Cmd.Flags().Uint64VarP(&createInfo.InputBoxDeploymentBlock,
"inputbox-block-number",
"n",
0,
"inputbox-block-number", "n", 0,
"Input Box deployment block number")
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Cmd.Flags().BoolVar(&createInfo.LogPretty,
"log-color", createInfo.LogPretty,
"tint the logs (colored output)")
Cmd.Flags().DurationVar(&createInfo.MaxStartupTime,
"max-startup-time", createInfo.MaxStartupTime,
"maximum startup time in seconds")
Expand All @@ -102,6 +96,6 @@ func run(cmd *cobra.Command, args []string) {
}

cobra.CheckErr(evmreader.Create(&createInfo, &readerService))
readerService.CreateDefaultHandlers("/" + readerService.Name)
readerService.CreateDefaultHandlers("")
cobra.CheckErr(readerService.Serve())
}
12 changes: 7 additions & 5 deletions cmd/cartesi-rollups-node/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ var (
createInfo = node.CreateInfo{
CreateInfo: service.CreateInfo{
Name: "cartesi-rollups-node",
ProcOwner: true,
EnableSignalHandling: true,
TelemetryCreate: true,
TelemetryAddress: ":10001",
TelemetryAddress: ":10000",
Impl: &nodeService,
},
MaxStartupTime: 10 * time.Second,
Expand All @@ -38,15 +37,18 @@ var Cmd = &cobra.Command{

func init() {
createInfo.LoadEnv()
Cmd.Flags().BoolVar(&createInfo.EnableClaimSubmission,
"claim-submission", createInfo.EnableClaimSubmission,
"enable or disable claim submission (reader mode)")
Cmd.Flags().StringVar(&createInfo.TelemetryAddress,
"telemetry-address", createInfo.TelemetryAddress,
"telemetry address")
Cmd.Flags().Var(&createInfo.LogLevel,
"log-level",
"log level: debug, info, warn or error")
Cmd.Flags().BoolVar(&createInfo.LogPretty,
"log-color", createInfo.LogPretty,
"tint the logs (colored output)")
Cmd.Flags().BoolVar(&createInfo.EnableClaimSubmission,
"claim-submission", createInfo.EnableClaimSubmission,
"enable or disable claim submission (reader mode)")
Cmd.Flags().DurationVar(&createInfo.MaxStartupTime,
"max-startup-time", createInfo.MaxStartupTime,
"maximum startup time in seconds")
Expand Down
5 changes: 2 additions & 3 deletions cmd/cartesi-rollups-validator/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ var (
createInfo = validator.CreateInfo{
CreateInfo: service.CreateInfo{
Name: "validator",
ProcOwner: true,
EnableSignalHandling: true,
TelemetryCreate: true,
TelemetryAddress: ":10002",
TelemetryAddress: ":10003",
Impl: &validatorService,
},
}
Expand Down Expand Up @@ -54,6 +53,6 @@ func init() {

func run(cmd *cobra.Command, args []string) {
cobra.CheckErr(validator.Create(&createInfo, &validatorService))
validatorService.CreateDefaultHandlers("/" + validatorService.Name)
validatorService.CreateDefaultHandlers("")
cobra.CheckErr(validatorService.Serve())
}
31 changes: 15 additions & 16 deletions internal/advancer/advancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ type IAdvancerMachines interface {

type Service struct {
service.Service
repository IAdvancerRepository
machines IAdvancerMachines
inspector inspect.Inspector
repository IAdvancerRepository
machines IAdvancerMachines
inspector inspect.Inspector
HTTPServer *http.Server
HTTPServerFunc func() error
}

type CreateInfo struct {
Expand All @@ -57,23 +59,22 @@ type CreateInfo struct {
PostgresEndpoint config.Redacted[string]
PostgresSslMode bool
Repository *repository.Database
HttpAddress string
HttpPort int
MachineServerVerbosity config.Redacted[cartesimachine.ServerVerbosity]
Machines *machines.Machines
MaxStartupTime time.Duration
InspectAddress string
InspectServeMux *http.ServeMux
}

func (c *CreateInfo) LoadEnv() {
c.PostgresEndpoint.Value = config.GetPostgresEndpoint()
c.PollInterval = config.GetAdvancerPollingInterval()
c.HttpAddress = config.GetHttpAddress()
c.HttpPort = config.GetHttpPort()
c.MachineServerVerbosity.Value =
cartesimachine.ServerVerbosity(config.GetMachineServerVerbosity())
c.LogLevel = service.LogLevel(config.GetLogLevel())
c.LogPretty = config.GetLogPrettyEnabled()
c.MaxStartupTime = config.GetMaxStartupTime()
c.InspectAddress = config.GetInspectAddress()
}

func Create(c *CreateInfo, s *Service) error {
Expand Down Expand Up @@ -110,19 +111,17 @@ func Create(c *CreateInfo, s *Service) error {
logger = logger.With("service", "inspect")
s.inspector = inspect.Inspector{
IInspectMachines: c.Machines,
Logger: logger,
}
if s.Service.ServeMux == nil {
if c.CreateInfo.ServeMux == nil {
c.ServeMux = http.NewServeMux()
}
s.ServeMux = c.ServeMux
Logger: logger,
ServeMux: http.NewServeMux(),
}

s.ServeMux.Handle("/inspect/{dapp}",
s.inspector.ServeMux.Handle("/inspect/{dapp}",
services.CorsMiddleware(http.Handler(&s.inspector)))
s.ServeMux.Handle("/inspect/{dapp}/{payload}",
s.inspector.ServeMux.Handle("/inspect/{dapp}/{payload}",
services.CorsMiddleware(http.Handler(&s.inspector)))
s.HTTPServer, s.HTTPServerFunc = s.inspector.CreateInspectServer(
c.InspectAddress, 3, 5*time.Second, s.inspector.ServeMux)
go s.HTTPServerFunc()
}
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion internal/claimer/claimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *CreateInfo) LoadEnv() {
c.PostgresEndpoint.Value = config.GetPostgresEndpoint()
c.PollInterval = config.GetClaimerPollingInterval()
c.LogLevel = service.LogLevel(config.GetLogLevel())
c.MaxStartupTime = config.GetMaxStartupTime()
c.LogPretty = config.GetLogPrettyEnabled()
}

func Create(c *CreateInfo, s *Service) error {
Expand Down
13 changes: 3 additions & 10 deletions internal/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,11 @@ for more information."""
# HTTP
#

[http.CARTESI_HTTP_ADDRESS]
default = "127.0.0.1"
[http.CARTESI_INSPECT_ADDRESS]
default = ":10012"
go-type = "string"
description = """
HTTP address for the node."""

[http.CARTESI_HTTP_PORT]
default = "10000"
go-type = "int"
description = """
HTTP port for the node.
The node will also use the 20 ports after this one for internal services."""
HTTP address for inspect."""

#
# Temporary
Expand Down
20 changes: 4 additions & 16 deletions internal/config/generated.go

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

4 changes: 2 additions & 2 deletions internal/evmreader/retrypolicy_application_delegator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func NewApplicationWithRetryPolicy(
delegate ApplicationContract,
maxRetries uint64,
delayBetweenCalls time.Duration,
logger *slog.Logger,
logger *slog.Logger,
) *ApplicationRetryPolicyDelegator {
return &ApplicationRetryPolicyDelegator{
delegate: delegate,
maxRetries: maxRetries,
delayBetweenCalls: delayBetweenCalls,
logger: logger,
logger: logger,
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/evmreader/retrypolicy_consensus_delegator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func NewConsensusWithRetryPolicy(
delegate ConsensusContract,
maxRetries uint64,
delayBetweenCalls time.Duration,
logger *slog.Logger,
logger *slog.Logger,
) *ConsensusRetryPolicyDelegator {
return &ConsensusRetryPolicyDelegator{
delegate: delegate,
maxRetries: maxRetries,
delayBetweenCalls: delayBetweenCalls,
logger: logger,
logger: logger,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/evmreader/retrypolicy_ethclient_delegator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewEhtClientWithRetryPolicy(
delegate: delegate,
maxRetries: maxRetries,
delayBetweenCalls: delayBetweenCalls,
logger: logger,
logger: logger,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/evmreader/retrypolicy_ethwsclient_delegator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewEthWsClientWithRetryPolicy(
delegate: delegate,
maxRetries: maxRetries,
delayBetweenCalls: delayBetweenCalls,
logger: logger,
logger: logger,
}
}

Expand Down
Loading

0 comments on commit 55e21fd

Please sign in to comment.