Skip to content

Commit 774e4d5

Browse files
committed
Merge branch 'main' into mes/table-user-groups
2 parents c642ef8 + 21f8731 commit 774e4d5

File tree

121 files changed

+3078
-1869
lines changed

Some content is hidden

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

121 files changed

+3078
-1869
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 {

.github/workflows/ci.yaml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,9 @@ jobs:
291291
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
292292
--packages="./..." -- $PARALLEL_FLAG -short -failfast $COVERAGE_FLAGS
293293
294-
- name: Print test stats
295-
if: success() || failure()
296-
run: |
297-
# Artifacts are not available after rerunning a job,
298-
# so we need to print the test stats to the log.
299-
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
300-
301294
- name: Upload test stats to Datadog
295+
timeout-minutes: 1
296+
continue-on-error: true
302297
uses: ./.github/actions/upload-datadog
303298
if: success() || failure()
304299
with:
@@ -343,14 +338,9 @@ jobs:
343338
export TS_DEBUG_DISCO=true
344339
make test-postgres
345340
346-
- name: Print test stats
347-
if: success() || failure()
348-
run: |
349-
# Artifacts are not available after rerunning a job,
350-
# so we need to print the test stats to the log.
351-
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
352-
353341
- name: Upload test stats to Datadog
342+
timeout-minutes: 1
343+
continue-on-error: true
354344
uses: ./.github/actions/upload-datadog
355345
if: success() || failure()
356346
with:
@@ -391,6 +381,8 @@ jobs:
391381
gotestsum --junitfile="gotests.xml" -- -race ./...
392382
393383
- name: Upload test stats to Datadog
384+
timeout-minutes: 1
385+
continue-on-error: true
394386
uses: ./.github/actions/upload-datadog
395387
if: always()
396388
with:

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/server.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import (
4141
"github.com/prometheus/client_golang/prometheus"
4242
"github.com/prometheus/client_golang/prometheus/collectors"
4343
"github.com/prometheus/client_golang/prometheus/promhttp"
44+
"go.opentelemetry.io/otel"
45+
"go.opentelemetry.io/otel/propagation"
4446
"go.opentelemetry.io/otel/trace"
4547
"golang.org/x/mod/semver"
4648
"golang.org/x/oauth2"
@@ -78,6 +80,7 @@ import (
7880
"github.com/coder/coder/v2/coderd/httpmw"
7981
"github.com/coder/coder/v2/coderd/oauthpki"
8082
"github.com/coder/coder/v2/coderd/prometheusmetrics"
83+
"github.com/coder/coder/v2/coderd/prometheusmetrics/insights"
8184
"github.com/coder/coder/v2/coderd/schedule"
8285
"github.com/coder/coder/v2/coderd/telemetry"
8386
"github.com/coder/coder/v2/coderd/tracing"
@@ -198,6 +201,21 @@ func enablePrometheus(
198201
}
199202
afterCtx(ctx, closeWorkspacesFunc)
200203

204+
insightsMetricsCollector, err := insights.NewMetricsCollector(options.Database, options.Logger, 0, 0)
205+
if err != nil {
206+
return nil, xerrors.Errorf("unable to initialize insights metrics collector: %w", err)
207+
}
208+
err = options.PrometheusRegistry.Register(insightsMetricsCollector)
209+
if err != nil {
210+
return nil, xerrors.Errorf("unable to register insights metrics collector: %w", err)
211+
}
212+
213+
closeInsightsMetricsCollector, err := insightsMetricsCollector.Run(ctx)
214+
if err != nil {
215+
return nil, xerrors.Errorf("unable to run insights metrics collector: %w", err)
216+
}
217+
afterCtx(ctx, closeInsightsMetricsCollector)
218+
201219
if vals.Prometheus.CollectAgentStats {
202220
closeAgentStatsFunc, err := prometheusmetrics.AgentStats(ctx, logger, options.PrometheusRegistry, options.Database, time.Now(), 0)
203221
if err != nil {
@@ -938,7 +956,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
938956
autobuildTicker := time.NewTicker(vals.AutobuildPollInterval.Value())
939957
defer autobuildTicker.Stop()
940958
autobuildExecutor := autobuild.NewExecutor(
941-
ctx, options.Database, options.Pubsub, coderAPI.TemplateScheduleStore, &coderAPI.Auditor, logger, autobuildTicker.C)
959+
ctx, options.Database, options.Pubsub, coderAPI.TemplateScheduleStore, &coderAPI.Auditor, coderAPI.AccessControlStore, logger, autobuildTicker.C)
942960
autobuildExecutor.Run()
943961

944962
hangDetectorTicker := time.NewTicker(vals.JobHangDetectorInterval.Value())
@@ -2020,6 +2038,13 @@ func ConfigureTraceProvider(
20202038
sqlDriver = "postgres"
20212039
)
20222040

2041+
otel.SetTextMapPropagator(
2042+
propagation.NewCompositeTextMapPropagator(
2043+
propagation.TraceContext{},
2044+
propagation.Baggage{},
2045+
),
2046+
)
2047+
20232048
if cfg.Trace.Enable.Value() || cfg.Trace.DataDog.Value() || cfg.Trace.HoneycombAPIKey != "" {
20242049
sdkTracerProvider, _closeTracing, err := tracing.TracerProvider(ctx, "coderd", tracing.TracerOpts{
20252050
Default: cfg.Trace.Enable.Value(),

cli/templates.go

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

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

109
"github.com/coder/coder/v2/cli/clibase"
1110
"github.com/coder/coder/v2/cli/cliui"
1211
"github.com/coder/coder/v2/codersdk"
12+
"github.com/coder/pretty"
1313
)
1414

1515
func (r *RootCmd) templates() *clibase.Cmd {

cli/templateversionarchive.go

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

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

1211
"github.com/coder/coder/v2/cli/clibase"
1312
"github.com/coder/coder/v2/cli/cliui"
1413
"github.com/coder/coder/v2/codersdk"
14+
"github.com/coder/pretty"
1515
)
1616

1717
func (r *RootCmd) unarchiveTemplateVersion() *clibase.Cmd {

cli/templateversions.go

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

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

1211
"github.com/coder/coder/v2/cli/clibase"
1312
"github.com/coder/coder/v2/cli/cliui"
1413
"github.com/coder/coder/v2/codersdk"
14+
"github.com/coder/pretty"
1515
)
1616

1717
func (r *RootCmd) templateVersions() *clibase.Cmd {

cli/user_delete_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func TestUserDelete(t *testing.T) {
121121
// pw, err := cryptorand.String(16)
122122
// require.NoError(t, err)
123123

124-
// fmt.Println(aUser.OrganizationID)
125124
// toDelete, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
126125
// Email: "colin5@coder.com",
127126
// Username: "coolin",

coderd/apidoc/docs.go

Lines changed: 8 additions & 0 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: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/audit/request.go

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/google/uuid"
1313
"github.com/sqlc-dev/pqtype"
14+
"go.opentelemetry.io/otel/baggage"
15+
"golang.org/x/xerrors"
1416

1517
"cdr.dev/slog"
1618
"github.com/coder/coder/v2/coderd/database"
@@ -54,6 +56,7 @@ type BuildAuditParams[T Auditable] struct {
5456
Status int
5557
Action database.AuditAction
5658
OrganizationID uuid.UUID
59+
IP string
5760
AdditionalFields json.RawMessage
5861

5962
New T
@@ -248,9 +251,7 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
248251
// WorkspaceBuildAudit creates an audit log for a workspace build.
249252
// The audit log is committed upon invocation.
250253
func WorkspaceBuildAudit[T Auditable](ctx context.Context, p *BuildAuditParams[T]) {
251-
// As the audit request has not been initiated directly by a user, we omit
252-
// certain user details.
253-
ip := parseIP("")
254+
ip := parseIP(p.IP)
254255

255256
diff := Diff(p.Audit, p.Old, p.New)
256257
var err error
@@ -280,16 +281,70 @@ func WorkspaceBuildAudit[T Auditable](ctx context.Context, p *BuildAuditParams[T
280281
RequestID: p.JobID,
281282
AdditionalFields: p.AdditionalFields,
282283
}
283-
exportErr := p.Audit.Export(ctx, auditLog)
284-
if exportErr != nil {
284+
err = p.Audit.Export(ctx, auditLog)
285+
if err != nil {
285286
p.Log.Error(ctx, "export audit log",
286287
slog.F("audit_log", auditLog),
287288
slog.Error(err),
288289
)
289-
return
290290
}
291291
}
292292

293+
type WorkspaceBuildBaggage struct {
294+
IP string
295+
}
296+
297+
func (b WorkspaceBuildBaggage) Props() ([]baggage.Property, error) {
298+
ipProp, err := baggage.NewKeyValueProperty("ip", b.IP)
299+
if err != nil {
300+
return nil, xerrors.Errorf("create ip kv property: %w", err)
301+
}
302+
303+
return []baggage.Property{ipProp}, nil
304+
}
305+
306+
func WorkspaceBuildBaggageFromRequest(r *http.Request) WorkspaceBuildBaggage {
307+
return WorkspaceBuildBaggage{IP: r.RemoteAddr}
308+
}
309+
310+
type Baggage interface {
311+
Props() ([]baggage.Property, error)
312+
}
313+
314+
func BaggageToContext(ctx context.Context, d Baggage) (context.Context, error) {
315+
props, err := d.Props()
316+
if err != nil {
317+
return ctx, xerrors.Errorf("create baggage properties: %w", err)
318+
}
319+
320+
m, err := baggage.NewMember("audit", "baggage", props...)
321+
if err != nil {
322+
return ctx, xerrors.Errorf("create new baggage member: %w", err)
323+
}
324+
325+
b, err := baggage.New(m)
326+
if err != nil {
327+
return ctx, xerrors.Errorf("create new baggage carrier: %w", err)
328+
}
329+
330+
return baggage.ContextWithBaggage(ctx, b), nil
331+
}
332+
333+
func BaggageFromContext(ctx context.Context) WorkspaceBuildBaggage {
334+
d := WorkspaceBuildBaggage{}
335+
b := baggage.FromContext(ctx)
336+
props := b.Member("audit").Properties()
337+
for _, prop := range props {
338+
switch prop.Key() {
339+
case "ip":
340+
d.IP, _ = prop.Value()
341+
default:
342+
}
343+
}
344+
345+
return d
346+
}
347+
293348
func either[T Auditable, R any](old, new T, fn func(T) R, auditAction database.AuditAction) R {
294349
if ResourceID(new) != uuid.Nil {
295350
return fn(new)

0 commit comments

Comments
 (0)