Repository: etcd-io/etcd
File: tests/robustness/traffic/traffic.go (Go)

Code before:
type trafficStats struct {
	Successes, Failures int
	Period              time.Duration
}

func (ts *trafficStats) SuccessRate() float64 {
	return float64(ts.Successes) / float64(ts.Successes+ts.Failures)
}

func (ts *trafficStats) QPS() float64 {
	return float64(ts.Successes) / ts.Period.Seconds()
}

type Profile struct {
	MinimalQPS                            float64
	MaximalQPS                            float64
	BurstableQPS                          int
	MaxNonUniqueRequestConcurrency        int
	MemberClientCount                     int
	ClusterClientCount                    int
	ForbidCompaction                      bool
	CompactPeriod                         time.Duration
	ContinuousWatchCreationInterval       time.Duration
	ContinuousWatchCreationRevisionOffset int64
}

func (p Profile) WithoutCompaction() Profile {
	p.ForbidCompaction = true
	return p
}

func (p Profile) WithCompactionPeriod(cp time.Duration) Profile {
	p.CompactPeriod = cp
	return p
}

func (p Profile) WithContinuousWatchCreationInterval(interval time.Duration) Profile {
	p.ContinuousWatchCreationInterval = interval
	return p
}

func (p Profile) WithContinuousWatchCreationRevisionOffset(offset int64) Profile {
	p.ContinuousWatchCreationRevisionOffset = offset
	return p
}

type RunTrafficLoopParam struct {
	Client                             *client.RecordingClient
	QPSLimiter                         *rate.Limiter
	IDs                                identity.Provider
	LeaseIDStorage                     identity.LeaseIDStorage

Review comment (suggestion):
Can you make it substruct?

```suggestion
	BackgroundWatchConifg
}

type BackgroundWatchConifg struct {
  Interval time.Duration
  RevisionOffset int64
}
```

Code after:

type trafficStats struct {
	Successes, Failures int
	Period              time.Duration
}

func (ts *trafficStats) SuccessRate() float64 {
	return float64(ts.Successes) / float64(ts.Successes+ts.Failures)
}

func (ts *trafficStats) QPS() float64 {
	return float64(ts.Successes) / ts.Period.Seconds()
}

type Profile struct {
	MinimalQPS                     float64
	MaximalQPS                     float64
	BurstableQPS                   int
	MaxNonUniqueRequestConcurrency int
	MemberClientCount              int
	ClusterClientCount             int
	ForbidCompaction               bool
	CompactPeriod                  time.Duration
	options.BackgroundWatchConfig
}

func (p Profile) WithoutCompaction() Profile {
	p.ForbidCompaction = true
	return p
}

func (p Profile) WithCompactionPeriod(cp time.Duration) Profile {
	p.CompactPeriod = cp
	return p
}

func (p Profile) WithBackgroundWatchConfigInterval(interval time.Duration) Profile {
	p.BackgroundWatchConfig.Interval = interval
	return p
}

func (p Profile) WithBackgroundWatchConfigRevisionOffset(offset int64) Profile {
	p.BackgroundWatchConfig.RevisionOffset = offset
	return p
}

type RunTrafficLoopParam struct {
	Client                             *client.RecordingClient
	QPSLimiter                         *rate.Limiter
	IDs                                identity.Provider
	LeaseIDStorage                     identity.LeaseIDStorage