diff options
| author | Shulhan <ms@kilabit.info> | 2021-03-21 04:30:07 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-03-21 04:30:07 +0700 |
| commit | 05474abb07f73aace79bcf339be8e5619dd4564b (patch) | |
| tree | 6cd71065014161f3f4f95aacb6b0508ce20a216c /run_request.go | |
| parent | 77e3074ccbbb01945e06d5608d34d5f39352500e (diff) | |
| download | gorankusu-05474abb07f73aace79bcf339be8e5619dd4564b.tar.xz | |
all: implement API and interface for attack functionality
When the user click "Attack" it will call the API to run the load testing.
If there is load testing currently, it will return with an error.
On success, the result of load testing will be stored on directory
defined in Environment.ResultsDir with file named
<HttpTarget.ID>.<date_time>.<RPS>x<Duration>s.<ResultsSuffix>.bin
This file contains the vegeta.Results.
Diffstat (limited to 'run_request.go')
| -rw-r--r-- | run_request.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/run_request.go b/run_request.go index 2d06e23..1f72b96 100644 --- a/run_request.go +++ b/run_request.go @@ -4,7 +4,52 @@ package trunks +import ( + "fmt" + "sync" + "time" + + vegeta "github.com/tsenart/vegeta/v12/lib" +) + type RunRequest struct { + Locker sync.Mutex Target *Target HttpTarget *HttpTarget + result *loadTestingResult +} + +func (rr *RunRequest) String() string { + return fmt.Sprintf("Target:%v HttpTarget:%v\n", rr.Target, rr.HttpTarget) +} + +// +// merge the request parameter into original target and HTTP target. +// +func (rr *RunRequest) merge(env *Environment, origTarget *Target, origHttpTarget *HttpTarget) { + if rr.Target.Opts.Duration > 0 && + rr.Target.Opts.Duration <= env.MaxAttackDuration { + origTarget.Opts.Duration = rr.Target.Opts.Duration + } + + if rr.Target.Opts.RatePerSecond > 0 && + rr.Target.Opts.RatePerSecond <= env.MaxAttackRate { + origTarget.Opts.RatePerSecond = rr.Target.Opts.RatePerSecond + origTarget.Opts.ratePerSecond = vegeta.Rate{ + Freq: rr.Target.Opts.RatePerSecond, + Per: time.Second, + } + } + + if rr.Target.Opts.Timeout > 0 && + rr.Target.Opts.Timeout <= DefaultAttackTimeout { + origTarget.Opts.Timeout = rr.Target.Opts.Timeout + } + + origTarget.Vars = rr.Target.Vars + rr.Target = origTarget + + origHttpTarget.Headers = rr.HttpTarget.Headers + origHttpTarget.Params = rr.HttpTarget.Params + rr.HttpTarget = origHttpTarget } |
