Repository: coinbase/rosetta-cli
Pull request #165 (2020-10-15 16:01:07)

[Logging] Expose Reconciler Queue Size + Last Checked
Related: https://github.com/coinbase/rosetta-sdk-go/pull/187

This PR exposes new reconciler information (`QueueSize` and `LastIndexReconciled`) in the `check:data` status endpoint.

### Changes
- [x] Update `rosetta-cli` version
- [x] Add logging changes
- [x] Update to new `rosetta-sdk-go` release


Patch:
diff --git a/cmd/root.go b/cmd/root.go
index 4b9687e..d276a4d 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -247,6 +247,6 @@ var versionCmd = &cobra.Command{
 	Use:   "version",
 	Short: "Print rosetta-cli version",
 	Run: func(cmd *cobra.Command, args []string) {
-		fmt.Println("v0.5.12")
+		fmt.Println("v0.5.13")
 	},
 }
diff --git a/go.mod b/go.mod
index 59790fa..be91211 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/coinbase/rosetta-cli
 go 1.13
 
 require (
-	github.com/coinbase/rosetta-sdk-go v0.5.3-0.20201015002757-978c228143a3
+	github.com/coinbase/rosetta-sdk-go v0.5.3
 	github.com/fatih/color v1.9.0
 	github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c
 	github.com/spf13/cobra v1.1.0
diff --git a/go.sum b/go.sum
index 7a6f0a7..7e847b3 100644
--- a/go.sum
+++ b/go.sum
@@ -82,6 +82,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
 github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U=
 github.com/coinbase/rosetta-sdk-go v0.5.3-0.20201015002757-978c228143a3 h1:p8p0dVZDh/Zs35tzQq3nFftgFbphNvSzZ6dzLT31F7I=
 github.com/coinbase/rosetta-sdk-go v0.5.3-0.20201015002757-978c228143a3/go.mod h1:QVVeKHWFNb0NyzEY06LxXMAylJkYa7n+Hk03pORr0ws=
+github.com/coinbase/rosetta-sdk-go v0.5.3 h1:AujxZ2VDbq80x7SJDHd1nKOYA8AFD5H27gx07uerFpw=
+github.com/coinbase/rosetta-sdk-go v0.5.3/go.mod h1:QVVeKHWFNb0NyzEY06LxXMAylJkYa7n+Hk03pORr0ws=
 github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
 github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
 github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go
index 5074fe2..c639a2a 100644
--- a/pkg/logger/logger.go
+++ b/pkg/logger/logger.go
@@ -122,12 +122,14 @@ func (l *Logger) LogDataStatus(ctx context.Context, status *results.CheckDataSta
 	}
 
 	progressMessage := fmt.Sprintf(
-		"[PROGRESS] Blocks Synced: %d/%d (Completed: %f%%, Rate: %f/second) Time Remaining: %s",
+		"[PROGRESS] Blocks Synced: %d/%d (Completed: %f%%, Rate: %f/second) Time Remaining: %s Reconciler Queue: %d (Last Index Checked: %d)", // nolint:lll
 		status.Progress.Blocks,
 		status.Progress.Tip,
 		status.Progress.Completed,
 		status.Progress.Rate,
 		status.Progress.TimeRemaining,
+		status.Progress.ReconcilerQueueSize,
+		status.Progress.ReconcilerLastIndex,
 	)
 
 	// Don't print out the same progress message twice.
diff --git a/pkg/results/data_results.go b/pkg/results/data_results.go
index a39a506..99f2104 100644
--- a/pkg/results/data_results.go
+++ b/pkg/results/data_results.go
@@ -27,6 +27,7 @@ import (
 
 	"github.com/coinbase/rosetta-sdk-go/asserter"
 	"github.com/coinbase/rosetta-sdk-go/fetcher"
+	"github.com/coinbase/rosetta-sdk-go/reconciler"
 	"github.com/coinbase/rosetta-sdk-go/storage"
 	"github.com/coinbase/rosetta-sdk-go/syncer"
 	"github.com/coinbase/rosetta-sdk-go/types"
@@ -228,11 +229,13 @@ func ComputeCheckDataStats(
 // CheckDataProgress contains information
 // about check:data's syncing progress.
 type CheckDataProgress struct {
-	Blocks        int64   `json:"blocks"`
-	Tip           int64   `json:"tip"`
-	Completed     float64 `json:"completed"`
-	Rate          float64 `json:"rate"`
-	TimeRemaining string  `json:"time_remaining"`
+	Blocks              int64   `json:"blocks"`
+	Tip                 int64   `json:"tip"`
+	Completed           float64 `json:"completed"`
+	Rate                float64 `json:"rate"`
+	TimeRemaining       string  `json:"time_remaining"`
+	ReconcilerQueueSize int     `json:"reconciler_queue_size"`
+	ReconcilerLastIndex int64   `json:"reconciler_last_index"`
 }
 
 // ComputeCheckDataProgress returns
@@ -242,6 +245,7 @@ func ComputeCheckDataProgress(
 	fetcher *fetcher.Fetcher,
 	network *types.NetworkIdentifier,
 	counters *storage.CounterStorage,
+	reconciler *reconciler.Reconciler,
 ) *CheckDataProgress {
 	networkStatus, fetchErr := fetcher.NetworkStatusRetry(ctx, network, nil)
 	if fetchErr != nil {
@@ -287,11 +291,13 @@ func ComputeCheckDataProgress(
 	blocksSyncedFloat, _ := blocksSynced.Float64()
 
 	return &CheckDataProgress{
-		Blocks:        adjustedBlocks,
-		Tip:           tipIndex,
-		Completed:     blocksSyncedFloat * utils.OneHundred,
-		Rate:          blocksPerSecondFloat,
-		TimeRemaining: utils.TimeToTip(blocksPerSecondFloat, adjustedBlocks, tipIndex).String(),
+		Blocks:              adjustedBlocks,
+		Tip:                 tipIndex,
+		Completed:           blocksSyncedFloat * utils.OneHundred,
+		Rate:                blocksPerSecondFloat,
+		TimeRemaining:       utils.TimeToTip(blocksPerSecondFloat, adjustedBlocks, tipIndex).String(),
+		ReconcilerQueueSize: reconciler.QueueSize(),
+		ReconcilerLastIndex: reconciler.LastIndexReconciled(),
 	}
 }
 
@@ -310,6 +316,7 @@ func ComputeCheckDataStatus(
 	balances *storage.BalanceStorage,
 	fetcher *fetcher.Fetcher,
 	network *types.NetworkIdentifier,
+	reconciler *reconciler.Reconciler,
 ) *CheckDataStatus {
 	return &CheckDataStatus{
 		Stats: ComputeCheckDataStats(
@@ -322,6 +329,7 @@ func ComputeCheckDataStatus(
 			fetcher,
 			network,
 			counters,
+			reconciler,
 		),
 	}
 }


Test patch:
diff --git a/pkg/tester/data.go b/pkg/tester/data.go
index d8b8e9b..dbbf05a 100644
--- a/pkg/tester/data.go
+++ b/pkg/tester/data.go
@@ -361,7 +361,14 @@ func (t *DataTester) StartPeriodicLogger(
 				big.NewInt(periodicLoggingSeconds),
 			)
 
-			status := results.ComputeCheckDataStatus(ctx, t.counterStorage, t.balanceStorage, t.fetcher, t.config.Network)
+			status := results.ComputeCheckDataStatus(
+				ctx,
+				t.counterStorage,
+				t.balanceStorage,
+				t.fetcher,
+				t.config.Network,
+				t.reconciler,
+			)
 			t.logger.LogDataStatus(ctx, status)
 		}
 	}
@@ -378,6 +385,7 @@ func (t *DataTester) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		t.balanceStorage,
 		t.fetcher,
 		t.network,
+		t.reconciler,
 	)
 
 	if err := json.NewEncoder(w).Encode(status); err != nil {