Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/tracing #395

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cmd/check_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ package cmd
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"time"

"github.com/coinbase/rosetta-cli/pkg/logger"
"github.com/coinbase/rosetta-cli/pkg/results"
"github.com/coinbase/rosetta-cli/pkg/tester"
"github.com/coinbase/rosetta-cli/pkg/tracer"
"github.com/coinbase/rosetta-sdk-go/client"
"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/coinbase/rosetta-sdk-go/utils"
Expand Down Expand Up @@ -74,6 +79,23 @@ of what one of these files looks like.`,
)

func runCheckDataCmd(_ *cobra.Command, _ []string) error {
var client *client.APIClient
if Config.EnableRequestInstrumentation == true {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
{
shutdown, err := tracer.InitProvider(Config)
if err != nil {
color.Yellow("Warning: %w ", err)
}
defer func() {
if err := shutdown(ctx); err != nil {
log.Fatal("failed to shutdown TracerProvider: %w", err)
}
}()
}
client = tracer.NewTracedClient(Config)
}
ensureDataDirectoryExists()
ctx, cancel := context.WithCancel(Context)

Expand All @@ -82,6 +104,7 @@ func runCheckDataCmd(_ *cobra.Command, _ []string) error {
metadata = logger.ConvertMapToString(metadataMap)

fetcherOpts := []fetcher.Option{
fetcher.WithClient(client),
fetcher.WithMaxConnections(Config.MaxOnlineConnections),
fetcher.WithRetryElapsedTime(time.Duration(Config.RetryElapsedTime) * time.Second),
fetcher.WithTimeout(time.Duration(Config.HTTPTimeout) * time.Second),
Expand Down
24 changes: 15 additions & 9 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ func DefaultPerfConfiguration() *CheckPerfConfiguration {
// EthereumNetwork, DefaultURL, DefaultTimeout, and DefaultDataConfiguration.
func DefaultConfiguration() *Configuration {
return &Configuration{
Network: EthereumNetwork,
OnlineURL: DefaultURL,
MaxOnlineConnections: DefaultMaxOnlineConnections,
HTTPTimeout: DefaultTimeout,
MaxRetries: DefaultMaxRetries,
MaxSyncConcurrency: DefaultMaxSyncConcurrency,
TipDelay: DefaultTipDelay,
MaxReorgDepth: DefaultMaxReorgDepth,
Data: DefaultDataConfiguration(),
Network: EthereumNetwork,
OnlineURL: DefaultURL,
MaxOnlineConnections: DefaultMaxOnlineConnections,
HTTPTimeout: DefaultTimeout,
MaxRetries: DefaultMaxRetries,
MaxSyncConcurrency: DefaultMaxSyncConcurrency,
TipDelay: DefaultTipDelay,
MaxReorgDepth: DefaultMaxReorgDepth,
EnableRequestInstrumentation: DefaultEnableRequestInstrumentation,
OtelCollectorURL: DefaultOtelCollectorURL,
Data: DefaultDataConfiguration(),
}
}

Expand Down Expand Up @@ -161,6 +163,10 @@ func populateMissingFields(config *Configuration) *Configuration {
config.OnlineURL = DefaultURL
}

if len(config.OtelCollectorURL) == 0 {
config.OtelCollectorURL = DefaultOtelCollectorURL
}

if config.HTTPTimeout == 0 {
config.HTTPTimeout = DefaultTimeout
}
Expand Down
8 changes: 8 additions & 0 deletions configuration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const (
// ETH Defaults
EthereumIDBlockchain = "Ethereum"
EthereumIDNetwork = "Ropsten"
// Tracing Default
DefaultEnableRequestInstrumentation = false
DefaultOtelCollectorURL = "localhost:4317"
)

// Default Configuration Values
Expand Down Expand Up @@ -388,6 +391,11 @@ type Configuration struct {
// on all non-200 responses.
ForceRetry bool `json:"force_retry,omitempty"`

// Turn client tracing on-off for outbound requests.
EnableRequestInstrumentation bool `json:"enable_request_instrumentation"`

// OtelCollectorUrl is URL at which the traces are exported to otel collector".
OtelCollectorURL string `json:"otel_collector_url"`
// MaxSyncConcurrency is the maximum sync concurrency to use while syncing blocks.
// Sync concurrency is managed automatically by the `syncer` package.
MaxSyncConcurrency int64 `json:"max_sync_concurrency"`
Expand Down
17 changes: 12 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ require (
github.com/coinbase/rosetta-sdk-go v0.8.3
github.com/coinbase/rosetta-sdk-go/types v1.0.0
github.com/fatih/color v1.13.0
github.com/google/go-cmp v0.5.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/errors v0.9.1
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.2
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.38.0
go.opentelemetry.io/otel v1.13.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.13.0
go.opentelemetry.io/otel/sdk v1.13.0
go.uber.org/zap v1.21.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/protobuf v1.27.1 // indirect
golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect
golang.org/x/sync v0.1.0
google.golang.org/grpc v1.52.3
)
Loading