-
Notifications
You must be signed in to change notification settings - Fork 0
/
probe.go
74 lines (57 loc) · 1.3 KB
/
probe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package sm
import (
"time"
"github.com/sirupsen/logrus"
"go.k6.io/k6/js/modules"
"go.k6.io/k6/lib"
"go.k6.io/k6/metrics"
)
func init() {
modules.Register("k6/x/sm", NewRootModule())
}
type RootModule struct{}
var _ modules.Module = &RootModule{}
func NewRootModule() *RootModule {
return &RootModule{}
}
func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
return &ModuleInstance{
vu: vu,
prober: &Prober{vu: vu},
}
}
type ModuleInstance struct {
vu modules.VU
prober *Prober
}
var _ modules.Instance = &ModuleInstance{}
func (mi *ModuleInstance) Exports() modules.Exports {
return modules.Exports{
Default: mi.prober,
}
}
type Prober struct {
vu modules.VU
}
type Opts struct {
Method string
}
func (p *Prober) Http(target string, opts Opts) bool {
ctx := p.vu.Context()
state := p.vu.State()
es := lib.GetExecutionState(ctx)
mFooBar, err := es.Test.Registry.NewMetric("foo_bar", metrics.Counter, metrics.Default)
if err != nil {
return false
}
state.Logger.WithFields(logrus.Fields{"target": target, "opts": opts}).Info("Prober.Http called")
// do something interesting here
metrics.PushIfNotDone(ctx, state.Samples, metrics.Sample{
Time: time.Now().UTC(),
Value: 1,
TimeSeries: metrics.TimeSeries{
Metric: mFooBar,
},
})
return true
}