Skip to content

Commit

Permalink
add --prometheus-addr option
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Yang <geekya215@gmail.com>
  • Loading branch information
geekya215 committed Aug 8, 2023
1 parent c0b4f46 commit 714cdd7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
52 changes: 32 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,16 @@ 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 && len(*prometheusAddr) == 0 {
*prometheusAddr = DEFAULT_PROMETHEUS_ADDR
}

// 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.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

0 comments on commit 714cdd7

Please sign in to comment.