github.com/yandex/pandora@v0.5.32/components/guns/dummy/generator.go (about)

     1  package dummy
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/yandex/pandora/core"
     7  	"github.com/yandex/pandora/core/aggregator/netsample"
     8  	"github.com/yandex/pandora/core/warmup"
     9  )
    10  
    11  type GunConfig struct {
    12  	Sleep time.Duration `config:"sleep"`
    13  }
    14  
    15  type Gun struct {
    16  	DebugLog bool
    17  	Conf     GunConfig
    18  	Aggr     core.Aggregator
    19  	core.GunDeps
    20  }
    21  
    22  func DefaultGunConfig() GunConfig {
    23  	return GunConfig{}
    24  }
    25  
    26  func (g *Gun) WarmUp(_ *warmup.Options) (any, error) {
    27  	return nil, nil
    28  }
    29  
    30  func NewGun(conf GunConfig) *Gun {
    31  	return &Gun{Conf: conf}
    32  }
    33  
    34  func (g *Gun) Bind(aggr core.Aggregator, deps core.GunDeps) error {
    35  	g.Aggr = aggr
    36  	g.GunDeps = deps
    37  	return nil
    38  }
    39  
    40  func (g *Gun) Shoot(_ core.Ammo) {
    41  	g.shoot()
    42  }
    43  
    44  func (g *Gun) shoot() {
    45  	code := 0
    46  	sample := netsample.Acquire("")
    47  	defer func() {
    48  		sample.SetProtoCode(code)
    49  		g.Aggr.Report(sample)
    50  	}()
    51  
    52  	time.Sleep(g.Conf.Sleep)
    53  	code = 200
    54  }
    55  
    56  var _ warmup.WarmedUp = (*Gun)(nil)