Skip to content

Commit 3c31168

Browse files
committed
Merge branch 'main' into 9983-insights-metrics
2 parents 0cb1206 + 2b5e02f commit 3c31168

File tree

101 files changed

+2354
-1576
lines changed

Some content is hidden

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

101 files changed

+2354
-1576
lines changed

.github/actions/setup-sqlc/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ runs:
55
using: "composite"
66
steps:
77
- name: Setup sqlc
8-
uses: sqlc-dev/setup-sqlc@v3
8+
uses: sqlc-dev/setup-sqlc@v4
99
with:
1010
sqlc-version: "1.20.0"

.github/pr-deployments/template/main.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
22
required_providers {
33
coder = {
4-
source = "coder/coder"
4+
source = "coder/coder"
55
}
66
kubernetes = {
7-
source = "hashicorp/kubernetes"
7+
source = "hashicorp/kubernetes"
88
}
99
}
1010
}
@@ -235,6 +235,9 @@ resource "kubernetes_deployment" "main" {
235235
"app.kubernetes.io/name" = "coder-workspace"
236236
}
237237
}
238+
strategy {
239+
type = "Recreate"
240+
}
238241

239242
template {
240243
metadata {

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ lint: lint/shellcheck lint/go lint/ts lint/helm lint/site-icons
419419

420420
lint/site-icons:
421421
./scripts/check_site_icons.sh
422-
423422
.PHONY: lint/site-icons
424423

425424
lint/ts:
@@ -517,6 +516,8 @@ coderd/database/dump.sql: coderd/database/gen/dump/main.go $(wildcard coderd/dat
517516
go run ./coderd/database/gen/dump/main.go
518517

519518
# Generates Go code for querying the database.
519+
# coderd/database/queries.sql.go
520+
# coderd/database/models.go
520521
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
521522
./coderd/database/generate.sh
522523

@@ -539,19 +540,18 @@ provisionerd/proto/provisionerd.pb.go: provisionerd/proto/provisionerd.proto
539540
--go-drpc_opt=paths=source_relative \
540541
./provisionerd/proto/provisionerd.proto
541542

542-
site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
543-
go run ./scripts/apitypings/ > site/src/api/typesGenerated.ts
544-
cd site
545-
pnpm run format:types ./src/api/typesGenerated.ts
543+
site/src/api/typesGenerated.ts: $(wildcard scripts/apitypings/*) $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
544+
go run ./scripts/apitypings/ > $@
545+
pnpm run format:write:only "$@"
546546

547547
site/e2e/provisionerGenerated.ts: provisionerd/proto/provisionerd.pb.go provisionersdk/proto/provisioner.pb.go
548548
cd site
549549
../scripts/pnpm_install.sh
550550
pnpm run gen:provisioner
551551

552-
site/src/theme/icons.json: $(wildcard site/static/icon/*)
553-
go run ./scripts/gensite/ -icons $@
554-
pnpm run format:write:only $@
552+
site/src/theme/icons.json: $(wildcard scripts/gensite/*) $(wildcard site/static/icon/*)
553+
go run ./scripts/gensite/ -icons "$@"
554+
pnpm run format:write:only "$@"
555555

556556
examples/examples.gen.json: scripts/examplegen/main.go examples/examples.go $(shell find ./examples/templates)
557557
go run ./scripts/examplegen/main.go > examples/examples.gen.json

cli/templates.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package cli
33
import (
44
"time"
55

6-
"github.com/coder/pretty"
76
"github.com/google/uuid"
87
"golang.org/x/xerrors"
98

9+
"github.com/coder/pretty"
10+
1011
"github.com/coder/coder/v2/cli/clibase"
1112
"github.com/coder/coder/v2/cli/cliui"
1213
"github.com/coder/coder/v2/codersdk"

cli/templateversionarchive.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"strings"
77
"time"
88

9-
"github.com/coder/pretty"
109
"golang.org/x/xerrors"
1110

11+
"github.com/coder/pretty"
12+
1213
"github.com/coder/coder/v2/cli/clibase"
1314
"github.com/coder/coder/v2/cli/cliui"
1415
"github.com/coder/coder/v2/codersdk"

cli/templateversions.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"strings"
66
"time"
77

8-
"github.com/coder/pretty"
98
"github.com/google/uuid"
109
"golang.org/x/xerrors"
1110

11+
"github.com/coder/pretty"
12+
1213
"github.com/coder/coder/v2/cli/clibase"
1314
"github.com/coder/coder/v2/cli/cliui"
1415
"github.com/coder/coder/v2/codersdk"

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ func New(options *Options) *API {
597597
})
598598
r.Route("/experiments", func(r chi.Router) {
599599
r.Use(apiKeyMiddleware)
600+
r.Get("/available", handleExperimentsSafe)
600601
r.Get("/", api.handleExperimentsGet)
601602
})
602603
r.Get("/updatecheck", api.updateCheck)

coderd/database/generate.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
2121
sqlc generate
2222

2323
first=true
24-
for fi in queries/*.sql.go; do
24+
files=$(find ./queries/ -type f -name "*.sql.go" | LC_ALL=C sort)
25+
for fi in $files; do
2526
# Find the last line from the imports section and add 1. We have to
2627
# disable pipefail temporarily to avoid ERRPIPE errors when piping into
2728
# `head -n1`.
@@ -56,7 +57,7 @@ SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
5657
go mod download
5758
go run golang.org/x/tools/cmd/goimports@latest -w queries.sql.go
5859

59-
go run ../../scripts/dbgen/main.go
60+
go run ../../scripts/dbgen
6061
# This will error if a view is broken.
6162
go test -run=TestViewSubset
6263
)

coderd/experiments.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"net/http"
55

66
"github.com/coder/coder/v2/coderd/httpapi"
7+
"github.com/coder/coder/v2/codersdk"
78
)
89

9-
// @Summary Get experiments
10-
// @ID get-experiments
10+
// @Summary Get enabled experiments
11+
// @ID get-enabled-experiments
1112
// @Security CoderSessionToken
1213
// @Produce json
1314
// @Tags General
@@ -17,3 +18,17 @@ func (api *API) handleExperimentsGet(rw http.ResponseWriter, r *http.Request) {
1718
ctx := r.Context()
1819
httpapi.Write(ctx, rw, http.StatusOK, api.Experiments)
1920
}
21+
22+
// @Summary Get safe experiments
23+
// @ID get-safe-experiments
24+
// @Security CoderSessionToken
25+
// @Produce json
26+
// @Tags General
27+
// @Success 200 {array} codersdk.Experiment
28+
// @Router /experiments/available [get]
29+
func handleExperimentsSafe(rw http.ResponseWriter, r *http.Request) {
30+
ctx := r.Context()
31+
httpapi.Write(ctx, rw, http.StatusOK, codersdk.AvailableExperiments{
32+
Safe: codersdk.ExperimentsAll,
33+
})
34+
}

coderd/experiments_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,21 @@ func Test_Experiments(t *testing.T) {
116116
require.Error(t, err)
117117
require.ErrorContains(t, err, httpmw.SignedOutErrorMessage)
118118
})
119+
120+
t.Run("available experiments", func(t *testing.T) {
121+
t.Parallel()
122+
cfg := coderdtest.DeploymentValues(t)
123+
client := coderdtest.New(t, &coderdtest.Options{
124+
DeploymentValues: cfg,
125+
})
126+
_ = coderdtest.CreateFirstUser(t, client)
127+
128+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
129+
defer cancel()
130+
131+
experiments, err := client.SafeExperiments(ctx)
132+
require.NoError(t, err)
133+
require.NotNil(t, experiments)
134+
require.ElementsMatch(t, codersdk.ExperimentsAll, experiments.Safe)
135+
})
119136
}

codersdk/deployment.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,12 +2013,13 @@ var ExperimentsAll = Experiments{
20132013
ExperimentSingleTailnet,
20142014
}
20152015

2016-
// Experiments is a list of experiments that are enabled for the deployment.
2016+
// Experiments is a list of experiments.
20172017
// Multiple experiments may be enabled at the same time.
20182018
// Experiments are not safe for production use, and are not guaranteed to
20192019
// be backwards compatible. They may be removed or renamed at any time.
20202020
type Experiments []Experiment
20212021

2022+
// Returns a list of experiments that are enabled for the deployment.
20222023
func (e Experiments) Enabled(ex Experiment) bool {
20232024
for _, v := range e {
20242025
if v == ex {
@@ -2041,6 +2042,25 @@ func (c *Client) Experiments(ctx context.Context) (Experiments, error) {
20412042
return exp, json.NewDecoder(res.Body).Decode(&exp)
20422043
}
20432044

2045+
// AvailableExperiments is an expandable type that returns all safe experiments
2046+
// available to be used with a deployment.
2047+
type AvailableExperiments struct {
2048+
Safe []Experiment `json:"safe"`
2049+
}
2050+
2051+
func (c *Client) SafeExperiments(ctx context.Context) (AvailableExperiments, error) {
2052+
res, err := c.Request(ctx, http.MethodGet, "/api/v2/experiments/available", nil)
2053+
if err != nil {
2054+
return AvailableExperiments{}, err
2055+
}
2056+
defer res.Body.Close()
2057+
if res.StatusCode != http.StatusOK {
2058+
return AvailableExperiments{}, ReadBodyAsError(res)
2059+
}
2060+
var exp AvailableExperiments
2061+
return exp, json.NewDecoder(res.Body).Decode(&exp)
2062+
}
2063+
20442064
type DAUsResponse struct {
20452065
Entries []DAUEntry `json:"entries"`
20462066
TZHourOffset int `json:"tz_hour_offset"`

docs/admin/provisioners.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Provisioners
1+
# External provisioners
22

33
By default, the Coder server runs
44
[built-in provisioner daemons](../cli/server.md#provisioner-daemons), which

docs/api/general.md

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

0 commit comments

Comments
 (0)