Skip to content

Commit 3238a70

Browse files
Merge pull request #21 from form3tech-oss/martinr-verbose-log-fix
Fix for verbose log output to file when flag is not set
2 parents 5386f37 + 80ec5b6 commit 3238a70

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

pkg/f1/raterunner/runner.go renamed to pkg/f1/raterun/runner.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package raterunner
1+
package raterun
22

33
import (
44
"errors"
@@ -13,13 +13,22 @@ type Rate struct {
1313
Rate time.Duration // run in amount of Duration
1414
}
1515

16+
type Runner interface {
17+
// Terminate cancels scheduling for the next run
18+
Terminate()
19+
// RestartRate resets function calling back to first defined rate
20+
RestartRate()
21+
// run starts running the function at rates provided to the constructor
22+
Run()
23+
}
24+
1625
// New creates a new runner which varies in time according to given rates
17-
func New(fn RunFunction, rates []Rate) (*RateRunner, error) {
26+
func New(fn RunFunction, rates []Rate) (*rrInstance, error) {
1827
if len(rates) == 0 {
1928
return nil, errors.New("empty rates")
2029
}
2130

22-
rateRunner := &RateRunner{
31+
rateRunner := &rrInstance{
2332
terminateRunner: make(chan bool, 1),
2433
restartRates: make(chan bool, 1),
2534
runFunction: fn,
@@ -30,7 +39,7 @@ func New(fn RunFunction, rates []Rate) (*RateRunner, error) {
3039
return rateRunner, nil
3140
}
3241

33-
type RateRunner struct {
42+
type rrInstance struct {
3443
terminateRunner chan bool
3544
restartRates chan bool
3645
// function that is going to be run at specific timed intervals, according to current rate set at a specific moment in time
@@ -44,18 +53,15 @@ type RateRunner struct {
4453
rateTimer *time.Timer
4554
}
4655

47-
// Terminate finishes the runner
48-
func (rr *RateRunner) Terminate() {
56+
func (rr *rrInstance) Terminate() {
4957
rr.terminateRunner <- true
5058
}
5159

52-
// RestartRate resets function calling back to first defined rate
53-
func (rr *RateRunner) RestartRate() {
60+
func (rr *rrInstance) RestartRate() {
5461
rr.restartRates <- true
5562
}
5663

57-
// run starts running the function following the rates given to the constructor
58-
func (rr *RateRunner) Run() {
64+
func (rr *rrInstance) Run() {
5965
go func() {
6066
rr.rateTimer = time.NewTimer(rr.rates[0].Start)
6167
rr.fnTicker = time.NewTicker(time.Hour)
@@ -80,7 +86,7 @@ func (rr *RateRunner) Run() {
8086
}()
8187
}
8288

83-
func (rr *RateRunner) scheduleNextRate(rateIndex int) {
89+
func (rr *rrInstance) scheduleNextRate(rateIndex int) {
8490
if rateIndex < len(rr.rates) {
8591
nextRate := rr.rates[rateIndex]
8692
// close rateTimer if it hasn't run yet to prevent double runs
@@ -89,7 +95,7 @@ func (rr *RateRunner) scheduleNextRate(rateIndex int) {
8995
}
9096
}
9197

92-
func (rr *RateRunner) runAtRate(rate Rate) {
98+
func (rr *rrInstance) runAtRate(rate Rate) {
9399
rr.fnTicker.Stop()
94100
rr.fnTicker = time.NewTicker(rate.Rate)
95101
}

pkg/f1/raterunner/runner_test.go renamed to pkg/f1/raterun/runner_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package raterunner
1+
package raterun
22

33
import (
44
"testing"

pkg/f1/raterunner/runner_test_stage.go renamed to pkg/f1/raterun/runner_test_stage.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package raterunner
1+
package raterun
22

33
import (
44
"sync"
@@ -12,7 +12,7 @@ import (
1212

1313
type RatedRunnerStage struct {
1414
rates []Rate
15-
runner *RateRunner
15+
runner Runner
1616
m sync.Mutex
1717
funcRuns map[time.Duration]int
1818
t *testing.T

pkg/f1/run/test_runner.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
"github.com/form3tech-oss/f1/pkg/f1/trace"
2121

22-
"github.com/form3tech-oss/f1/pkg/f1/raterunner"
22+
"github.com/form3tech-oss/f1/pkg/f1/raterun"
2323

2424
"github.com/form3tech-oss/f1/pkg/f1/trigger/api"
2525

@@ -46,10 +46,10 @@ func NewRun(options options.RunOptions, t *api.Trigger) (*Run, error) {
4646
}
4747
run.result.IgnoreDropped = options.IgnoreDropped
4848

49-
progressRunner, _ := raterunner.New(func(rate time.Duration, t time.Time) {
49+
progressRunner, _ := raterun.New(func(rate time.Duration, t time.Time) {
5050
run.gatherProgressMetrics(rate)
5151
fmt.Println(run.result.Progress())
52-
}, []raterunner.Rate{
52+
}, []raterun.Rate{
5353
{Start: time.Nanosecond, Rate: time.Second},
5454
{Start: time.Minute, Rate: time.Second * 10},
5555
{Start: time.Minute * 5, Rate: time.Minute / 2},
@@ -72,7 +72,7 @@ type Run struct {
7272
RateDescription string
7373
pusher *push.Pusher
7474
notifyDropped sync.Once
75-
progressRunner *raterunner.RateRunner
75+
progressRunner raterun.Runner
7676
}
7777

7878
var startTemplate = template.Must(template.New("result parse").

pkg/f1/testing/t.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewT(env map[string]string, vu, iter string, scenarioName string) *T {
2929
t := &T{
3030
VirtualUser: vu,
3131
Iteration: iter,
32-
Log: log.New().WithField("u", vu).WithField("i", iter).WithField("scenario", scenarioName).Logger,
32+
Log: log.WithField("u", vu).WithField("i", iter).WithField("scenario", scenarioName).Logger,
3333
Environment: env,
3434
Scenario: scenarioName,
3535
}

0 commit comments

Comments
 (0)