Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite13fcaf

Browse files
refactor(scaletest): support exposing arbitrary metrics on scaletest runs (#19886)
Relates tocoder/internal#889The existing implementation for exposing read and written bytes was a little awkward - we're going to be adding a bunch of scaletest runners / load generators that *don't* transfer any bytes. This PR has the scaletest reports expose a map of arbitrary string-keyed metrics instead.FWIW, the latest iteration of the scaletesting infrastructure doesn't parse these reports right now - they're just logged to stdout, so we're good to break the json schema here.
1 parentd02ff5f commite13fcaf

File tree

5 files changed

+106
-83
lines changed

5 files changed

+106
-83
lines changed

‎scaletest/harness/results.go‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ type Results struct {
2727

2828
// RunResult is the result of a single test run.
2929
typeRunResultstruct {
30-
FullIDstring`json:"full_id"`
31-
TestNamestring`json:"test_name"`
32-
IDstring`json:"id"`
33-
Logsstring`json:"logs"`
34-
Errorerror`json:"error"`
35-
StartedAt time.Time`json:"started_at"`
36-
Duration httpapi.Duration`json:"duration"`
37-
DurationMSint64`json:"duration_ms"`
38-
TotalBytesReadint64`json:"total_bytes_read"`
39-
TotalBytesWrittenint64`json:"total_bytes_written"`
30+
FullIDstring`json:"full_id"`
31+
TestNamestring`json:"test_name"`
32+
IDstring`json:"id"`
33+
Logsstring`json:"logs"`
34+
Errorerror`json:"error"`
35+
StartedAt time.Time`json:"started_at"`
36+
Duration httpapi.Duration`json:"duration"`
37+
DurationMSint64`json:"duration_ms"`
38+
Metricsmap[string]any`json:"metrics,omitempty"`
4039
}
4140

4241
// MarshalJSON implements json.Marhshaler for RunResult.
@@ -61,16 +60,15 @@ func (r *TestRun) Result() RunResult {
6160
}
6261

6362
returnRunResult{
64-
FullID:r.FullID(),
65-
TestName:r.testName,
66-
ID:r.id,
67-
Logs:r.logs.String(),
68-
Error:r.err,
69-
StartedAt:r.started,
70-
Duration:httpapi.Duration(r.duration),
71-
DurationMS:r.duration.Milliseconds(),
72-
TotalBytesRead:r.bytesRead,
73-
TotalBytesWritten:r.bytesWritten,
63+
FullID:r.FullID(),
64+
TestName:r.testName,
65+
ID:r.id,
66+
Logs:r.logs.String(),
67+
Error:r.err,
68+
StartedAt:r.started,
69+
Duration:httpapi.Duration(r.duration),
70+
DurationMS:r.duration.Milliseconds(),
71+
Metrics:r.metrics,
7472
}
7573
}
7674

‎scaletest/harness/results_test.go‎

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/coder/coder/v2/coderd/httpapi"
1818
"github.com/coder/coder/v2/scaletest/harness"
19+
"github.com/coder/coder/v2/scaletest/workspacetraffic"
1920
)
2021

2122
typetestErrorstruct {
@@ -36,40 +37,46 @@ func Test_Results(t *testing.T) {
3637
TotalFail:2,
3738
Runs:map[string]harness.RunResult{
3839
"test-0/0": {
39-
FullID:"test-0/0",
40-
TestName:"test-0",
41-
ID:"0",
42-
Logs:"test-0/0 log line 1\ntest-0/0 log line 2",
43-
Error:xerrors.New("test-0/0 error"),
44-
StartedAt:now,
45-
Duration:httpapi.Duration(time.Second),
46-
DurationMS:1000,
47-
TotalBytesRead:1024,
48-
TotalBytesWritten:2048,
40+
FullID:"test-0/0",
41+
TestName:"test-0",
42+
ID:"0",
43+
Logs:"test-0/0 log line 1\ntest-0/0 log line 2",
44+
Error:xerrors.New("test-0/0 error"),
45+
StartedAt:now,
46+
Duration:httpapi.Duration(time.Second),
47+
DurationMS:1000,
48+
Metrics:map[string]any{
49+
workspacetraffic.BytesReadMetric:1024,
50+
workspacetraffic.BytesWrittenMetric:2048,
51+
},
4952
},
5053
"test-0/1": {
51-
FullID:"test-0/1",
52-
TestName:"test-0",
53-
ID:"1",
54-
Logs:"test-0/1 log line 1\ntest-0/1 log line 2",
55-
Error:nil,
56-
StartedAt:now.Add(333*time.Millisecond),
57-
Duration:httpapi.Duration(time.Second),
58-
DurationMS:1000,
59-
TotalBytesRead:512,
60-
TotalBytesWritten:1024,
54+
FullID:"test-0/1",
55+
TestName:"test-0",
56+
ID:"1",
57+
Logs:"test-0/1 log line 1\ntest-0/1 log line 2",
58+
Error:nil,
59+
StartedAt:now.Add(333*time.Millisecond),
60+
Duration:httpapi.Duration(time.Second),
61+
DurationMS:1000,
62+
Metrics:map[string]any{
63+
workspacetraffic.BytesReadMetric:512,
64+
workspacetraffic.BytesWrittenMetric:1024,
65+
},
6166
},
6267
"test-0/2": {
63-
FullID:"test-0/2",
64-
TestName:"test-0",
65-
ID:"2",
66-
Logs:"test-0/2 log line 1\ntest-0/2 log line 2",
67-
Error:testError{hidden:xerrors.New("test-0/2 error")},
68-
StartedAt:now.Add(666*time.Millisecond),
69-
Duration:httpapi.Duration(time.Second),
70-
DurationMS:1000,
71-
TotalBytesRead:2048,
72-
TotalBytesWritten:4096,
68+
FullID:"test-0/2",
69+
TestName:"test-0",
70+
ID:"2",
71+
Logs:"test-0/2 log line 1\ntest-0/2 log line 2",
72+
Error:testError{hidden:xerrors.New("test-0/2 error")},
73+
StartedAt:now.Add(666*time.Millisecond),
74+
Duration:httpapi.Duration(time.Second),
75+
DurationMS:1000,
76+
Metrics:map[string]any{
77+
workspacetraffic.BytesReadMetric:2048,
78+
workspacetraffic.BytesWrittenMetric:4096,
79+
},
7380
},
7481
},
7582
Elapsed:httpapi.Duration(time.Second),
@@ -115,9 +122,11 @@ Test results:
115122
"started_at": "2023-10-05T12:03:56.395813665Z",
116123
"duration": "1s",
117124
"duration_ms": 1000,
118-
"total_bytes_read": 1024,
119-
"total_bytes_written": 2048,
120-
"error": "test-0/0 error:\n github.com/coder/coder/v2/scaletest/harness_test.Test_Results\n [working_directory]/results_test.go:43"
125+
"metrics": {
126+
"bytes_read": 1024,
127+
"bytes_written": 2048
128+
},
129+
"error": "test-0/0 error:\n github.com/coder/coder/v2/scaletest/harness_test.Test_Results\n [working_directory]/results_test.go:44"
121130
},
122131
"test-0/1": {
123132
"full_id": "test-0/1",
@@ -127,8 +136,10 @@ Test results:
127136
"started_at": "2023-10-05T12:03:56.728813665Z",
128137
"duration": "1s",
129138
"duration_ms": 1000,
130-
"total_bytes_read": 512,
131-
"total_bytes_written": 1024,
139+
"metrics": {
140+
"bytes_read": 512,
141+
"bytes_written": 1024
142+
},
132143
"error": "\u003cnil\u003e"
133144
},
134145
"test-0/2": {
@@ -139,8 +150,10 @@ Test results:
139150
"started_at": "2023-10-05T12:03:57.061813665Z",
140151
"duration": "1s",
141152
"duration_ms": 1000,
142-
"total_bytes_read": 2048,
143-
"total_bytes_written": 4096,
153+
"metrics": {
154+
"bytes_read": 2048,
155+
"bytes_written": 4096
156+
},
144157
"error": "test-0/2 error"
145158
}
146159
}

‎scaletest/harness/run.go‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ type Cleanable interface {
3131
Cleanup(ctx context.Context,idstring,logs io.Writer)error
3232
}
3333

34-
// Collectable is an optional extension to Runnable that allows to get metrics from the runner.
34+
// Collectable is an optional extension to Runnable that exposes additional
35+
// metrics from the runner.
3536
typeCollectableinterface {
3637
Runnable
37-
// Gets the bytes transferred
38-
GetBytesTransferred() (int64,int64)
38+
GetMetrics()map[string]any
3939
}
4040

4141
// AddRun creates a new *TestRun with the given name, ID and Runnable, adds it
@@ -73,13 +73,12 @@ type TestRun struct {
7373
idstring
7474
runnerRunnable
7575

76-
logs*syncBuffer
77-
donechanstruct{}
78-
started time.Time
79-
duration time.Duration
80-
errerror
81-
bytesReadint64
82-
bytesWrittenint64
76+
logs*syncBuffer
77+
donechanstruct{}
78+
started time.Time
79+
duration time.Duration
80+
errerror
81+
metricsmap[string]any
8382
}
8483

8584
funcNewTestRun(testNamestring,idstring,runnerRunnable)*TestRun {
@@ -111,7 +110,7 @@ func (r *TestRun) Run(ctx context.Context) (err error) {
111110
if!ok {
112111
return
113112
}
114-
r.bytesRead,r.bytesWritten=c.GetBytesTransferred()
113+
r.metrics=c.GetMetrics()
115114
}()
116115
deferfunc() {
117116
e:=recover()

‎scaletest/harness/run_test.go‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,28 @@ type testFns struct {
1717
RunFnfunc(ctx context.Context,idstring,logs io.Writer)error
1818
// CleanupFn is optional if no cleanup is required.
1919
CleanupFnfunc(ctx context.Context,idstring,logs io.Writer)error
20-
//getBytesTransferred is optional ifbyte transfer tracking is required.
21-
getBytesTransferredfunc()(int64,int64)
20+
//GetMetricsFn is optional ifno metric collection is required.
21+
GetMetricsFnfunc()map[string]any
2222
}
2323

24+
var (
25+
_ harness.Runnable=&testFns{}
26+
_ harness.Cleanable=&testFns{}
27+
_ harness.Collectable=&testFns{}
28+
)
29+
2430
// Run implements Runnable.
2531
func (fnstestFns)Run(ctx context.Context,idstring,logs io.Writer)error {
2632
returnfns.RunFn(ctx,id,logs)
2733
}
2834

2935
// GetBytesTransferred implements Collectable.
30-
func (fnstestFns)GetBytesTransferred()(bytesReadint64,bytesWrittenint64) {
31-
iffns.getBytesTransferred==nil {
32-
return0,0
36+
func (fnstestFns)GetMetrics()map[string]any {
37+
iffns.GetMetricsFn==nil {
38+
returnnil
3339
}
3440

35-
returnfns.getBytesTransferred()
41+
returnfns.GetMetricsFn()
3642
}
3743

3844
// Cleanup implements Cleanable.
@@ -65,9 +71,9 @@ func Test_TestRun(t *testing.T) {
6571
atomic.AddInt64(&cleanupCalled,1)
6672
returnnil
6773
},
68-
getBytesTransferred:func()(int64,int64) {
74+
GetMetricsFn:func()map[string]any {
6975
atomic.AddInt64(&collectableCalled,1)
70-
return0,0
76+
returnnil
7177
},
7278
}
7379
)
@@ -132,7 +138,7 @@ func Test_TestRun(t *testing.T) {
132138
RunFn:func(ctx context.Context,idstring,logs io.Writer)error {
133139
returnnil
134140
},
135-
getBytesTransferred:nil,
141+
GetMetricsFn:nil,
136142
})
137143

138144
err:=run.Run(context.Background())

‎scaletest/workspacetraffic/run.go‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ type Runner struct {
2828
}
2929

3030
var (
31-
_ harness.Runnable=&Runner{}
32-
_ harness.Cleanable=&Runner{}
31+
_ harness.Runnable=&Runner{}
32+
_ harness.Cleanable=&Runner{}
33+
_ harness.Collectable=&Runner{}
3334
)
3435

3536
// func NewRunner(client *codersdk.Client, cfg Config, metrics *Metrics) *Runner {
@@ -210,10 +211,16 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) (err error)
210211
}
211212
}
212213

213-
func (r*Runner)GetBytesTransferred() (bytesRead,bytesWrittenint64) {
214-
bytesRead=r.cfg.ReadMetrics.GetTotalBytes()
215-
bytesWritten=r.cfg.WriteMetrics.GetTotalBytes()
216-
returnbytesRead,bytesWritten
214+
const (
215+
BytesReadMetric="bytes_read"
216+
BytesWrittenMetric="bytes_written"
217+
)
218+
219+
func (r*Runner)GetMetrics()map[string]any {
220+
returnmap[string]any{
221+
BytesReadMetric:r.cfg.ReadMetrics.GetTotalBytes(),
222+
BytesWrittenMetric:r.cfg.WriteMetrics.GetTotalBytes(),
223+
}
217224
}
218225

219226
// Cleanup does nothing, successfully.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp