Skip to content

Commit

Permalink
e2e: add prometheus flag to Generator CLI (cometbft#563)
Browse files Browse the repository at this point in the history
* Add prometheus flag to CLI

* Fix CLI help message

* Enable prometheus in nightly tests
  • Loading branch information
hvanz authored Mar 23, 2023
1 parent 23389e7 commit 01c0188
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-manual-multiversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# When changing -g, also change the matrix groups above
# Generate multi-version tests with double the quantity of E2E nodes
# based on the current branch as compared to the latest version.
run: ./build/generator -g 5 -m "latest:1,local:2" -d networks/nightly/
run: ./build/generator -g 5 -m "latest:1,local:2" -d networks/nightly/ -p

- name: Run ${{ matrix.p2p }} p2p testnets
working-directory: test/e2e
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Generate testnets
working-directory: test/e2e
# When changing -g, also change the matrix groups above
run: ./build/generator -g 5 -d networks/nightly/
run: ./build/generator -g 5 -d networks/nightly/ -p

- name: Run ${{ matrix.p2p }} p2p testnets
working-directory: test/e2e
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-nightly-34x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Generate testnets
working-directory: test/e2e
# When changing -g, also change the matrix groups above
run: ./build/generator -g 2 -d networks/nightly
run: ./build/generator -g 2 -d networks/nightly -p

- name: Run testnets in group ${{ matrix.group }}
working-directory: test/e2e
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-nightly-37x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Generate testnets
working-directory: test/e2e
# When changing -g, also change the matrix groups above
run: ./build/generator -g 5 -d networks/nightly/
run: ./build/generator -g 5 -d networks/nightly/ -p

- name: Run ${{ matrix.p2p }} p2p testnets
working-directory: test/e2e
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-nightly-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Generate testnets
working-directory: test/e2e
# When changing -g, also change the matrix groups above
run: ./build/generator -g 5 -d networks/nightly/
run: ./build/generator -g 5 -d networks/nightly/ -p

- name: Run ${{ matrix.p2p }} p2p testnets
working-directory: test/e2e
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type generateConfig struct {
randSource *rand.Rand
outputDir string
multiVersion string
prometheus bool
}

// Generate generates random testnets using the given RNG.
Expand Down Expand Up @@ -106,7 +107,7 @@ func Generate(cfg *generateConfig) ([]e2e.Manifest, error) {
}
manifests := []e2e.Manifest{}
for _, opt := range combinations(testnetCombinations) {
manifest, err := generateTestnet(cfg.randSource, opt, upgradeVersion)
manifest, err := generateTestnet(cfg.randSource, opt, upgradeVersion, cfg.prometheus)
if err != nil {
return nil, err
}
Expand All @@ -116,7 +117,7 @@ func Generate(cfg *generateConfig) ([]e2e.Manifest, error) {
}

// generateTestnet generates a single testnet with the given options.
func generateTestnet(r *rand.Rand, opt map[string]interface{}, upgradeVersion string) (e2e.Manifest, error) {
func generateTestnet(r *rand.Rand, opt map[string]interface{}, upgradeVersion string, prometheus bool) (e2e.Manifest, error) {
manifest := e2e.Manifest{
IPv6: ipv6.Choose(r).(bool),
ABCIProtocol: nodeABCIProtocols.Choose(r).(string),
Expand All @@ -127,6 +128,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}, upgradeVersion st
Evidence: evidence.Choose(r).(int),
Nodes: map[string]*e2e.ManifestNode{},
UpgradeVersion: upgradeVersion,
Prometheus: prometheus,
}

switch abciDelays.Choose(r).(string) {
Expand Down
12 changes: 9 additions & 3 deletions test/e2e/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type CLI struct {
func NewCLI() *CLI {
cli := &CLI{}
cli.root = &cobra.Command{
Use: "generator -d dir [-g int] [-m version_weight_csv]",
Use: "generator -d dir [-g int] [-m version_weight_csv] [-p]",
Short: "End-to-end testnet generator",
SilenceUsage: true,
SilenceErrors: true, // we'll output them ourselves in Run()
Expand All @@ -48,7 +48,11 @@ func NewCLI() *CLI {
if err != nil {
return err
}
return cli.generate(dir, groups, multiVersion)
prometheus, err := cmd.Flags().GetBool("prometheus")
if err != nil {
return err
}
return cli.generate(dir, groups, multiVersion, prometheus)
},
}

Expand All @@ -57,12 +61,13 @@ func NewCLI() *CLI {
cli.root.PersistentFlags().StringP("multi-version", "m", "", "Comma-separated list of versions of CometBFT to test in the generated testnets, "+
"or empty to only use this branch's version")
cli.root.PersistentFlags().IntP("groups", "g", 0, "Number of groups")
cli.root.PersistentFlags().BoolP("prometheus", "p", false, "Enable generation of Prometheus metrics on all manifests")

return cli
}

// generate generates manifests in a directory.
func (cli *CLI) generate(dir string, groups int, multiVersion string) error {
func (cli *CLI) generate(dir string, groups int, multiVersion string, prometheus bool) error {
err := os.MkdirAll(dir, 0o755)
if err != nil {
return err
Expand All @@ -71,6 +76,7 @@ func (cli *CLI) generate(dir string, groups int, multiVersion string) error {
cfg := &generateConfig{
randSource: rand.New(rand.NewSource(randomSeed)), //nolint:gosec
multiVersion: multiVersion,
prometheus: prometheus,
}
manifests, err := Generate(cfg)
if err != nil {
Expand Down

0 comments on commit 01c0188

Please sign in to comment.