mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-20 07:40:32 +08:00
fix: add boomer mode(standalone/master/worker)
This commit is contained in:
@@ -37,7 +37,7 @@ var boomCmd = &cobra.Command{
|
|||||||
hrpBoomer.AddOutput(boomer.NewConsoleOutput())
|
hrpBoomer.AddOutput(boomer.NewConsoleOutput())
|
||||||
}
|
}
|
||||||
if prometheusPushgatewayURL != "" {
|
if prometheusPushgatewayURL != "" {
|
||||||
hrpBoomer.AddOutput(boomer.NewPrometheusPusherOutput(prometheusPushgatewayURL, "hrp"))
|
hrpBoomer.AddOutput(boomer.NewPrometheusPusherOutput(prometheusPushgatewayURL, "hrp", hrpBoomer.GetMode()))
|
||||||
}
|
}
|
||||||
hrpBoomer.SetDisableKeepAlive(disableKeepalive)
|
hrpBoomer.SetDisableKeepAlive(disableKeepalive)
|
||||||
hrpBoomer.SetDisableCompression(disableCompression)
|
hrpBoomer.SetDisableCompression(disableCompression)
|
||||||
|
|||||||
@@ -7,11 +7,26 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Mode is the running mode of boomer, both standalone and distributed are supported.
|
||||||
|
type Mode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DistributedMasterMode requires being connected by each worker.
|
||||||
|
DistributedMasterMode Mode = iota
|
||||||
|
// DistributedWorkerMode requires connecting to a master.
|
||||||
|
DistributedWorkerMode
|
||||||
|
// StandaloneMode will run without a master.
|
||||||
|
StandaloneMode
|
||||||
|
)
|
||||||
|
|
||||||
// A Boomer is used to run tasks.
|
// A Boomer is used to run tasks.
|
||||||
type Boomer struct {
|
type Boomer struct {
|
||||||
|
mode Mode
|
||||||
|
|
||||||
localRunner *localRunner
|
localRunner *localRunner
|
||||||
|
|
||||||
cpuProfile string
|
cpuProfile string
|
||||||
@@ -24,9 +39,39 @@ type Boomer struct {
|
|||||||
disableCompression bool
|
disableCompression bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMode only accepts boomer.DistributedMasterMode、boomer.DistributedWorkerMode and boomer.StandaloneMode.
|
||||||
|
func (b *Boomer) SetMode(mode Mode) {
|
||||||
|
switch mode {
|
||||||
|
case DistributedMasterMode:
|
||||||
|
b.mode = DistributedMasterMode
|
||||||
|
case DistributedWorkerMode:
|
||||||
|
b.mode = DistributedWorkerMode
|
||||||
|
case StandaloneMode:
|
||||||
|
b.mode = StandaloneMode
|
||||||
|
default:
|
||||||
|
log.Error().Err(errors.New("Invalid mode, ignored!"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMode returns boomer operating mode
|
||||||
|
func (b *Boomer) GetMode() string {
|
||||||
|
switch b.mode {
|
||||||
|
case DistributedMasterMode:
|
||||||
|
return "master"
|
||||||
|
case DistributedWorkerMode:
|
||||||
|
return "worker"
|
||||||
|
case StandaloneMode:
|
||||||
|
return "standalone"
|
||||||
|
default:
|
||||||
|
log.Error().Err(errors.New("Invalid mode, ignored!"))
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewStandaloneBoomer returns a new Boomer, which can run without master.
|
// NewStandaloneBoomer returns a new Boomer, which can run without master.
|
||||||
func NewStandaloneBoomer(spawnCount int, spawnRate float64) *Boomer {
|
func NewStandaloneBoomer(spawnCount int, spawnRate float64) *Boomer {
|
||||||
return &Boomer{
|
return &Boomer{
|
||||||
|
mode: StandaloneMode,
|
||||||
localRunner: newLocalRunner(spawnCount, spawnRate),
|
localRunner: newLocalRunner(spawnCount, spawnRate),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -471,10 +471,12 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewPrometheusPusherOutput returns a PrometheusPusherOutput.
|
// NewPrometheusPusherOutput returns a PrometheusPusherOutput.
|
||||||
func NewPrometheusPusherOutput(gatewayURL, jobName string) *PrometheusPusherOutput {
|
func NewPrometheusPusherOutput(gatewayURL, jobName string, mode string) *PrometheusPusherOutput {
|
||||||
nodeUUID, _ := uuid.NewUUID()
|
nodeUUID, _ := uuid.NewUUID()
|
||||||
return &PrometheusPusherOutput{
|
return &PrometheusPusherOutput{
|
||||||
pusher: push.New(gatewayURL, jobName).Grouping("instance", nodeUUID.String()),
|
pusher: push.New(gatewayURL, jobName).
|
||||||
|
Grouping("instance", nodeUUID.String()).
|
||||||
|
Grouping("mode", mode),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user