Skip to content

Commit 803e555

Browse files
committed
Merge branch 'jsjoeio/update-dogfood' of github.com:coder/coder into jsjoeio/update-dogfood
2 parents ab841ce + 3ed2fa6 commit 803e555

File tree

7 files changed

+111
-73
lines changed

7 files changed

+111
-73
lines changed

cli/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func list() *cobra.Command {
7777
if err != nil {
7878
return err
7979
}
80+
8081
filter := codersdk.WorkspaceFilter{
8182
FilterQuery: searchQuery,
8283
}
@@ -91,6 +92,7 @@ func list() *cobra.Command {
9192
}
9293
filter.Owner = myUser.Username
9394
}
95+
9496
res, err := client.Workspaces(cmd.Context(), filter)
9597
if err != nil {
9698
return err
@@ -102,10 +104,12 @@ func list() *cobra.Command {
102104
_, _ = fmt.Fprintln(cmd.ErrOrStderr())
103105
return nil
104106
}
107+
105108
userRes, err := client.Users(cmd.Context(), codersdk.UsersRequest{})
106109
if err != nil {
107110
return err
108111
}
112+
109113
usersByID := map[uuid.UUID]codersdk.User{}
110114
for _, user := range userRes.Users {
111115
usersByID[user.ID] = user

cli/root.go

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -136,53 +136,6 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
136136
}
137137
return cmd.Help()
138138
},
139-
PersistentPreRun: func(cmd *cobra.Command, args []string) {
140-
if cliflag.IsSetBool(cmd, varNoVersionCheck) &&
141-
cliflag.IsSetBool(cmd, varNoFeatureWarning) {
142-
return
143-
}
144-
145-
// login handles checking the versions itself since it has a handle
146-
// to an unauthenticated client.
147-
//
148-
// server is skipped for obvious reasons.
149-
//
150-
// agent is skipped because these checks use the global coder config
151-
// and not the agent URL and token from the environment.
152-
//
153-
// gitssh is skipped because it's usually not called by users
154-
// directly.
155-
if cmd.Name() == "login" || cmd.Name() == "server" || cmd.Name() == "agent" || cmd.Name() == "gitssh" {
156-
return
157-
}
158-
if isGitAskpass {
159-
return
160-
}
161-
162-
client, err := CreateClient(cmd)
163-
// If we are unable to create a client, presumably the subcommand will fail as well
164-
// so we can bail out here.
165-
if err != nil {
166-
return
167-
}
168-
169-
err = checkVersions(cmd, client)
170-
if err != nil {
171-
// Just log the error here. We never want to fail a command
172-
// due to a pre-run.
173-
_, _ = fmt.Fprintf(cmd.ErrOrStderr(),
174-
cliui.Styles.Warn.Render("check versions error: %s"), err)
175-
_, _ = fmt.Fprintln(cmd.ErrOrStderr())
176-
}
177-
178-
err = checkWarnings(cmd, client)
179-
if err != nil {
180-
// Same as above
181-
_, _ = fmt.Fprintf(cmd.ErrOrStderr(),
182-
cliui.Styles.Warn.Render("check entitlement warnings error: %s"), err)
183-
_, _ = fmt.Fprintln(cmd.ErrOrStderr())
184-
}
185-
},
186139
Example: formatExamples(
187140
example{
188141
Description: "Start a Coder server",
@@ -307,6 +260,37 @@ func CreateClient(cmd *cobra.Command) (*codersdk.Client, error) {
307260
return nil, err
308261
}
309262
client.SetSessionToken(token)
263+
264+
// We send these requests in parallel to minimize latency.
265+
var (
266+
versionErr = make(chan error)
267+
warningErr = make(chan error)
268+
)
269+
go func() {
270+
versionErr <- checkVersions(cmd, client)
271+
close(versionErr)
272+
}()
273+
274+
go func() {
275+
warningErr <- checkWarnings(cmd, client)
276+
close(warningErr)
277+
}()
278+
279+
if err = <-versionErr; err != nil {
280+
// Just log the error here. We never want to fail a command
281+
// due to a pre-run.
282+
_, _ = fmt.Fprintf(cmd.ErrOrStderr(),
283+
cliui.Styles.Warn.Render("check versions error: %s"), err)
284+
_, _ = fmt.Fprintln(cmd.ErrOrStderr())
285+
}
286+
287+
if err = <-warningErr; err != nil {
288+
// Same as above
289+
_, _ = fmt.Fprintf(cmd.ErrOrStderr(),
290+
cliui.Styles.Warn.Render("check entitlement warnings error: %s"), err)
291+
_, _ = fmt.Fprintln(cmd.ErrOrStderr())
292+
}
293+
310294
return client, nil
311295
}
312296

coderd/client_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package coderd_test
2+
3+
import (
4+
"context"
5+
"net/http"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/coder/coder/codersdk"
10+
"github.com/coder/coder/testutil"
11+
)
12+
13+
// Issue: https://github.com/coder/coder/issues/5249
14+
// While running tests in parallel, the web server seems to be overloaded and responds with HTTP 502.
15+
// require.Eventually expects correct HTTP responses.
16+
17+
func doWithRetries(t require.TestingT, client *codersdk.Client, req *http.Request) (*http.Response, error) {
18+
var resp *http.Response
19+
var err error
20+
require.Eventually(t, func() bool {
21+
// nolint // only requests which are not passed upstream have a body closed
22+
resp, err = client.HTTPClient.Do(req)
23+
if resp != nil && resp.StatusCode == http.StatusBadGateway {
24+
if resp.Body != nil {
25+
resp.Body.Close()
26+
}
27+
return false
28+
}
29+
return true
30+
}, testutil.WaitLong, testutil.IntervalFast)
31+
return resp, err
32+
}
33+
34+
func requestWithRetries(ctx context.Context, t require.TestingT, client *codersdk.Client, method, path string, body interface{}, opts ...codersdk.RequestOption) (*http.Response, error) {
35+
var resp *http.Response
36+
var err error
37+
require.Eventually(t, func() bool {
38+
// nolint // only requests which are not passed upstream have a body closed
39+
resp, err = client.Request(ctx, method, path, body, opts...)
40+
if resp != nil && resp.StatusCode == http.StatusBadGateway {
41+
if resp.Body != nil {
42+
resp.Body.Close()
43+
}
44+
return false
45+
}
46+
return true
47+
}, testutil.WaitLong, testutil.IntervalFast)
48+
return resp, err
49+
}

coderd/database/queries.sql.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/provisionerjobs.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ WHERE
1919
provisioner_jobs AS nested
2020
WHERE
2121
nested.started_at IS NULL
22-
AND nested.canceled_at IS NULL
23-
AND nested.completed_at IS NULL
22+
-- Ensure the caller has the correct provisioner.
2423
AND nested.provisioner = ANY(@types :: provisioner_type [ ])
2524
-- Ensure the caller satisfies all job tags.
2625
AND nested.tags <@ @tags :: jsonb

coderd/workspaceapps_test.go

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func setupProxyTest(t *testing.T, customAppHost ...string) (*codersdk.Client, co
120120
},
121121
},
122122
})
123+
123124
user := coderdtest.CreateFirstUser(t, client)
124125

125126
workspace := createWorkspaceWithApps(t, client, user.OrganizationID, appHost, uint16(tcpAddr.Port))
@@ -243,7 +244,7 @@ func TestWorkspaceAppsProxyPath(t *testing.T) {
243244
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
244245
defer cancel()
245246

246-
resp, err := client.Request(ctx, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s", workspace.Name, proxyTestAppNameOwner), nil)
247+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s", workspace.Name, proxyTestAppNameOwner), nil)
247248
require.NoError(t, err)
248249
defer resp.Body.Close()
249250

@@ -264,7 +265,7 @@ func TestWorkspaceAppsProxyPath(t *testing.T) {
264265
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
265266
defer cancel()
266267

267-
resp, err := userClient.Request(ctx, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s", workspace.Name, proxyTestAppNameOwner), nil)
268+
resp, err := requestWithRetries(ctx, t, userClient, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s", workspace.Name, proxyTestAppNameOwner), nil)
268269
require.NoError(t, err)
269270
defer resp.Body.Close()
270271
require.Equal(t, http.StatusNotFound, resp.StatusCode)
@@ -276,7 +277,7 @@ func TestWorkspaceAppsProxyPath(t *testing.T) {
276277
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
277278
defer cancel()
278279

279-
resp, err := client.Request(ctx, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s", workspace.Name, proxyTestAppNameOwner), nil)
280+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s", workspace.Name, proxyTestAppNameOwner), nil)
280281
require.NoError(t, err)
281282
defer resp.Body.Close()
282283
require.Equal(t, http.StatusTemporaryRedirect, resp.StatusCode)
@@ -288,7 +289,7 @@ func TestWorkspaceAppsProxyPath(t *testing.T) {
288289
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
289290
defer cancel()
290291

291-
resp, err := client.Request(ctx, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s/", workspace.Name, proxyTestAppNameOwner), nil)
292+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s/", workspace.Name, proxyTestAppNameOwner), nil)
292293
require.NoError(t, err)
293294
defer resp.Body.Close()
294295
require.Equal(t, http.StatusTemporaryRedirect, resp.StatusCode)
@@ -303,7 +304,7 @@ func TestWorkspaceAppsProxyPath(t *testing.T) {
303304
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
304305
defer cancel()
305306

306-
resp, err := client.Request(ctx, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s/?%s", workspace.Name, proxyTestAppNameOwner, proxyTestAppQuery), nil)
307+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s/?%s", workspace.Name, proxyTestAppNameOwner, proxyTestAppQuery), nil)
307308
require.NoError(t, err)
308309
defer resp.Body.Close()
309310
body, err := io.ReadAll(resp.Body)
@@ -318,7 +319,7 @@ func TestWorkspaceAppsProxyPath(t *testing.T) {
318319
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
319320
defer cancel()
320321

321-
resp, err := client.Request(ctx, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s/?%s", workspace.Name, proxyTestAppNameOwner, proxyTestAppQuery), nil, func(r *http.Request) {
322+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, fmt.Sprintf("/@me/%s/apps/%s/?%s", workspace.Name, proxyTestAppNameOwner, proxyTestAppQuery), nil, func(r *http.Request) {
322323
r.Header.Set("Cf-Connecting-IP", "1.1.1.1")
323324
})
324325
require.NoError(t, err)
@@ -367,7 +368,9 @@ func TestWorkspaceApplicationAuth(t *testing.T) {
367368
require.NoError(t, err)
368369
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
369370
require.NoError(t, err)
370-
resp, err := client.HTTPClient.Do(req)
371+
372+
var resp *http.Response
373+
resp, err = doWithRetries(t, client, req)
371374
require.NoError(t, err)
372375
resp.Body.Close()
373376

@@ -380,7 +383,7 @@ func TestWorkspaceApplicationAuth(t *testing.T) {
380383
require.Equal(t, u.String(), gotLocation.Query().Get("redirect_uri"))
381384

382385
// Load the application auth-redirect endpoint.
383-
resp, err = client.Request(ctx, http.MethodGet, "/api/v2/applications/auth-redirect", nil, codersdk.WithQueryParam(
386+
resp, err = requestWithRetries(ctx, t, client, http.MethodGet, "/api/v2/applications/auth-redirect", nil, codersdk.WithQueryParam(
384387
"redirect_uri", u.String(),
385388
))
386389
require.NoError(t, err)
@@ -517,7 +520,7 @@ func TestWorkspaceApplicationAuth(t *testing.T) {
517520
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
518521
defer cancel()
519522

520-
resp, err := client.Request(ctx, http.MethodGet, "/api/v2/applications/auth-redirect", nil,
523+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, "/api/v2/applications/auth-redirect", nil,
521524
codersdk.WithQueryParam("redirect_uri", c.redirectURI),
522525
)
523526
require.NoError(t, err)
@@ -556,7 +559,7 @@ func TestWorkspaceAppsProxySubdomainPassthrough(t *testing.T) {
556559
defer cancel()
557560

558561
uri := fmt.Sprintf("http://app--agent--workspace--username.%s/api/v2/users/me", proxyTestSubdomain)
559-
resp, err := client.Request(ctx, http.MethodGet, uri, nil)
562+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, uri, nil)
560563
require.NoError(t, err)
561564
defer resp.Body.Close()
562565

@@ -605,7 +608,7 @@ func TestWorkspaceAppsProxySubdomainBlocked(t *testing.T) {
605608
defer cancel()
606609

607610
uri := fmt.Sprintf("http://not-an-app-subdomain.%s/api/v2/users/me", proxyTestSubdomain)
608-
resp, err := client.Request(ctx, http.MethodGet, uri, nil)
611+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, uri, nil)
609612
require.NoError(t, err)
610613
defer resp.Body.Close()
611614

@@ -689,7 +692,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
689692
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
690693
defer cancel()
691694

692-
resp, err := userClient.Request(ctx, http.MethodGet, proxyURL(t, client, proxyTestAppNameOwner), nil)
695+
resp, err := requestWithRetries(ctx, t, userClient, http.MethodGet, proxyURL(t, client, proxyTestAppNameOwner), nil)
693696
require.NoError(t, err)
694697
defer resp.Body.Close()
695698
require.Equal(t, http.StatusNotFound, resp.StatusCode)
@@ -702,7 +705,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
702705
defer cancel()
703706

704707
slashlessURL := proxyURL(t, client, proxyTestAppNameOwner, "")
705-
resp, err := client.Request(ctx, http.MethodGet, slashlessURL, nil)
708+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, slashlessURL, nil)
706709
require.NoError(t, err)
707710
defer resp.Body.Close()
708711
require.Equal(t, http.StatusTemporaryRedirect, resp.StatusCode)
@@ -719,7 +722,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
719722
defer cancel()
720723

721724
querylessURL := proxyURL(t, client, proxyTestAppNameOwner, "/", "")
722-
resp, err := client.Request(ctx, http.MethodGet, querylessURL, nil)
725+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, querylessURL, nil)
723726
require.NoError(t, err)
724727
defer resp.Body.Close()
725728
require.Equal(t, http.StatusTemporaryRedirect, resp.StatusCode)
@@ -735,7 +738,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
735738
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
736739
defer cancel()
737740

738-
resp, err := client.Request(ctx, http.MethodGet, proxyURL(t, client, proxyTestAppNameOwner, "/", proxyTestAppQuery), nil)
741+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, proxyURL(t, client, proxyTestAppNameOwner, "/", proxyTestAppQuery), nil)
739742
require.NoError(t, err)
740743
defer resp.Body.Close()
741744
body, err := io.ReadAll(resp.Body)
@@ -750,7 +753,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
750753
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
751754
defer cancel()
752755

753-
resp, err := client.Request(ctx, http.MethodGet, proxyURL(t, client, port, "/", proxyTestAppQuery), nil)
756+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, proxyURL(t, client, port, "/", proxyTestAppQuery), nil)
754757
require.NoError(t, err)
755758
defer resp.Body.Close()
756759
body, err := io.ReadAll(resp.Body)
@@ -778,7 +781,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
778781
defer cancel()
779782

780783
port := uint16(codersdk.MinimumListeningPort - 1)
781-
resp, err := client.Request(ctx, http.MethodGet, proxyURL(t, client, port, "/", proxyTestAppQuery), nil)
784+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, proxyURL(t, client, port, "/", proxyTestAppQuery), nil)
782785
require.NoError(t, err)
783786
defer resp.Body.Close()
784787

@@ -801,7 +804,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
801804
u := proxyURL(t, client, proxyTestAppNameOwner, "/", proxyTestAppQuery)
802805
t.Logf("url: %s", u)
803806

804-
resp, err := client.Request(ctx, http.MethodGet, u, nil)
807+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, u, nil)
805808
require.NoError(t, err)
806809
defer resp.Body.Close()
807810
body, err := io.ReadAll(resp.Body)
@@ -823,7 +826,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
823826
// Replace the -suffix with nothing.
824827
u = strings.Replace(u, "-suffix", "", 1)
825828

826-
resp, err := client.Request(ctx, http.MethodGet, u, nil)
829+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, u, nil)
827830
require.NoError(t, err)
828831
defer resp.Body.Close()
829832
body, err := io.ReadAll(resp.Body)
@@ -844,7 +847,7 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
844847
// Replace the -suffix with something else.
845848
u = strings.Replace(u, "-suffix", "-not-suffix", 1)
846849

847-
resp, err := client.Request(ctx, http.MethodGet, u, nil)
850+
resp, err := requestWithRetries(ctx, t, client, http.MethodGet, u, nil)
848851
require.NoError(t, err)
849852
defer resp.Body.Close()
850853
body, err := io.ReadAll(resp.Body)
@@ -947,7 +950,7 @@ func TestAppSharing(t *testing.T) {
947950
msg := fmt.Sprintf("client %d", i)
948951

949952
appPath := fmt.Sprintf("/@%s/%s.%s/apps/%s/?%s", username, workspaceName, agentName, appName, proxyTestAppQuery)
950-
res, err := client.Request(ctx, http.MethodGet, appPath, nil)
953+
res, err := requestWithRetries(ctx, t, client, http.MethodGet, appPath, nil)
951954
require.NoError(t, err, msg)
952955

953956
dump, err := httputil.DumpResponse(res, true)

docs/templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Template permissions can be used to give users and groups access to specific tem
343343

344344
## Community Templates
345345

346-
You can see a list of community templates by our users [here](../examples/templates/community-templates.md).
346+
You can see a list of community templates by our users [here](https://github.com/coder/coder/blob/main/examples/templates/community-templates.md).
347347

348348
## Next Steps
349349

0 commit comments

Comments
 (0)