-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pools: | ||
- gun: | ||
type: my-custom-gun-name | ||
target: example.com:80 | ||
|
||
ammo: | ||
type: my-custom-provider-name | ||
source: # You may just write file path here. Or stdin. | ||
type: inline | ||
data: | | ||
{"url": "url1", "queryParam": "query1"} | ||
{"url": "url2", "queryParam": "query2"} | ||
result: | ||
type: json | ||
sink: stderr # Just for interactivity print result to stderr. Usually file user. | ||
|
||
rps: | ||
- {duration: 2s, type: line, from: 1, to: 5} | ||
- {duration: 3s, type: const, ops: 5} | ||
- {duration: 2s, type: line, from: 5, to: 1} | ||
startup: | ||
type: once | ||
times: 5 | ||
|
||
log: | ||
level: debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2017 Yandex LLC. All rights reserved. | ||
// Use of this source code is governed by a MPL 2.0 | ||
// license that can be found in the LICENSE file. | ||
// Author: Vladimir Skipor <[email protected]> | ||
|
||
package main | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/spf13/afero" | ||
"go.uber.org/zap" | ||
|
||
"github.com/yandex/pandora/cli" | ||
"github.com/yandex/pandora/components/phttp/import" | ||
"github.com/yandex/pandora/core" | ||
"github.com/yandex/pandora/core/import" | ||
"github.com/yandex/pandora/core/register" | ||
) | ||
|
||
type Ammo struct { | ||
URL string | ||
QueryParam string | ||
} | ||
|
||
type Sample struct { | ||
URL string | ||
ShootTimeSeconds float64 | ||
} | ||
|
||
type GunConfig struct { | ||
Target string `validate:"required"` // Configuration will fail, without target defined | ||
} | ||
|
||
type Gun struct { | ||
// Configured on construction. | ||
conf GunConfig | ||
|
||
// Configured on Bind, before shooting. | ||
aggr core.Aggregator // May be your custom Aggregator. | ||
core.GunDeps | ||
} | ||
|
||
func NewGun(conf GunConfig) *Gun { | ||
return &Gun{conf: conf} | ||
} | ||
|
||
func (g *Gun) Bind(aggr core.Aggregator, deps core.GunDeps) error { | ||
g.aggr = aggr | ||
g.GunDeps = deps | ||
return nil | ||
} | ||
|
||
func (g *Gun) Shoot(ammo core.Ammo) { | ||
customAmmo := ammo.(*Ammo) // Shoot will panic on unexpected ammo type. Panic cancels shooting. | ||
g.shoot(customAmmo) | ||
} | ||
|
||
func (g *Gun) shoot(ammo *Ammo) { | ||
start := time.Now() | ||
defer func() { | ||
g.aggr.Report(Sample{ammo.URL, time.Since(start).Seconds()}) | ||
}() | ||
// Put your shoot logic here. | ||
g.Log.Info("Custom shoot", zap.String("target", g.conf.Target), zap.Any("ammo", ammo)) | ||
time.Sleep(time.Duration(rand.Float64() * float64(time.Second))) | ||
} | ||
|
||
func main() { | ||
// Standard imports. | ||
fs := afero.NewOsFs() | ||
coreimport.Import(fs) | ||
|
||
// May not be imported, if you don't need http guns and etc. | ||
phttp.Import(fs) | ||
|
||
// Custom imports. Integrate your custom types into configuration system. | ||
coreimport.RegisterCustomJSONProvider("my-custom-provider-name", func() core.Ammo { return &Ammo{} }) | ||
|
||
register.Gun("my-custom-gun-name", NewGun, func() GunConfig { | ||
return GunConfig{ | ||
Target: "default target", | ||
} | ||
}) | ||
register.Gun("my-custom/no-default", NewGun) | ||
|
||
cli.Run() | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.