Skip to content

Commit

Permalink
internal/cli/server: fix flag behaviour (#529)
Browse files Browse the repository at this point in the history
* remove setting maxpeers to 0 for nodiscover flag

* set default prometheus and open-collector endpoint

* skip building grpc address from pprof address and port

* fix: linters

* fix and improve tests

* use loopback address for prometheus and open-collector endpoint

* add logs for prometheus and open-collector setup

* updated the script to handle prometheus-addr

* updated builder/files/config.toml

Co-authored-by: Pratik Patil <pratikspatil024@gmail.com>
  • Loading branch information
manav2401 and pratikspatil024 committed Sep 27, 2022
1 parent 0969781 commit ce69e71
Show file tree
Hide file tree
Showing 6 changed files with 716 additions and 143 deletions.
4 changes: 2 additions & 2 deletions builder/files/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ syncmode = "full"
[telemetry]
metrics = true
# expensive = false
prometheus-addr = "127.0.0.1:7071"
# opencollector-endpoint = ""
# prometheus-addr = "127.0.0.1:7071"
# opencollector-endpoint = "127.0.0.1:4317"
# [telemetry.influx]
# influxdb = false
# endpoint = ""
Expand Down
7 changes: 3 additions & 4 deletions internal/cli/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ func DefaultConfig() *Config {
Telemetry: &TelemetryConfig{
Enabled: false,
Expensive: false,
PrometheusAddr: "",
OpenCollectorEndpoint: "",
PrometheusAddr: "127.0.0.1:7071",
OpenCollectorEndpoint: "127.0.0.1:4317",
InfluxDB: &InfluxDBConfig{
V1Enabled: false,
Endpoint: "",
Expand Down Expand Up @@ -991,8 +991,7 @@ func (c *Config) buildNode() (*node.Config, error) {
}

if c.P2P.NoDiscover {
// Disable networking, for now, we will not even allow incomming connections
cfg.P2P.MaxPeers = 0
// Disable peer discovery
cfg.P2P.NoDiscovery = true
}

Expand Down
151 changes: 16 additions & 135 deletions internal/cli/server/config_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (
"time"

"github.com/stretchr/testify/assert"

"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/params"
)

func TestConfigLegacy(t *testing.T) {
Expand All @@ -17,139 +14,23 @@ func TestConfigLegacy(t *testing.T) {
expectedConfig, err := readLegacyConfig(path)
assert.NoError(t, err)

testConfig := &Config{
Chain: "mainnet",
Identity: Hostname(),
RequiredBlocks: map[string]string{
"a": "b",
},
LogLevel: "INFO",
DataDir: "./data",
P2P: &P2PConfig{
MaxPeers: 30,
MaxPendPeers: 50,
Bind: "0.0.0.0",
Port: 30303,
NoDiscover: false,
NAT: "any",
Discovery: &P2PDiscovery{
V5Enabled: false,
Bootnodes: []string{},
BootnodesV4: []string{},
BootnodesV5: []string{},
StaticNodes: []string{},
TrustedNodes: []string{},
DNS: []string{},
},
},
Heimdall: &HeimdallConfig{
URL: "http://localhost:1317",
Without: false,
},
SyncMode: "full",
GcMode: "full",
Snapshot: true,
TxPool: &TxPoolConfig{
Locals: []string{},
NoLocals: false,
Journal: "transactions.rlp",
Rejournal: 1 * time.Hour,
PriceLimit: 30000000000,
PriceBump: 10,
AccountSlots: 16,
GlobalSlots: 32768,
AccountQueue: 16,
GlobalQueue: 32768,
LifeTime: 1 * time.Second,
},
Sealer: &SealerConfig{
Enabled: false,
Etherbase: "",
GasCeil: 30000000,
GasPrice: big.NewInt(1 * params.GWei),
ExtraData: "",
},
Gpo: &GpoConfig{
Blocks: 20,
Percentile: 60,
MaxPrice: big.NewInt(5000 * params.GWei),
IgnorePrice: big.NewInt(4),
},
JsonRPC: &JsonRPCConfig{
IPCDisable: false,
IPCPath: "",
GasCap: ethconfig.Defaults.RPCGasCap,
TxFeeCap: ethconfig.Defaults.RPCTxFeeCap,
Http: &APIConfig{
Enabled: false,
Port: 8545,
Prefix: "",
Host: "localhost",
API: []string{"eth", "net", "web3", "txpool", "bor"},
Cors: []string{"localhost"},
VHost: []string{"localhost"},
},
Ws: &APIConfig{
Enabled: false,
Port: 8546,
Prefix: "",
Host: "localhost",
API: []string{"net", "web3"},
Cors: []string{"localhost"},
VHost: []string{"localhost"},
},
Graphql: &APIConfig{
Enabled: false,
Cors: []string{"localhost"},
VHost: []string{"localhost"},
},
},
Ethstats: "",
Telemetry: &TelemetryConfig{
Enabled: false,
Expensive: false,
PrometheusAddr: "",
OpenCollectorEndpoint: "",
InfluxDB: &InfluxDBConfig{
V1Enabled: false,
Endpoint: "",
Database: "",
Username: "",
Password: "",
Tags: map[string]string{},
V2Enabled: false,
Token: "",
Bucket: "",
Organization: "",
},
},
Cache: &CacheConfig{
Cache: 1024,
PercDatabase: 50,
PercTrie: 15,
PercGc: 25,
PercSnapshot: 10,
Journal: "triecache",
Rejournal: 1 * time.Second,
NoPrefetch: false,
Preimages: false,
TxLookupLimit: 2350000,
},
Accounts: &AccountsConfig{
Unlock: []string{},
PasswordFile: "",
AllowInsecureUnlock: false,
UseLightweightKDF: false,
DisableBorWallet: true,
},
GRPC: &GRPCConfig{
Addr: ":3131",
},
Developer: &DeveloperConfig{
Enabled: false,
Period: 0,
},
testConfig := DefaultConfig()

testConfig.DataDir = "./data"
testConfig.Snapshot = false
testConfig.RequiredBlocks = map[string]string{
"31000000": "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e",
"32000000": "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68",
}
testConfig.P2P.MaxPeers = 30
testConfig.TxPool.Locals = []string{}
testConfig.TxPool.LifeTime = time.Second
testConfig.Sealer.Enabled = true
testConfig.Sealer.GasCeil = 30000000
testConfig.Sealer.GasPrice = big.NewInt(1000000000)
testConfig.Gpo.IgnorePrice = big.NewInt(4)
testConfig.Cache.Cache = 1024
testConfig.Cache.Rejournal = time.Second

assert.Equal(t, expectedConfig, testConfig)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ func (s *Server) setupMetrics(config *TelemetryConfig, serviceName string) error
}
}()

log.Info("Enabling metrics export to prometheus", "path", fmt.Sprintf("http://%s/debug/metrics/prometheus", config.PrometheusAddr))

}

if config.OpenCollectorEndpoint != "" {
Expand Down Expand Up @@ -322,6 +324,8 @@ func (s *Server) setupMetrics(config *TelemetryConfig, serviceName string) error

// set the tracer
s.tracer = tracerProvider

log.Info("Open collector tracing started", "address", config.OpenCollectorEndpoint)
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions internal/cli/server/testdata/test.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
datadir = "./data"
snapshot = false

["eth.requiredblocks"]
a = "b"
"31000000" = "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e"
"32000000" = "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68"

[p2p]
maxpeers = 30
Expand All @@ -11,7 +13,7 @@ locals = []
lifetime = "1s"

[miner]
mine = false
mine = true
gaslimit = 30000000
gasprice = "1000000000"

Expand Down
Loading

0 comments on commit ce69e71

Please sign in to comment.