-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatagrams.go
77 lines (67 loc) · 1.55 KB
/
datagrams.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
75
76
77
package wt
import (
"log"
"time"
"go.k6.io/k6/metrics"
)
func (c *Connection) SendDatagram(p []byte) {
err := c.Session.SendDatagram(p)
defer c.logSendDatagramMetrics(len(p))
if err != nil {
log.Println("SendDatagram error: " + err.Error())
}
}
func (c *Connection) ReceiveDatagram() []byte {
p, err := c.Session.ReceiveDatagram(c.Session.Context())
if err != nil {
log.Println("ReceiveDatagram error: " + err.Error())
}
defer c.logRecvDatagramMetrics(len(p))
return p
}
func (c *Connection) logSendDatagramMetrics(n int) {
state := c.vu.State()
ctx := c.vu.Context()
if state == nil || ctx == nil {
return
}
now := time.Now()
metrics.PushIfNotDone(ctx, state.Samples, metrics.ConnectedSamples{
Samples: []metrics.Sample{
{
Time: now,
TimeSeries: metrics.TimeSeries{Metric: c.metrics.DatagramsSentCount},
Value: 1,
},
{
Time: now,
TimeSeries: metrics.TimeSeries{Metric: c.metrics.DatagramsSentBytes},
Value: float64(n),
},
},
Time: now,
})
}
func (c *Connection) logRecvDatagramMetrics(n int) {
state := c.vu.State()
ctx := c.vu.Context()
if state == nil || ctx == nil {
return
}
now := time.Now()
metrics.PushIfNotDone(ctx, state.Samples, metrics.ConnectedSamples{
Samples: []metrics.Sample{
{
Time: now,
TimeSeries: metrics.TimeSeries{Metric: c.metrics.DatagramsRecvCount},
Value: 1,
},
{
Time: now,
TimeSeries: metrics.TimeSeries{Metric: c.metrics.DatagramsRecvBytes},
Value: float64(n),
},
},
Time: now,
})
}