Skip to content

Commit 4fbbc1a

Browse files
committed
Merge branch 'main' into bq/workspace-filter
2 parents 68bd9f2 + 4eb0baa commit 4fbbc1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1052
-407
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ jobs:
179179
run: |
180180
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.17.2/sqlc_1.17.2_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
181181
- name: Install protoc-gen-go
182-
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
182+
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
183183
- name: Install protoc-gen-go-drpc
184-
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.26
184+
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
185185
- name: Install goimports
186186
run: go install golang.org/x/tools/cmd/goimports@latest
187187
- name: Install yq

.github/workflows/dogfood.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
cache-from: type=registry,ref=codercom/oss-dogfood:latest
5050
cache-to: type=inline
5151
deploy_template:
52+
needs: deploy_image
5253
runs-on: ubuntu-latest
5354
steps:
5455
- name: Checkout

.github/workflows/security.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ jobs:
8686
- name: Install mockgen
8787
run: go install github.com/golang/mock/mockgen@v1.6.0
8888
- name: Install protoc-gen-go
89-
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
89+
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
9090
- name: Install protoc-gen-go-drpc
91-
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.26
91+
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
9292
- name: Install Protoc
9393
run: |
9494
# protoc must be in lockstep with our dogfood Dockerfile or the

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ site/stats/
5959
./scaletest/terraform/.terraform
6060
./scaletest/terraform/.terraform.lock.hcl
6161
terraform.tfstate.*
62+
**/*.tfvars

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ site/stats/
6262
./scaletest/terraform/.terraform
6363
./scaletest/terraform/.terraform.lock.hcl
6464
terraform.tfstate.*
65+
**/*.tfvars
6566
# .prettierignore.include:
6667
# Helm templates contain variables that are invalid YAML and can't be formatted
6768
# by Prettier.

cli/agent_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func TestWorkspaceAgent(t *testing.T) {
5353
pty := ptytest.New(t).Attach(inv)
5454

5555
clitest.Start(t, inv)
56-
pty.ExpectMatch("starting agent")
56+
ctx := inv.Context()
57+
pty.ExpectMatchContext(ctx, "starting agent")
5758

5859
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
5960

@@ -99,8 +100,7 @@ func TestWorkspaceAgent(t *testing.T) {
99100
//nolint:revive,staticcheck
100101
context.WithValue(inv.Context(), "azure-client", metadataClient),
101102
)
102-
ctx, cancelFunc := context.WithCancel(context.Background())
103-
defer cancelFunc()
103+
ctx := inv.Context()
104104
clitest.Start(t, inv)
105105
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
106106
workspace, err := client.Workspace(ctx, workspace.ID)
@@ -112,7 +112,7 @@ func TestWorkspaceAgent(t *testing.T) {
112112
dialer, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, nil)
113113
require.NoError(t, err)
114114
defer dialer.Close()
115-
require.True(t, dialer.AwaitReachable(context.Background()))
115+
require.True(t, dialer.AwaitReachable(ctx))
116116
})
117117

118118
t.Run("AWS", func(t *testing.T) {
@@ -153,17 +153,18 @@ func TestWorkspaceAgent(t *testing.T) {
153153
context.WithValue(inv.Context(), "aws-client", metadataClient),
154154
)
155155
clitest.Start(t, inv)
156+
ctx := inv.Context()
156157
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
157-
workspace, err := client.Workspace(inv.Context(), workspace.ID)
158+
workspace, err := client.Workspace(ctx, workspace.ID)
158159
require.NoError(t, err)
159160
resources := workspace.LatestBuild.Resources
160161
if assert.NotEmpty(t, resources) && assert.NotEmpty(t, resources[0].Agents) {
161162
assert.NotEmpty(t, resources[0].Agents[0].Version)
162163
}
163-
dialer, err := client.DialWorkspaceAgent(inv.Context(), resources[0].Agents[0].ID, nil)
164+
dialer, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, nil)
164165
require.NoError(t, err)
165166
defer dialer.Close()
166-
require.True(t, dialer.AwaitReachable(context.Background()))
167+
require.True(t, dialer.AwaitReachable(ctx))
167168
})
168169

169170
t.Run("GoogleCloud", func(t *testing.T) {
@@ -204,7 +205,7 @@ func TestWorkspaceAgent(t *testing.T) {
204205
clitest.Start(t,
205206
inv.WithContext(
206207
//nolint:revive,staticcheck
207-
context.WithValue(context.Background(), "gcp-client", metadataClient),
208+
context.WithValue(inv.Context(), "gcp-client", metadataClient),
208209
),
209210
)
210211

@@ -220,7 +221,7 @@ func TestWorkspaceAgent(t *testing.T) {
220221
dialer, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, nil)
221222
require.NoError(t, err)
222223
defer dialer.Close()
223-
require.True(t, dialer.AwaitReachable(context.Background()))
224+
require.True(t, dialer.AwaitReachable(ctx))
224225
sshClient, err := dialer.SSHClient(ctx)
225226
require.NoError(t, err)
226227
defer sshClient.Close()
@@ -269,7 +270,7 @@ func TestWorkspaceAgent(t *testing.T) {
269270
pty := ptytest.New(t).Attach(inv)
270271

271272
clitest.Start(t, inv)
272-
pty.ExpectMatch("starting agent")
273+
pty.ExpectMatchContext(inv.Context(), "starting agent")
273274

274275
resources := coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
275276
require.Len(t, resources, 1)

cli/cliui/provisionerjob_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func TestProvisionerJob(t *testing.T) {
8282
// This cannot be ran in parallel because it uses a signal.
8383
// nolint:paralleltest
8484
t.Run("Cancel", func(t *testing.T) {
85+
t.Skip("This test issues an interrupt signal which will propagate to the test runner.")
86+
8587
if runtime.GOOS == "windows" {
8688
// Sending interrupt signal isn't supported on Windows!
8789
t.SkipNow()

cli/scaletest.go

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ import (
1414
"time"
1515

1616
"github.com/google/uuid"
17+
"github.com/prometheus/client_golang/prometheus"
18+
"github.com/prometheus/client_golang/prometheus/promhttp"
1719
"go.opentelemetry.io/otel/trace"
1820
"golang.org/x/xerrors"
1921

22+
"cdr.dev/slog"
23+
"cdr.dev/slog/sloggers/sloghuman"
24+
2025
"github.com/coder/coder/cli/clibase"
2126
"github.com/coder/coder/cli/cliui"
2227
"github.com/coder/coder/coderd/httpapi"
@@ -896,8 +901,11 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
896901

897902
func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
898903
var (
899-
tickInterval time.Duration
900-
bytesPerTick int64
904+
tickInterval time.Duration
905+
bytesPerTick int64
906+
scaletestPrometheusAddress string
907+
scaletestPrometheusWait time.Duration
908+
901909
client = &codersdk.Client{}
902910
tracingFlags = &scaletestTracingFlags{}
903911
strategy = &scaletestStrategyFlags{}
@@ -913,6 +921,12 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
913921
),
914922
Handler: func(inv *clibase.Invocation) error {
915923
ctx := inv.Context()
924+
reg := prometheus.NewRegistry()
925+
metrics := workspacetraffic.NewMetrics(reg, "username", "workspace_name", "agent_name")
926+
927+
logger := slog.Make(sloghuman.Sink(io.Discard))
928+
prometheusSrvClose := ServeHandler(ctx, logger, promhttp.HandlerFor(reg, promhttp.HandlerOpts{}), scaletestPrometheusAddress, "prometheus")
929+
defer prometheusSrvClose()
916930

917931
// Bypass rate limiting
918932
client.HTTPClient = &http.Client{
@@ -943,6 +957,9 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
943957
_, _ = fmt.Fprintln(inv.Stderr, "\nUploading traces...")
944958
if err := closeTracing(ctx); err != nil {
945959
_, _ = fmt.Fprintf(inv.Stderr, "\nError uploading traces: %+v\n", err)
960+
// Wait for prometheus metrics to be scraped
961+
_, _ = fmt.Fprintf(inv.Stderr, "Waiting %s for prometheus metrics to be scraped\n", scaletestPrometheusWait)
962+
<-time.After(scaletestPrometheusWait)
946963
}
947964
}()
948965
tracer := tracerProvider.Tracer(scaletestTracerName)
@@ -955,16 +972,18 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
955972
th := harness.NewTestHarness(strategy.toStrategy(), cleanupStrategy.toStrategy())
956973
for idx, ws := range workspaces {
957974
var (
958-
agentID uuid.UUID
959-
name = "workspace-traffic"
960-
id = strconv.Itoa(idx)
975+
agentID uuid.UUID
976+
agentName string
977+
name = "workspace-traffic"
978+
id = strconv.Itoa(idx)
961979
)
962980

963981
for _, res := range ws.LatestBuild.Resources {
964982
if len(res.Agents) == 0 {
965983
continue
966984
}
967985
agentID = res.Agents[0].ID
986+
agentName = res.Agents[0].Name
968987
}
969988

970989
if agentID == uuid.Nil {
@@ -974,16 +993,20 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
974993

975994
// Setup our workspace agent connection.
976995
config := workspacetraffic.Config{
977-
AgentID: agentID,
978-
BytesPerTick: bytesPerTick,
979-
Duration: strategy.timeout,
980-
TickInterval: tickInterval,
996+
AgentID: agentID,
997+
AgentName: agentName,
998+
BytesPerTick: bytesPerTick,
999+
Duration: strategy.timeout,
1000+
TickInterval: tickInterval,
1001+
WorkspaceName: ws.Name,
1002+
WorkspaceOwner: ws.OwnerName,
1003+
Registry: reg,
9811004
}
9821005

9831006
if err := config.Validate(); err != nil {
9841007
return xerrors.Errorf("validate config: %w", err)
9851008
}
986-
var runner harness.Runnable = workspacetraffic.NewRunner(client, config)
1009+
var runner harness.Runnable = workspacetraffic.NewRunner(client, config, metrics)
9871010
if tracingEnabled {
9881011
runner = &runnableTraceWrapper{
9891012
tracer: tracer,
@@ -1034,6 +1057,20 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
10341057
Description: "How often to send traffic.",
10351058
Value: clibase.DurationOf(&tickInterval),
10361059
},
1060+
{
1061+
Flag: "scaletest-prometheus-address",
1062+
Env: "CODER_SCALETEST_PROMETHEUS_ADDRESS",
1063+
Default: "0.0.0.0:21112",
1064+
Description: "Address on which to expose scaletest Prometheus metrics.",
1065+
Value: clibase.StringOf(&scaletestPrometheusAddress),
1066+
},
1067+
{
1068+
Flag: "scaletest-prometheus-wait",
1069+
Env: "CODER_SCALETEST_PROMETHEUS_WAIT",
1070+
Default: "5s",
1071+
Description: "How long to wait before exiting in order to allow Prometheus metrics to be scraped.",
1072+
Value: clibase.DurationOf(&scaletestPrometheusWait),
1073+
},
10371074
}
10381075

10391076
tracingFlags.attach(&cmd.Options)

cli/scaletest_test.go

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ import (
88
"path/filepath"
99
"testing"
1010

11-
"github.com/google/uuid"
1211
"github.com/stretchr/testify/assert"
1312
"github.com/stretchr/testify/require"
1413

15-
"github.com/coder/coder/agent"
1614
"github.com/coder/coder/cli/clitest"
1715
"github.com/coder/coder/coderd/coderdtest"
1816
"github.com/coder/coder/codersdk"
19-
"github.com/coder/coder/codersdk/agentsdk"
20-
"github.com/coder/coder/provisioner/echo"
21-
"github.com/coder/coder/provisionersdk/proto"
2217
"github.com/coder/coder/pty/ptytest"
2318
"github.com/coder/coder/scaletest/harness"
2419
"github.com/coder/coder/testutil"
@@ -205,70 +200,28 @@ param3: 1
205200
})
206201
}
207202

208-
// This test pretends to stand up a workspace and run a no-op traffic generation test.
209-
// It's not a real test, but it's useful for debugging.
210-
// We do not perform any cleanup.
203+
// This test just validates that the CLI command accepts its known arguments.
204+
// A more comprehensive test is performed in workspacetraffic/run_test.go
211205
func TestScaleTestWorkspaceTraffic(t *testing.T) {
212206
t.Parallel()
213207

214208
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitMedium)
215209
defer cancelFunc()
216210

217-
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
218-
user := coderdtest.CreateFirstUser(t, client)
219-
220-
authToken := uuid.NewString()
221-
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
222-
Parse: echo.ParseComplete,
223-
ProvisionPlan: echo.ProvisionComplete,
224-
ProvisionApply: []*proto.Provision_Response{{
225-
Type: &proto.Provision_Response_Complete{
226-
Complete: &proto.Provision_Complete{
227-
Resources: []*proto.Resource{{
228-
Name: "example",
229-
Type: "aws_instance",
230-
Agents: []*proto.Agent{{
231-
Id: uuid.NewString(),
232-
Name: "agent",
233-
Auth: &proto.Agent_Token{
234-
Token: authToken,
235-
},
236-
Apps: []*proto.App{},
237-
}},
238-
}},
239-
},
240-
},
241-
}},
242-
})
243-
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
244-
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
245-
246-
ws := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) {
247-
cwr.Name = "scaletest-test"
248-
})
249-
coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID)
250-
251-
agentClient := agentsdk.New(client.URL)
252-
agentClient.SetSessionToken(authToken)
253-
agentCloser := agent.New(agent.Options{
254-
Client: agentClient,
255-
})
256-
t.Cleanup(func() {
257-
_ = agentCloser.Close()
258-
})
259-
260-
coderdtest.AwaitWorkspaceAgents(t, client, ws.ID)
211+
client := coderdtest.New(t, nil)
212+
_ = coderdtest.CreateFirstUser(t, client)
261213

262214
inv, root := clitest.New(t, "scaletest", "workspace-traffic",
263215
"--timeout", "1s",
264216
"--bytes-per-tick", "1024",
265217
"--tick-interval", "100ms",
218+
"--scaletest-prometheus-address", "127.0.0.1:0",
219+
"--scaletest-prometheus-wait", "0s",
266220
)
267221
clitest.SetupConfig(t, client, root)
268222
var stdout, stderr bytes.Buffer
269223
inv.Stdout = &stdout
270224
inv.Stderr = &stderr
271225
err := inv.WithContext(ctx).Run()
272-
require.NoError(t, err)
273-
require.Contains(t, stdout.String(), "Pass: 1")
226+
require.ErrorContains(t, err, "no scaletest workspaces exist")
274227
}

cli/server_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,8 @@ func TestServer_Production(t *testing.T) {
14911491

14921492
//nolint:tparallel,paralleltest // This test cannot be run in parallel due to signal handling.
14931493
func TestServer_Shutdown(t *testing.T) {
1494+
t.Skip("This test issues an interrupt signal which will propagate to the test runner.")
1495+
14941496
if runtime.GOOS == "windows" {
14951497
// Sending interrupt signal isn't supported on Windows!
14961498
t.SkipNow()

cli/testdata/coder_scaletest_workspace-traffic_--help.golden

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ Generate traffic to scaletest workspaces through coderd
2727
Output format specs in the format "<format>[:<path>]". Not specifying
2828
a path will default to stdout. Available formats: text, json.
2929

30+
--scaletest-prometheus-address string, $CODER_SCALETEST_PROMETHEUS_ADDRESS (default: 0.0.0.0:21112)
31+
Address on which to expose scaletest Prometheus metrics.
32+
33+
--scaletest-prometheus-wait duration, $CODER_SCALETEST_PROMETHEUS_WAIT (default: 5s)
34+
How long to wait before exiting in order to allow Prometheus metrics
35+
to be scraped.
36+
3037
--tick-interval duration, $CODER_SCALETEST_WORKSPACE_TRAFFIC_TICK_INTERVAL (default: 100ms)
3138
How often to send traffic.
3239

0 commit comments

Comments
 (0)