Skip to content

Commit 7379e11

Browse files
authoredMay 8, 2024··
Merge pull request #5 from kelseyaubrecht/feat/datagrams
Feat/datagrams
2 parents 4413580 + e8a8925 commit 7379e11

File tree

9 files changed

+294
-162
lines changed

9 files changed

+294
-162
lines changed
 

‎.github/workflows/test.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v3
1919
with:
20-
go-version: 1.22
20+
go-version: 1.21
2121

2222
- name: Run prettier
2323
uses: creyD/prettier_action@v4.3
2424
with:
2525
dry: True
26-
26+
2727
- name: Lint code issues
2828
uses: golangci/golangci-lint-action@v3.7.1
2929
with:
3030
skip-pkg-cache: true
31-
31+
3232
- name: Build k6 with xk6-webtransport
3333
run: |
3434
go install go.k6.io/xk6/cmd/xk6@latest
3535
xk6 build --with github.com/kelseyaubrecht/xk6-webtransport@latest
36-

‎README.md

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
![ ](https://github.com/kelseyaubrecht/xk6-webtransport/actions/workflows/test.yaml/badge.svg)
2-
31
# xk6-webtransport
42

5-
[k6](https://github.com/grafana/k6) extension to k6 extension to use the WebTransport protocol. Currently only supports bidirectional streams.
3+
![ ](https://github.com/kelseyaubrecht/xk6-webtransport/actions/workflows/test.yaml/badge.svg)
4+
5+
[k6](https://github.com/grafana/k6) extension to k6 extension to use the WebTransport protocol.
66
Implemented using the [xk6](https://github.com/grafana/xk6) system and [webtransport-go](https://github.com/quic-go/webtransport-go).
77

8+
Supports:
9+
10+
- bidirectional streams
11+
- datagrams
12+
813
## Work in progress
914

1015
This project is a work in progress. Feedback and contributions are welcome!
@@ -25,13 +30,13 @@ To build a `k6` binary with this extension, first ensure you have the prerequisi
2530

2631
Then:
2732

28-
1. Install `xk6`:
33+
- Install `xk6`:
2934

3035
```shell
3136
go install go.k6.io/xk6/cmd/xk6@latest
3237
```
3338

34-
2. Build the binary:
39+
- Build the binary:
3540

3641
```shell
3742
xk6 build --with github.com/kelseyaubrecht/xk6-webtransport@latest
@@ -47,7 +52,7 @@ xk6 build --with github.com/kelseyaubrecht/xk6-webtransport@latest
4752

4853
## Usage example
4954

50-
An example of using the extension to create a bidirection stream.
55+
An example of using the extension to create a bidirection stream. More in [examples](examples).
5156

5257
```javascript
5358
import wt from "k6/x/webtransport";
@@ -68,11 +73,15 @@ export default function () {
6873

6974
## Metrics
7075

71-
| Metric | Type | Description |
72-
| ------------------------ | ------- | ---------------------------------- |
73-
| webtransport_read_bytes | counter | Total bytes read |
74-
| webtransport_read_count | counter | Total read count |
75-
| webtransport_read_size | trend | Trends of read size per operation |
76-
| webtransport_write_bytes | counter | Total bytes written |
77-
| webtransport_write_count | counter | Total write count |
78-
| webtransport_write_size | trend | Trends of write size per operation |
76+
| Metric | Type | Description |
77+
| ------------------------------------- | ------- | ---------------------------------- |
78+
| webtransport_read_bytes | counter | Total bytes read |
79+
| webtransport_read_count | counter | Total read count |
80+
| webtransport_read_size | trend | Trends of read size per operation |
81+
| webtransport_write_bytes | counter | Total bytes written |
82+
| webtransport_write_count | counter | Total write count |
83+
| webtransport_write_size | trend | Trends of write size per operation |
84+
| webtransport_datagrams_sent_count | counter | Number of sent datagrams |
85+
| webtransport_datagrams_sent_bytes | counter | Total bytes sent in datagrams |
86+
| webtransport_datagrams_received_count | counter | Number of received datagrams |
87+
| webtransport_datagrams_received_bytes | counter | Total bytes received in datagrams |

‎datagrams.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package wt
2+
3+
import (
4+
"log"
5+
"time"
6+
7+
"go.k6.io/k6/metrics"
8+
)
9+
10+
func (c *Connection) SendDatagram(p []byte) {
11+
err := c.Session.SendDatagram(p)
12+
defer c.logSendDatagramMetrics(len(p))
13+
if err != nil {
14+
log.Println("SendDatagram error: " + err.Error())
15+
}
16+
}
17+
18+
func (c *Connection) ReceiveDatagram() []byte {
19+
p, err := c.Session.ReceiveDatagram(c.Session.Context())
20+
if err != nil {
21+
log.Println("ReceiveDatagram error: " + err.Error())
22+
}
23+
defer c.logRecvDatagramMetrics(len(p))
24+
return p
25+
}
26+
27+
func (c *Connection) logSendDatagramMetrics(n int) {
28+
state := c.vu.State()
29+
ctx := c.vu.Context()
30+
if state == nil || ctx == nil {
31+
return
32+
}
33+
34+
now := time.Now()
35+
36+
metrics.PushIfNotDone(ctx, state.Samples, metrics.ConnectedSamples{
37+
Samples: []metrics.Sample{
38+
{
39+
Time: now,
40+
TimeSeries: metrics.TimeSeries{Metric: c.metrics.DatagramsSentCount},
41+
Value: 1,
42+
},
43+
{
44+
Time: now,
45+
TimeSeries: metrics.TimeSeries{Metric: c.metrics.DatagramsSentBytes},
46+
Value: float64(n),
47+
},
48+
},
49+
Time: now,
50+
})
51+
}
52+
53+
func (c *Connection) logRecvDatagramMetrics(n int) {
54+
state := c.vu.State()
55+
ctx := c.vu.Context()
56+
if state == nil || ctx == nil {
57+
return
58+
}
59+
60+
now := time.Now()
61+
62+
metrics.PushIfNotDone(ctx, state.Samples, metrics.ConnectedSamples{
63+
Samples: []metrics.Sample{
64+
{
65+
Time: now,
66+
TimeSeries: metrics.TimeSeries{Metric: c.metrics.DatagramsRecvCount},
67+
Value: 1,
68+
},
69+
{
70+
Time: now,
71+
TimeSeries: metrics.TimeSeries{Metric: c.metrics.DatagramsRecvBytes},
72+
Value: float64(n),
73+
},
74+
},
75+
Time: now,
76+
})
77+
}

‎examples/datagrams.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import wt from "k6/x/webtransport";
2+
3+
export default function () {
4+
const url = "https://localhost:443/webtransport";
5+
let data = [0, 1, 2, 3, 4];
6+
7+
wt.connect(url);
8+
9+
wt.sendDatagram(data);
10+
11+
const response = wt.receiveDatagram();
12+
// handle response
13+
}

‎go.mod

+39-37
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
11
module github.com/kelseyaubrecht/xk6-webtransport
22

3-
go 1.22
3+
go 1.21
44

55
require (
6-
github.com/quic-go/webtransport-go v0.6.0
7-
go.k6.io/k6 v0.48.0
6+
github.com/quic-go/webtransport-go v0.8.0
7+
go.k6.io/k6 v0.50.0
88
)
99

1010
require (
1111
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
12-
github.com/dlclark/regexp2 v1.9.0 // indirect
13-
github.com/dop251/goja v0.0.0-20231027120936-b396bb4c349d // indirect
14-
github.com/fatih/color v1.15.0 // indirect
15-
github.com/go-logr/logr v1.2.4 // indirect
12+
github.com/go-logr/logr v1.4.1 // indirect
1613
github.com/go-logr/stdr v1.2.2 // indirect
17-
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect
18-
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
14+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
1915
github.com/golang/protobuf v1.5.3 // indirect
20-
github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f // indirect
2116
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
17+
go.opentelemetry.io/otel v1.21.0 // indirect
18+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
19+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect
20+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 // indirect
21+
go.opentelemetry.io/otel/metric v1.21.0 // indirect
22+
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
23+
go.opentelemetry.io/otel/trace v1.21.0 // indirect
24+
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
25+
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
26+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
27+
google.golang.org/grpc v1.60.0 // indirect
28+
google.golang.org/protobuf v1.33.0 // indirect
29+
)
30+
31+
require (
32+
github.com/dlclark/regexp2 v1.11.0 // indirect
33+
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 // indirect
34+
github.com/fatih/color v1.16.0 // indirect
35+
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
36+
github.com/google/pprof v0.0.0-20240507183855-6f11f98ebb1c // indirect
2237
github.com/josharian/intern v1.0.0 // indirect
2338
github.com/mailru/easyjson v0.7.7 // indirect
2439
github.com/mattn/go-colorable v0.1.13 // indirect
25-
github.com/mattn/go-isatty v0.0.19 // indirect
40+
github.com/mattn/go-isatty v0.0.20 // indirect
2641
github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect
2742
github.com/onsi/ginkgo v1.16.5 // indirect
28-
github.com/onsi/ginkgo/v2 v2.12.0 // indirect
43+
github.com/onsi/ginkgo/v2 v2.17.3 // indirect
2944
github.com/quic-go/qpack v0.4.0 // indirect
30-
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
31-
github.com/quic-go/quic-go v0.40.0 // indirect
45+
github.com/quic-go/quic-go v0.43.1 // indirect
3246
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
3347
github.com/sirupsen/logrus v1.9.3 // indirect
34-
github.com/spf13/afero v1.1.2 // indirect
35-
go.opentelemetry.io/otel v1.19.0 // indirect
36-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
37-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
38-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
39-
go.opentelemetry.io/otel/metric v1.19.0 // indirect
40-
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
41-
go.opentelemetry.io/otel/trace v1.19.0 // indirect
42-
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
43-
go.uber.org/mock v0.3.0 // indirect
44-
golang.org/x/crypto v0.14.0 // indirect
45-
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
46-
golang.org/x/mod v0.12.0 // indirect
47-
golang.org/x/net v0.17.0 // indirect
48-
golang.org/x/sys v0.13.0 // indirect
49-
golang.org/x/text v0.13.0 // indirect
50-
golang.org/x/time v0.3.0 // indirect
51-
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
52-
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
53-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect
54-
google.golang.org/grpc v1.58.3 // indirect
55-
google.golang.org/protobuf v1.31.0 // indirect
56-
gopkg.in/guregu/null.v3 v3.3.0 // indirect
48+
github.com/spf13/afero v1.11.0 // indirect
49+
go.uber.org/mock v0.4.0 // indirect
50+
golang.org/x/crypto v0.23.0 // indirect
51+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
52+
golang.org/x/mod v0.17.0 // indirect
53+
golang.org/x/net v0.25.0 // indirect
54+
golang.org/x/sys v0.20.0 // indirect
55+
golang.org/x/text v0.15.0 // indirect
56+
golang.org/x/time v0.5.0 // indirect
57+
golang.org/x/tools v0.21.0 // indirect
58+
gopkg.in/guregu/null.v3 v3.5.0 // indirect
5759
)

0 commit comments

Comments
 (0)
Please sign in to comment.