Skip to content

Commit

Permalink
chore: introduces constants for tracer push configs environment varia…
Browse files Browse the repository at this point in the history
…ble names (manual backport #1324) (#1323)

Introduced constants for the tracer push configuration environment
variables to reduce errors when setting and reading these variables in
the code, particularly in downstream repositories.

Manual backport of
#1324
  • Loading branch information
staheri14 authored Apr 24, 2024
1 parent a877076 commit a1bcb0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 13 additions & 5 deletions pkg/trace/local_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import (
"github.com/tendermint/tendermint/libs/log"
)

const (
PushBucketName = "TRACE_PUSH_BUCKET_NAME"
PushRegion = "TRACE_PUSH_REGION"
PushAccessKey = "TRACE_PUSH_ACCESS_KEY"
PushKey = "TRACE_PUSH_SECRET_KEY"
PushDelay = "TRACE_PUSH_DELAY"
)

// Event wraps some trace data with metadata that dictates the table and things
// like the chainID and nodeID.
type Event[T any] struct {
Expand Down Expand Up @@ -109,11 +117,11 @@ func NewLocalTracer(cfg *config.Config, logger log.Logger, chainID, nodeID strin

// GetPushConfigFromEnv reads the required environment variables to push trace
func GetPushConfigFromEnv() (S3Config, error) {
bucketName := os.Getenv("TRACE_PUSH_BUCKET_NAME")
region := os.Getenv("TRACE_PUSH_REGION")
accessKey := os.Getenv("TRACE_PUSH_ACCESS_KEY")
secretKey := os.Getenv("TRACE_PUSH_SECRET_KEY")
pushDelay, err := strconv.ParseInt(os.Getenv("TRACE_PUSH_DELAY"), 10, 64)
bucketName := os.Getenv(PushBucketName)
region := os.Getenv(PushRegion)
accessKey := os.Getenv(PushAccessKey)
secretKey := os.Getenv(PushKey)
pushDelay, err := strconv.ParseInt(os.Getenv(PushDelay), 10, 64)
if err != nil {
return S3Config{}, err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/trace/local_tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ func TestLocalTracerServerPull(t *testing.T) {

// TestReadPushConfigFromConfigFile tests reading the push config from the environment variables.
func TestReadPushConfigFromEnvVars(t *testing.T) {
os.Setenv("TRACE_PUSH_BUCKET_NAME", "bucket")
os.Setenv("TRACE_PUSH_REGION", "region")
os.Setenv("TRACE_PUSH_ACCESS_KEY", "access")
os.Setenv("TRACE_PUSH_SECRET_KEY", "secret")
os.Setenv("TRACE_PUSH_DELAY", "10")
os.Setenv(PushBucketName, "bucket")
os.Setenv(PushRegion, "region")
os.Setenv(PushAccessKey, "access")
os.Setenv(PushKey, "secret")
os.Setenv(PushDelay, "10")

lt := setupLocalTracer(t, 0)
require.Equal(t, "bucket", lt.s3Config.BucketName)
Expand Down

0 comments on commit a1bcb0d

Please sign in to comment.