Skip to content

Commit

Permalink
Merge pull request #143 from coinbase/patrick/progress-endpoint
Browse files Browse the repository at this point in the history
Expose a Status Endpoint for check:*
  • Loading branch information
patrick-ogrady authored Sep 30, 2020
2 parents ae4ef80 + 4972b54 commit a3b47a4
Show file tree
Hide file tree
Showing 17 changed files with 523 additions and 227 deletions.
16 changes: 13 additions & 3 deletions cmd/check_construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"time"

"github.com/coinbase/rosetta-cli/pkg/results"
"github.com/coinbase/rosetta-cli/pkg/tester"

"github.com/coinbase/rosetta-sdk-go/fetcher"
Expand Down Expand Up @@ -70,7 +71,7 @@ func runCheckConstructionCmd(cmd *cobra.Command, args []string) {

_, _, fetchErr := fetcher.InitializeAsserter(ctx, Config.Network)
if fetchErr != nil {
tester.ExitConstruction(
results.ExitConstruction(
Config,
nil,
nil,
Expand All @@ -81,7 +82,7 @@ func runCheckConstructionCmd(cmd *cobra.Command, args []string) {

_, err := utils.CheckNetworkSupported(ctx, Config.Network, fetcher)
if err != nil {
tester.ExitConstruction(
results.ExitConstruction(
Config,
nil,
nil,
Expand All @@ -99,7 +100,7 @@ func runCheckConstructionCmd(cmd *cobra.Command, args []string) {
&SignalReceived,
)
if err != nil {
tester.ExitConstruction(
results.ExitConstruction(
Config,
nil,
nil,
Expand Down Expand Up @@ -135,6 +136,15 @@ func runCheckConstructionCmd(cmd *cobra.Command, args []string) {
return tester.LogMemoryLoop(ctx)
})

g.Go(func() error {
return tester.StartServer(
ctx,
"check:construction status",
constructionTester,
Config.Construction.StatusPort,
)
})

sigListeners := []context.CancelFunc{cancel}
go handleSignals(&sigListeners)

Expand Down
12 changes: 9 additions & 3 deletions cmd/check_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"time"

"github.com/coinbase/rosetta-cli/pkg/results"
"github.com/coinbase/rosetta-cli/pkg/tester"

"github.com/coinbase/rosetta-sdk-go/fetcher"
Expand Down Expand Up @@ -83,7 +84,7 @@ func runCheckDataCmd(cmd *cobra.Command, args []string) {

_, _, fetchErr := fetcher.InitializeAsserter(ctx, Config.Network)
if fetchErr != nil {
tester.ExitData(
results.ExitData(
Config,
nil,
nil,
Expand All @@ -96,7 +97,7 @@ func runCheckDataCmd(cmd *cobra.Command, args []string) {

networkStatus, err := utils.CheckNetworkSupported(ctx, Config.Network, fetcher)
if err != nil {
tester.ExitData(
results.ExitData(
Config,
nil,
nil,
Expand Down Expand Up @@ -146,7 +147,12 @@ func runCheckDataCmd(cmd *cobra.Command, args []string) {
})

g.Go(func() error {
return dataTester.StartProgressLogger(ctx)
return tester.StartServer(
ctx,
"check:data status",
dataTester,
Config.Data.StatusPort,
)
})

sigListeners := []context.CancelFunc{cancel}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print rosetta-cli version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v0.5.5")
fmt.Println("v0.5.6")
},
}
20 changes: 20 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
DefaultBroadcastLimit = 3
DefaultTipDelay = 300
DefaultBlockBroadcastLimit = 5
DefaultStatusPort = 9090

// ETH Defaults
EthereumIDBlockchain = "Ethereum"
Expand Down Expand Up @@ -135,6 +136,11 @@ type ConstructionConfiguration struct {
// workflows should be performed before stopping.
EndConditions map[string]int `json:"end_conditions,omitempty"`

// StatusPort allows the caller to query a running check:construction
// test to get stats about progress. This can be used instead
// of parsing logs to populate some sort of status dashboard.
StatusPort uint `json:"status_port,omitempty"`

// ResultsOutputFile is the absolute filepath of where to save
// the results of a check:construction run.
ResultsOutputFile string `json:"results_output_file,omitempty"`
Expand All @@ -147,6 +153,7 @@ func DefaultDataConfiguration() *DataConfiguration {
ActiveReconciliationConcurrency: DefaultActiveReconciliationConcurrency,
InactiveReconciliationConcurrency: DefaultInactiveReconciliationConcurrency,
InactiveReconciliationFrequency: DefaultInactiveReconciliationFrequency,
StatusPort: DefaultStatusPort,
}
}

Expand Down Expand Up @@ -271,6 +278,11 @@ type DataConfiguration struct {
// EndCondition contains the conditions for the syncer to stop
EndConditions *DataEndConditions `json:"end_conditions,omitempty"`

// StatusPort allows the caller to query a running check:data
// test to get stats about progress. This can be used instead
// of parsing logs to populate some sort of status dashboard.
StatusPort uint `json:"status_port,omitempty"`

// ResultsOutputFile is the absolute filepath of where to save
// the results of a check:data run.
ResultsOutputFile string `json:"results_output_file"`
Expand Down Expand Up @@ -354,6 +366,10 @@ func populateConstructionMissingFields(
constructionConfig.BlockBroadcastLimit = DefaultBlockBroadcastLimit
}

if constructionConfig.StatusPort == 0 {
constructionConfig.StatusPort = DefaultStatusPort
}

return constructionConfig
}

Expand All @@ -374,6 +390,10 @@ func populateDataMissingFields(dataConfig *DataConfiguration) *DataConfiguration
dataConfig.InactiveReconciliationFrequency = DefaultInactiveReconciliationFrequency
}

if dataConfig.StatusPort == 0 {
dataConfig.StatusPort = DefaultStatusPort
}

return dataConfig
}

Expand Down
3 changes: 3 additions & 0 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var (
StaleDepth: 12,
BroadcastLimit: 200,
BlockBroadcastLimit: 992,
StatusPort: 21,
Workflows: append(
fakeWorkflows,
&job.Workflow{
Expand All @@ -75,6 +76,7 @@ var (
ReconciliationDisabled: false,
HistoricalBalanceEnabled: &historicalEnabled,
StartIndex: &startIndex,
StatusPort: 123,
EndConditions: &DataEndConditions{
ReconciliationCoverage: &goodCoverage,
},
Expand Down Expand Up @@ -153,6 +155,7 @@ func TestLoadConfiguration(t *testing.T) {
StaleDepth: DefaultStaleDepth,
BroadcastLimit: DefaultBroadcastLimit,
BlockBroadcastLimit: DefaultBlockBroadcastLimit,
StatusPort: DefaultStatusPort,
Workflows: fakeWorkflows,
}

Expand Down
1 change: 1 addition & 0 deletions examples/configuration/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"inactive_discrepency_search_disabled": false,
"balance_tracking_disabled": false,
"coin_tracking_disabled": false,
"status_port": 9090,
"results_output_file": "",
"pruning_disabled": false
}
Expand Down
Loading

0 comments on commit a3b47a4

Please sign in to comment.