Skip to content

Commit

Permalink
added service name in config and flags (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
manav2401 authored Nov 17, 2021
1 parent 78ba316 commit 87f9b91
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
12 changes: 12 additions & 0 deletions command/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Config struct {
// Chain is the chain to sync with
Chain string `hcl:"chain,optional"`

// Name, or identity of the node
Name string `hcl:"name,optional"`

// Whitelist is a list of required (block number, hash) pairs to accept
Whitelist map[string]string `hcl:"whitelist,optional"`

Expand Down Expand Up @@ -365,6 +368,7 @@ type AccountsConfig struct {
func DefaultConfig() *Config {
return &Config{
Chain: "mainnet",
Name: Hostname(),
Whitelist: map[string]string{},
LogLevel: "INFO",
DataDir: defaultDataDir(),
Expand Down Expand Up @@ -885,3 +889,11 @@ func defaultDataDir() string {
return filepath.Join(home, ".bor")
}
}

func Hostname() string {
hostname, err := os.Hostname()
if err != nil {
return "bor"
}
return hostname
}
5 changes: 5 additions & 0 deletions command/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func (c *Command) Flags() *flagset.Flagset {
Usage: "Name of the chain to sync",
Value: &c.cliConfig.Chain,
})
f.StringFlag(&flagset.StringFlag{
Name: "name",
Usage: "Name/Identity of the node",
Value: &c.cliConfig.Name,
})
f.StringFlag(&flagset.StringFlag{
Name: "log-level",
Usage: "Set log level for the server",
Expand Down
6 changes: 3 additions & 3 deletions command/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewServer(config *Config) (*Server, error) {
}
}

if err := srv.setupMetrics(config.Telemetry); err != nil {
if err := srv.setupMetrics(config.Telemetry, config.Name); err != nil {
return nil, err
}

Expand All @@ -133,7 +133,7 @@ func (s *Server) Stop() {
}
}

func (s *Server) setupMetrics(config *TelemetryConfig) error {
func (s *Server) setupMetrics(config *TelemetryConfig, serviceName string) error {
metrics.Enabled = config.Enabled
metrics.EnabledExpensive = config.Expensive

Expand Down Expand Up @@ -195,7 +195,7 @@ func (s *Server) setupMetrics(config *TelemetryConfig) error {
res, err := resource.New(ctx,
resource.WithAttributes(
// the service name used to display traces in backends
semconv.ServiceNameKey.String("bor"), // TODO: use the service name from the config
semconv.ServiceNameKey.String(serviceName),
),
)
if err != nil {
Expand Down

0 comments on commit 87f9b91

Please sign in to comment.