Skip to content

Commit

Permalink
Implementation of group_duration
Browse files Browse the repository at this point in the history
  • Loading branch information
ragnarlonn committed Jun 21, 2017
1 parent 2d9184a commit 533dd4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion js/modules/k6/k6.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ func (*K6) Group(ctx context.Context, name string, fn goja.Callable) (goja.Value
state.Group = g
defer func() { state.Group = old }()

return fn(goja.Undefined())
tags := make(map[string]string)
tags["group"] = g.Path
// Call group function and generate group_duration sample
startTime := time.Now()
ret, err := fn(goja.Undefined())
t := time.Now()
duration := t.Sub(startTime).Seconds() * 1000
state.Samples = append(state.Samples,
stats.Sample{Time: t, Metric: metrics.GroupDuration, Tags: tags, Value: duration},
)
return ret, err
}

func (*K6) Check(ctx context.Context, arg0, checks goja.Value, extras ...goja.Value) (bool, error) {
Expand Down
3 changes: 2 additions & 1 deletion lib/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var (
Errors = stats.New("errors", stats.Counter)

// Runner-emitted.
Checks = stats.New("checks", stats.Rate)
Checks = stats.New("checks", stats.Rate)
GroupDuration = stats.New("group_duration", stats.Trend, stats.Time)

// HTTP-related.
HTTPReqs = stats.New("http_reqs", stats.Counter)
Expand Down

0 comments on commit 533dd4c

Please sign in to comment.