From a4611cf981f4e85db46a49ca033206a6ae6c352e Mon Sep 17 00:00:00 2001 From: Steph Samson Date: Fri, 8 Nov 2024 13:47:07 +0700 Subject: [PATCH 1/2] fix: default "" str for trace host and 0 for port --- queen.go | 21 +++++++++------------ util.go | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/queen.go b/queen.go index ffa19f6..63c6cc2 100644 --- a/queen.go +++ b/queen.go @@ -99,31 +99,28 @@ func NewQueen(ctx context.Context, dbConnString string, keysDbPath string, nPort } func getDbClient(ctx context.Context) *db.DBClient { - dbPort, err := strconv.Atoi(os.Getenv("DB_PORT")) + dbPort, err := getEnvInt("DB_PORT", 6667) if err != nil { logger.Errorf("Port must be an integer: %w", err) } - mP, _ := tele.NewMeterProvider() tracesHost, tracesHostSet := os.LookupEnv("TRACES_HOST") if !tracesHostSet { - tracesHost = "0.0.0.0" - } - tracesPort, tracesPortSet := os.LookupEnv("TRACES_PORT") - if !tracesPortSet { - tracesPort = "6667" + tracesHost = "" } - tracesPortAsInt, err := strconv.Atoi(tracesPort) + tracesPort, err := getEnvInt("TRACES_PORT", 0) if err != nil { logger.Errorf("Port must be an integer: %w", err) } - - tP, _ := tele.NewTracerProvider( + tP, err := tele.NewTracerProvider( ctx, tracesHost, - tracesPortAsInt, + tracesPort, ) + if err != nil { + logger.Errorf("new tracer provider: %w", err) + } dbc, err := db.InitDBClient(ctx, &config.Database{ DatabaseHost: os.Getenv("DB_HOST"), @@ -330,7 +327,7 @@ func (q *Queen) persistLiveAntsKeys() { func (q *Queen) routine(ctx context.Context) { networkPeers, err := q.nebulaDB.GetLatestPeerIds(ctx) if err != nil { - logger.Warn("unable to get latest peer ids from Nebula", err) + logger.Warn("unable to get latest peer ids from Nebula ", err) return } diff --git a/util.go b/util.go index cc9a875..45eeb60 100644 --- a/util.go +++ b/util.go @@ -1,6 +1,9 @@ package ants import ( + "fmt" + "os" + "strconv" "time" "github.com/ipfs/go-cid" @@ -53,3 +56,17 @@ func bitstrToBit256(strKey bitstr.Key, padding []byte) bit256.Key { } return bit256.NewKey(bit256Key) } + +func getEnvInt(key string, defaultValue int) (int, error) { + value, exists := os.LookupEnv(key) + if !exists { + return defaultValue, nil + } + + result, err := strconv.Atoi(value) + if err != nil { + return 0, fmt.Errorf("%s must be an int: %w", key, err) + } + + return result, nil +} From b2101d2c86a31d9f440e0b48abb0b66bc1d61ccc Mon Sep 17 00:00:00 2001 From: Steph Samson Date: Fri, 8 Nov 2024 13:49:52 +0700 Subject: [PATCH 2/2] fix: default to 5432 for db port --- queen.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queen.go b/queen.go index 63c6cc2..e2732d9 100644 --- a/queen.go +++ b/queen.go @@ -99,7 +99,7 @@ func NewQueen(ctx context.Context, dbConnString string, keysDbPath string, nPort } func getDbClient(ctx context.Context) *db.DBClient { - dbPort, err := getEnvInt("DB_PORT", 6667) + dbPort, err := getEnvInt("DB_PORT", 5432) if err != nil { logger.Errorf("Port must be an integer: %w", err) }