Skip to content

Commit

Permalink
e2e: add manifest fields to enable Prometheus on nodes (#313)
Browse files Browse the repository at this point in the history
* Add Prometheus and PrometheusListenAddr flags

* Add Prometheus flag at root level, for all nodes

* Add comment

* Add PrometheusProxyPort; remove PrometheusListenAddr

* Update startup log message

* Update startup log message

* Don't print the whole line in docker template

* Remove flag from ManifestNode

* Do not generate PrometheusProxyPort if config is disabled
  • Loading branch information
hvanz committed Feb 24, 2023
1 parent d227550 commit a95a1df
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 32 deletions.
6 changes: 6 additions & 0 deletions test/e2e/pkg/infra/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ services:
ports:
- 26656
- {{ if .ProxyPort }}{{ .ProxyPort }}:{{ end }}26657
{{- if .PrometheusProxyPort }}
- {{ .PrometheusProxyPort }}:26660
{{- end }}
- 6060
volumes:
- ./{{ .Name }}:/cometbft
Expand All @@ -86,6 +89,9 @@ services:
ports:
- 26656
- {{ if .ProxyPort }}{{ .ProxyPort }}:{{ end }}26657
{{- if .PrometheusProxyPort }}
- {{ .PrometheusProxyPort }}:26660
{{- end }}
- 6060
volumes:
- ./{{ .Name }}:/cometbft
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/pkg/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ type Manifest struct {
LoadTxSizeBytes int `toml:"load_tx_size_bytes"`
LoadTxBatchSize int `toml:"load_tx_batch_size"`
LoadTxConnections int `toml:"load_tx_connections"`

// Enable or disable Prometheus metrics on all nodes.
// Defaults to false (disabled).
Prometheus bool `toml:"prometheus"`
}

// ManifestNode represents a node in a testnet manifest.
Expand Down
79 changes: 48 additions & 31 deletions test/e2e/pkg/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
)

const (
randomSeed int64 = 2308084734268
proxyPortFirst uint32 = 5701
randomSeed int64 = 2308084734268
proxyPortFirst uint32 = 5701
prometheusProxyPortFirst uint32 = 6701

defaultBatchSize = 2
defaultConnections = 1
Expand Down Expand Up @@ -79,33 +80,34 @@ type Testnet struct {
ProcessProposalDelay time.Duration
CheckTxDelay time.Duration
UpgradeVersion string
Prometheus bool
}

// Node represents a CometBFT node in a testnet.
type Node struct {
Name string
Version string
Testnet *Testnet
Mode Mode
PrivvalKey crypto.PrivKey
NodeKey crypto.PrivKey
IP net.IP
ProxyPort uint32
StartAt int64
BlockSync string
StateSync bool
Database string
ABCIProtocol Protocol
PrivvalProtocol Protocol
PersistInterval uint64
SnapshotInterval uint64
RetainBlocks uint64
Seeds []*Node
PersistentPeers []*Node
Perturbations []Perturbation

// SendNoLoad determines if the e2e test should send load to this node.
SendNoLoad bool
Name string
Version string
Testnet *Testnet
Mode Mode
PrivvalKey crypto.PrivKey
NodeKey crypto.PrivKey
IP net.IP
ProxyPort uint32
StartAt int64
BlockSync string
StateSync bool
Database string
ABCIProtocol Protocol
PrivvalProtocol Protocol
PersistInterval uint64
SnapshotInterval uint64
RetainBlocks uint64
Seeds []*Node
PersistentPeers []*Node
Perturbations []Perturbation
SendNoLoad bool
Prometheus bool
PrometheusProxyPort uint32
}

// LoadTestnet loads a testnet from a manifest file, using the filename to
Expand All @@ -117,6 +119,7 @@ func LoadTestnet(manifest Manifest, fname string, ifd InfrastructureData) (*Test
dir := strings.TrimSuffix(fname, filepath.Ext(fname))
keyGen := newKeyGenerator(randomSeed)
proxyPortGen := newPortGenerator(proxyPortFirst)
prometheusProxyPortGen := newPortGenerator(prometheusProxyPortFirst)
_, ipNet, err := net.ParseCIDR(ifd.Network)
if err != nil {
return nil, fmt.Errorf("invalid IP network address %q: %w", ifd.Network, err)
Expand All @@ -141,6 +144,7 @@ func LoadTestnet(manifest Manifest, fname string, ifd InfrastructureData) (*Test
ProcessProposalDelay: manifest.ProcessProposalDelay,
CheckTxDelay: manifest.CheckTxDelay,
UpgradeVersion: manifest.UpgradeVersion,
Prometheus: manifest.Prometheus,
}
if len(manifest.KeyType) != 0 {
testnet.KeyType = manifest.KeyType
Expand Down Expand Up @@ -202,6 +206,7 @@ func LoadTestnet(manifest Manifest, fname string, ifd InfrastructureData) (*Test
RetainBlocks: nodeManifest.RetainBlocks,
Perturbations: []Perturbation{},
SendNoLoad: nodeManifest.SendNoLoad,
Prometheus: testnet.Prometheus,
}
if node.StartAt == testnet.InitialHeight {
node.StartAt = 0 // normalize to 0 for initial nodes, since code expects this
Expand All @@ -221,6 +226,9 @@ func LoadTestnet(manifest Manifest, fname string, ifd InfrastructureData) (*Test
if nodeManifest.PersistInterval != nil {
node.PersistInterval = *nodeManifest.PersistInterval
}
if node.Prometheus {
node.PrometheusProxyPort = prometheusProxyPortGen.Next()
}
for _, p := range nodeManifest.Perturb {
node.Perturbations = append(node.Perturbations, Perturbation(p))
}
Expand Down Expand Up @@ -327,13 +335,22 @@ func (n Node) Validate(testnet Testnet) error {
if !testnet.IP.Contains(n.IP) {
return fmt.Errorf("node IP %v is not in testnet network %v", n.IP, testnet.IP)
}
if n.ProxyPort > 0 {
if n.ProxyPort <= 1024 {
return fmt.Errorf("local port %v must be >1024", n.ProxyPort)
if n.ProxyPort == n.PrometheusProxyPort {
return fmt.Errorf("node local port %v used also for Prometheus local port", n.ProxyPort)
}
if n.ProxyPort > 0 && n.ProxyPort <= 1024 {
return fmt.Errorf("local port %v must be >1024", n.ProxyPort)
}
if n.PrometheusProxyPort > 0 && n.PrometheusProxyPort <= 1024 {
return fmt.Errorf("local port %v must be >1024", n.PrometheusProxyPort)
}
for _, peer := range testnet.Nodes {
if peer.Name != n.Name && peer.ProxyPort == n.ProxyPort {
return fmt.Errorf("peer %q also has local port %v", peer.Name, n.ProxyPort)
}
for _, peer := range testnet.Nodes {
if peer.Name != n.Name && peer.ProxyPort == n.ProxyPort {
return fmt.Errorf("peer %q also has local port %v", peer.Name, n.ProxyPort)
if n.PrometheusProxyPort > 0 {
if peer.Name != n.Name && peer.PrometheusProxyPort == n.PrometheusProxyPort {
return fmt.Errorf("peer %q also has local port %v", peer.Name, n.PrometheusProxyPort)
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/runner/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ func MakeConfig(node *e2e.Node) (*config.Config, error) {
}
cfg.P2P.PersistentPeers += peer.AddressP2P(true)
}

if node.Prometheus {
cfg.Instrumentation.Prometheus = true
}

return cfg, nil
}

Expand Down
6 changes: 5 additions & 1 deletion test/e2e/runner/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ func Start(testnet *e2e.Testnet) error {
if _, err := waitForNode(node, 0, 15*time.Second); err != nil {
return err
}
logger.Info("start", "msg", log.NewLazySprintf("Node %v up on http://127.0.0.1:%v", node.Name, node.ProxyPort))
if node.PrometheusProxyPort > 0 {
logger.Info("start", "msg", log.NewLazySprintf("Node %v up on http://127.0.0.1:%v; with Prometheus on http://127.0.0.1:%v/metrics", node.Name, node.ProxyPort, node.PrometheusProxyPort))
} else {
logger.Info("start", "msg", log.NewLazySprintf("Node %v up on http://127.0.0.1:%v", node.Name, node.ProxyPort))
}
}

networkHeight := testnet.InitialHeight
Expand Down

0 comments on commit a95a1df

Please sign in to comment.