aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--attack_result.go17
-rw-r--r--environment.go46
-rw-r--r--http_target.go31
-rw-r--r--run_request.go8
-rw-r--r--run_response.go12
-rw-r--r--target.go14
-rw-r--r--trunks.go7
-rw-r--r--websocket_target.go15
8 files changed, 79 insertions, 71 deletions
diff --git a/attack_result.go b/attack_result.go
index f2cc132..544e886 100644
--- a/attack_result.go
+++ b/attack_result.go
@@ -30,19 +30,20 @@ const (
// AttackResult represent the output from load testing.
//
type AttackResult struct {
- mtx sync.Mutex
+ fout *os.File
+ encoder vegeta.Encoder
+ metrics *vegeta.Metrics
+ hist *vegeta.Histogram
TargetID string // ID of Target.
HttpTargetID string // ID of HTTP target which own the result.
Name string // Name of output file without path.
- TextReport []byte // TextReport the result reported as text.
- HistReport []byte // HistReport the result reported as histogram text.
+ fullpath string
+
+ TextReport []byte // TextReport the result reported as text.
+ HistReport []byte // HistReport the result reported as histogram text.
- fullpath string
- fout *os.File
- encoder vegeta.Encoder
- metrics *vegeta.Metrics
- hist *vegeta.Histogram
+ mtx sync.Mutex
}
//
diff --git a/environment.go b/environment.go
index 1c23109..6b7815c 100644
--- a/environment.go
+++ b/environment.go
@@ -16,24 +16,32 @@ import (
// Environment contains global configuration for load testing.
//
type Environment struct {
+ // AttackRunning will be set to non-nil if there is a load
+ // testing currently running.
+ AttackRunning *RunRequest
+
// ListenAddress is the address and port where Trunks HTTP web
// will run.
// If its emtpy, it will set to DefaultListenAddress.
ListenAddress string `ini:"trunks::listen_address"`
+ websocketListenAddress string
+
+ // ResultsDir is the path where the output of load testing will be
+ // stored.
+ // This field is optional, if its empty it will be set to the working
+ // directory where the program is running.
+ ResultsDir string `ini:"trunks:results:dir"`
+
+ // ResultsSuffix define custom string to add to the file name to
+ // uniquely identify results on each run.
+ ResultsSuffix string `ini:"trunks:result:suffix"`
+
// WebSocketListenPort is the port number where Trunks WebSocket API
// will run.
// If its empty, it will set to DefaultWebSocketListenPort.
WebSocketListenPort int
- // MaxAttackDuration define the maximum duration for an attack to be
- // run on each target.
- // The purpose of this option is to prevent client to attack service
- // and bringing it down.
- // This field is optional, default to DefaultMaxAttackDuration if its
- // zero.
- MaxAttackDuration time.Duration `ini:"trunks::max_attack_duration"`
-
// MaxAttackRate define the maximum AttackRate can be set by client.
// The purpose of this option is to prevent client to set attack rate
// which may bring down the service to be tested.
@@ -41,21 +49,15 @@ type Environment struct {
// zero.
MaxAttackRate int `ini:"trunks::max_attack_rate"`
- // ResultsDir is the path where the output of load testing will be
- // stored.
- // This field is optional, if its empty it will be set to the working
- // directory where the program is running.
- ResultsDir string `ini:"trunks:results:dir"`
-
- // ResultsSuffix define custom string to add to the file name to
- // uniquely identify results on each run.
- ResultsSuffix string `ini:"trunks:result:suffix"`
+ // MaxAttackDuration define the maximum duration for an attack to be
+ // run on each target.
+ // The purpose of this option is to prevent client to attack service
+ // and bringing it down.
+ // This field is optional, default to DefaultMaxAttackDuration if its
+ // zero.
+ MaxAttackDuration time.Duration `ini:"trunks::max_attack_duration"`
- // AttackRunning will be set to non-nil if there is a load
- // testing currently running.
- AttackRunning *RunRequest
- mtx sync.Mutex
- websocketListenAddress string
+ mtx sync.Mutex
}
func (env *Environment) init() (err error) {
diff --git a/http_target.go b/http_target.go
index b648072..1b0d6e8 100644
--- a/http_target.go
+++ b/http_target.go
@@ -39,29 +39,28 @@ type HttpAttackHandler func(rr *RunRequest) vegeta.Targeter
type HttpPreAttackHandler func(rr *RunRequest)
type HttpTarget struct {
- // Name of target, required.
- Name string
- Hint string // Description about what this HTTP target is doing.
+ Params KeyFormInput
+ ConvertParams HttpConvertParams `json:"-"`
+
+ Headers KeyFormInput
+
+ Run HttpRunHandler `json:"-"`
+ PreAttack HttpPreAttackHandler `json:"-"`
+ Attack HttpAttackHandler `json:"-"`
// ID of target, optional.
// If its empty, it will generated using value from Name.
ID string
- Method libhttp.RequestMethod
- Path string
- RequestType libhttp.RequestType
- Headers KeyFormInput
- Params KeyFormInput
-
- Run HttpRunHandler `json:"-"`
- ConvertParams HttpConvertParams `json:"-"`
+ Name string // Name of target, required.
+ Hint string // Description about what this HTTP target is doing.
+ Path string
- Attack HttpAttackHandler `json:"-"`
- PreAttack HttpPreAttackHandler `json:"-"`
- AttackLocker sync.Mutex `json:"-"` // Use this inside the Attack to lock resource.
+ Results []*AttackResult // Results contains list of load testing output.
+ RequestType libhttp.RequestType
+ Method libhttp.RequestMethod
- // Results contains list of load testing output.
- Results []*AttackResult
+ AttackLocker sync.Mutex `json:"-"` // Use this inside the Attack to lock resource.
// AllowAttack if its true the "Attack" button will be showed on user
// interface and client will be allowed to run load testing on this
diff --git a/run_request.go b/run_request.go
index 174781d..78c7b12 100644
--- a/run_request.go
+++ b/run_request.go
@@ -16,11 +16,13 @@ import (
// RunRequest define the request to run HTTP or WebSocket target.
//
type RunRequest struct {
- Locker sync.Mutex `json:"-"`
+ result *AttackResult
+
Target Target
- HttpTarget HttpTarget
WebSocketTarget WebSocketTarget
- result *AttackResult
+ HttpTarget HttpTarget
+
+ Locker sync.Mutex `json:"-"`
}
//
diff --git a/run_response.go b/run_response.go
index c916801..aeeda2c 100644
--- a/run_response.go
+++ b/run_response.go
@@ -18,12 +18,14 @@ import (
// WebSocket target.
//
type RunResponse struct {
- DumpRequest []byte
- DumpResponse []byte
- ResponseStatus string
+ ResponseStatus string
+ ResponseType string
+
+ DumpRequest []byte
+ DumpResponse []byte
+ ResponseBody []byte
+
ResponseStatusCode int
- ResponseType string
- ResponseBody []byte
}
//
diff --git a/target.go b/target.go
index da4382c..3cb095e 100644
--- a/target.go
+++ b/target.go
@@ -14,22 +14,24 @@ import (
// Target contains group of HttpTarget that can be tested by Trunks.
//
type Target struct {
+ // HttpClient that can be used for running HttpTarget.
+ HttpClient *libhttp.Client `json:"-"`
+
+ Opts *AttackOptions
+ Vars KeyFormInput
+
ID string
Name string
- Hint string
// BaseUrl contains the target address that serve the service to
// be tested.
// This field is required.
BaseUrl string
- Opts *AttackOptions
- Vars KeyFormInput
+ Hint string
+
HttpTargets []*HttpTarget
WebSocketTargets []*WebSocketTarget
-
- // HttpClient that can be used for running HttpTarget.
- HttpClient *libhttp.Client `json:"-"`
}
func (target *Target) init() (err error) {
diff --git a/trunks.go b/trunks.go
index 2e5bcd5..34886c1 100644
--- a/trunks.go
+++ b/trunks.go
@@ -47,13 +47,14 @@ const (
//
type Trunks struct {
Env *Environment
- Httpd *libhttp.Server // The HTTP server.
- Wsd *websocket.Server // The WebSocket server.
+ Httpd *libhttp.Server
+ Wsd *websocket.Server
- targets []*Target
attackq chan *RunRequest
cancelq chan bool
errq chan error
+
+ targets []*Target
}
//
diff --git a/websocket_target.go b/websocket_target.go
index 394d483..6bf68e5 100644
--- a/websocket_target.go
+++ b/websocket_target.go
@@ -16,14 +16,6 @@ type WebSocketRunHandler func(rr *RunRequest) (interface{}, error)
// WebSocketTarget define the target to test WebSocket service.
//
type WebSocketTarget struct {
- // Name of target, required.
- Name string
- Hint string // Description about what this WebSocket target is doing.
-
- // ID of target, optional.
- // If its empty, it will generated by normalized the value of Name.
- ID string
-
Headers KeyFormInput
// Params contains additional parameters to be passed when running
@@ -35,6 +27,13 @@ type WebSocketTarget struct {
Params KeyFormInput
Run WebSocketRunHandler `json:"-"`
+
+ // ID of target, optional.
+ // If its empty, it will generated by normalized the value of Name.
+ ID string
+
+ Name string // Name of target, required.
+ Hint string // Description about what this WebSocket target is doing.
}
func (wst *WebSocketTarget) init() (err error) {