From e10afb386109910f90458d6f20f6358c50cad58b Mon Sep 17 00:00:00 2001 From: Sanaz Taheri <35961250+staheri14@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:22:46 -0400 Subject: [PATCH] chore: introduces constants for tracer push configs environment variable names (#1324) 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. --- pkg/trace/local_tracer.go | 18 +++++++++++++----- pkg/trace/local_tracer_test.go | 10 +++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pkg/trace/local_tracer.go b/pkg/trace/local_tracer.go index d8e85b634f..76d44af502 100644 --- a/pkg/trace/local_tracer.go +++ b/pkg/trace/local_tracer.go @@ -13,6 +13,14 @@ import ( "github.com/cometbft/cometbft/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 { @@ -108,11 +116,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 } diff --git a/pkg/trace/local_tracer_test.go b/pkg/trace/local_tracer_test.go index 571e11e6bd..3cb69ad2d3 100644 --- a/pkg/trace/local_tracer_test.go +++ b/pkg/trace/local_tracer_test.go @@ -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)