Skip to content

Commit

Permalink
Merge pull request #17 from probe-lab/fix/traces-port
Browse files Browse the repository at this point in the history
fix: default "" str for trace host and 0 for port
  • Loading branch information
guillaumemichel authored Nov 8, 2024
2 parents 51b94e8 + b2101d2 commit a5e604b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
21 changes: 9 additions & 12 deletions queen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", 5432)
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"),
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 17 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ants

import (
"fmt"
"os"
"strconv"
"time"

"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -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
}

0 comments on commit a5e604b

Please sign in to comment.