Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --prometheus-addr option #295

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions cmd/tape/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ import (
)

const (
loglevel = "TAPE_LOGLEVEL"
logfilename = "Tape.log"
loglevel = "TAPE_LOGLEVEL"
logfilename = "Tape.log"
DEFAULT_PROMETHEUS_ADDR = ":8080"
)

var (
app = kingpin.New("tape", "A performance test tool for Hyperledger Fabric")

con = app.Flag("config", "Path to config file").Short('c').String()
num = app.Flag("number", "Number of tx for shot").Short('n').Int()
rate = app.Flag("rate", "[Optional] Creates tx rate, default 0 as unlimited").Default("0").Float64()
burst = app.Flag("burst", "[Optional] Burst size for Tape, should bigger than rate").Default("1000").Int()
signerNumber = app.Flag("signers", "[Optional] signer parallel Number for Tape, default as 5").Default("5").Int()
parallelNumber = app.Flag("parallel", "[Optional] parallel Number for Tape, default as 1").Default("1").Int()
prometheus = app.Flag("prometheus", "[Optional] prometheus enable or not").Default("false").Bool()
con = app.Flag("config", "Path to config file").Short('c').String()
num = app.Flag("number", "Number of tx for shot").Short('n').Int()
rate = app.Flag("rate", "[Optional] Creates tx rate, default 0 as unlimited").Default("0").Float64()
burst = app.Flag("burst", "[Optional] Burst size for Tape, should bigger than rate").Default("1000").Int()
signerNumber = app.Flag("signers", "[Optional] signer parallel Number for Tape, default as 5").Default("5").Int()
parallelNumber = app.Flag("parallel", "[Optional] parallel Number for Tape, default as 1").Default("1").Int()
enablePrometheus = app.Flag("prometheus", "[Optional] prometheus enable or not").Default("false").Bool()
prometheusAddr = app.Flag("prometheus-addr", "[Optional] prometheus address, default as :8080").String()

run = app.Command("run", "Start the tape program").Default()

Expand Down Expand Up @@ -63,20 +65,20 @@ func main() {
case version.FullCommand():
fmt.Println(cmdImpl.GetVersionInfo())
case commitOnly.FullCommand():
checkArgs(rate, burst, signerNumber, parallelNumber, *con, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *prometheus, logger, infra.COMMIT)
checkArgs(rate, burst, signerNumber, parallelNumber, *con, *enablePrometheus, prometheusAddr, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *enablePrometheus, *prometheusAddr, logger, infra.COMMIT)
case endorsementOnly.FullCommand():
checkArgs(rate, burst, signerNumber, parallelNumber, *con, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *prometheus, logger, infra.ENDORSEMENT)
checkArgs(rate, burst, signerNumber, parallelNumber, *con, *enablePrometheus, prometheusAddr, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *enablePrometheus, *prometheusAddr, logger, infra.ENDORSEMENT)
case run.FullCommand():
checkArgs(rate, burst, signerNumber, parallelNumber, *con, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *prometheus, logger, infra.FULLPROCESS)
checkArgs(rate, burst, signerNumber, parallelNumber, *con, *enablePrometheus, prometheusAddr, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *enablePrometheus, *prometheusAddr, logger, infra.FULLPROCESS)
case trafficOnly.FullCommand():
checkArgs(rate, burst, signerNumber, parallelNumber, *con, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *prometheus, logger, infra.TRAFFIC)
checkArgs(rate, burst, signerNumber, parallelNumber, *con, *enablePrometheus, prometheusAddr, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *enablePrometheus, *prometheusAddr, logger, infra.TRAFFIC)
case observerOnly.FullCommand():
checkArgs(rate, burst, signerNumber, parallelNumber, *con, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *prometheus, logger, infra.OBSERVER)
checkArgs(rate, burst, signerNumber, parallelNumber, *con, *enablePrometheus, prometheusAddr, logger)
err = cmdImpl.Process(*con, *num, *burst, *signerNumber, *parallelNumber, *rate, *enablePrometheus, *prometheusAddr, logger, infra.OBSERVER)
default:
err = errors.Errorf("invalid command: %s", fullCmd)
}
Expand All @@ -89,7 +91,7 @@ func main() {
os.Exit(0)
}

func checkArgs(rate *float64, burst, signerNumber, parallel *int, con string, logger *log.Logger) {
func checkArgs(rate *float64, burst, signerNumber, parallel *int, con string, enablePrometheus bool, prometheusAddr *string, logger *log.Logger) {
if len(con) == 0 {
os.Stderr.WriteString("tape: error: required flag --config not provided, try --help")
os.Exit(1)
Expand All @@ -115,6 +117,20 @@ func checkArgs(rate *float64, burst, signerNumber, parallel *int, con string, lo
fmt.Printf("As rate %d is bigger than burst %d, real rate is burst\n", int64(*rate), int64(*burst))
}

// enable prometheus but not provide --prometheus-addr option, use default prometheus address ":8080"
if enablePrometheus {
if len(*prometheusAddr) == 0 {
*prometheusAddr = DEFAULT_PROMETHEUS_ADDR
}
logger.Infof("prometheus running at %s\n", *prometheusAddr)
}

// not enable prometheus but provide --prometheus-addr option, show help message
if !enablePrometheus && len(*prometheusAddr) != 0 {
fmt.Printf("You've provided the --prometheus-addr option to specify a Prometheus address, but you haven't enabled Prometheus using --prometheus option\n")
logger.Warnf("prometheus is not available at %s, because --prometheus option is not provided\n", *prometheusAddr)
}

geekya215 marked this conversation as resolved.
Show resolved Hide resolved
logger.Infof("Will use rate %f as send rate\n", *rate)
logger.Infof("Will use %d as burst\n", burst)
}
8 changes: 4 additions & 4 deletions pkg/infra/cmdImpl/fullProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
log "github.com/sirupsen/logrus"
)

func Process(configPath string, num int, burst, signerNumber, parallel int, rate float64, prometheusOpt bool, logger *log.Logger, processmod int) error {
func Process(configPath string, num int, burst, signerNumber, parallel int, rate float64, enablePrometheus bool, prometheusAddr string, logger *log.Logger, processmod int) error {
/*** signal ***/
c := make(chan os.Signal, 1)

Expand Down Expand Up @@ -54,11 +54,11 @@ func Process(configPath string, num int, burst, signerNumber, parallel int, rate

var transactionlatency, readlatency *prometheus.SummaryVec
/*** start prometheus ***/
if prometheusOpt {
if enablePrometheus {
go func() {
fmt.Println("start prometheus")
http.Handle("/metrics", promhttp.Handler())
server := &http.Server{Addr: ":8080", Handler: nil}
server := &http.Server{Addr: prometheusAddr, Handler: nil}
err = server.ListenAndServe()
if err != nil {
cmdConfig.ErrorCh <- err
Expand Down Expand Up @@ -86,7 +86,7 @@ func Process(configPath string, num int, burst, signerNumber, parallel int, rate
prometheus.MustRegister(transactionlatency)
prometheus.MustRegister(readlatency)

basic.InitLatencyMap(transactionlatency, readlatency, processmod, prometheusOpt)
basic.InitLatencyMap(transactionlatency, readlatency, processmod, enablePrometheus)
}

/*** start workers ***/
Expand Down
Loading