Skip to content

Commit 2a1d764

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into bq/refactor-few-services
2 parents ec57777 + 225cf8a commit 2a1d764

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

+950
-438
lines changed

agent/agentssh/agentssh.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,13 @@ func (s *Server) sessionStart(session ssh.Session, extraEnv []string) (retErr er
254254
magicType = strings.TrimPrefix(kv, MagicSessionTypeEnvironmentVariable+"=")
255255
env = append(env[:index], env[index+1:]...)
256256
}
257-
switch magicType {
258-
case MagicSessionTypeVSCode:
257+
258+
// Always force lowercase checking to be case-insensitive.
259+
switch strings.ToLower(magicType) {
260+
case strings.ToLower(MagicSessionTypeVSCode):
259261
s.connCountVSCode.Add(1)
260262
defer s.connCountVSCode.Add(-1)
261-
case MagicSessionTypeJetBrains:
263+
case strings.ToLower(MagicSessionTypeJetBrains):
262264
s.connCountJetBrains.Add(1)
263265
defer s.connCountJetBrains.Add(-1)
264266
case "":

agent/agentssh/metrics.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package agentssh
22

33
import (
4+
"strings"
5+
46
"github.com/prometheus/client_golang/prometheus"
57
)
68

@@ -78,5 +80,6 @@ func magicTypeMetricLabel(magicType string) string {
7880
default:
7981
magicType = "unknown"
8082
}
81-
return magicType
83+
// Always be case insensitive
84+
return strings.ToLower(magicType)
8285
}

cli/exp_scaletest.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ func (s *scaletestTracingFlags) provider(ctx context.Context) (trace.TracerProvi
105105

106106
tracerProvider, closeTracing, err := tracing.TracerProvider(ctx, scaletestTracerName, tracing.TracerOpts{
107107
Default: s.traceEnable,
108-
Coder: s.traceCoder,
109108
Honeycomb: s.traceHoneycombAPIKey,
110109
})
111110
if err != nil {

cli/root.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/base64"
88
"encoding/json"
99
"errors"
10-
"flag"
1110
"fmt"
1211
"io"
1312
"math/rand"
@@ -436,10 +435,6 @@ func LoggerFromContext(ctx context.Context) (slog.Logger, bool) {
436435
return l, ok
437436
}
438437

439-
func isTest() bool {
440-
return flag.Lookup("test.v") != nil
441-
}
442-
443438
// RootCmd contains parameters and helpers useful to all commands.
444439
type RootCmd struct {
445440
clientURL *url.URL

cli/server.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
408408
// which is caught by goleaks.
409409
defer http.DefaultClient.CloseIdleConnections()
410410

411-
tracerProvider, sqlDriver, closeTracing := ConfigureTraceProvider(ctx, logger, inv, vals)
411+
tracerProvider, sqlDriver, closeTracing := ConfigureTraceProvider(ctx, logger, vals)
412412
defer func() {
413413
logger.Debug(ctx, "closing tracing")
414414
traceCloseErr := shutdownWithTimeout(closeTracing, 5*time.Second)
@@ -2087,27 +2087,17 @@ func (s *HTTPServers) Close() {
20872087
func ConfigureTraceProvider(
20882088
ctx context.Context,
20892089
logger slog.Logger,
2090-
inv *clibase.Invocation,
20912090
cfg *codersdk.DeploymentValues,
20922091
) (trace.TracerProvider, string, func(context.Context) error) {
20932092
var (
20942093
tracerProvider = trace.NewNoopTracerProvider()
20952094
closeTracing = func(context.Context) error { return nil }
20962095
sqlDriver = "postgres"
20972096
)
2098-
// Coder tracing should be disabled if telemetry is disabled unless
2099-
// --telemetry-trace was explicitly provided.
2100-
shouldCoderTrace := cfg.Telemetry.Enable.Value() && !isTest()
2101-
// Only override if telemetryTraceEnable was specifically set.
2102-
// By default we want it to be controlled by telemetryEnable.
2103-
if inv.ParsedFlags().Changed("telemetry-trace") {
2104-
shouldCoderTrace = cfg.Telemetry.Trace.Value()
2105-
}
21062097

2107-
if cfg.Trace.Enable.Value() || shouldCoderTrace || cfg.Trace.HoneycombAPIKey != "" {
2098+
if cfg.Trace.Enable.Value() || cfg.Trace.DataDog.Value() || cfg.Trace.HoneycombAPIKey != "" {
21082099
sdkTracerProvider, _closeTracing, err := tracing.TracerProvider(ctx, "coderd", tracing.TracerOpts{
21092100
Default: cfg.Trace.Enable.Value(),
2110-
Coder: shouldCoderTrace,
21112101
DataDog: cfg.Trace.DataDog.Value(),
21122102
Honeycomb: cfg.Trace.HoneycombAPIKey.String(),
21132103
})

cli/testdata/coder_server_--help.golden

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,6 @@ telemetrywhen required by your organization's security policy.
415415
Whether telemetry is enabled or not. Coder collects anonymized usage
416416
data to help improve our product.
417417

418-
--telemetry-trace bool, $CODER_TELEMETRY_TRACE (default: false)
419-
Whether Opentelemetry traces are sent to Coder. Coder collects
420-
anonymized application tracing to help improve our product. Disabling
421-
telemetry also disables this option.
422-
423418
USER QUIET HOURS SCHEDULE OPTIONS:
424419
Allow users to set quiet hours schedules each day for workspaces to avoid
425420
workspaces stopping during the day due to template max TTL.

cli/testdata/server-config.yaml.golden

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,6 @@ telemetry:
334334
# help improve our product.
335335
# (default: false, type: bool)
336336
enable: false
337-
# Whether Opentelemetry traces are sent to Coder. Coder collects anonymized
338-
# application tracing to help improve our product. Disabling telemetry also
339-
# disables this option.
340-
# (default: false, type: bool)
341-
trace: false
342337
# URL to send telemetry.
343338
# (default: https://telemetry.coder.com, type: url)
344339
url: https://telemetry.coder.com

coderd/activitybump.go

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ package coderd
22

33
import (
44
"context"
5-
"database/sql"
6-
"errors"
75
"time"
86

97
"github.com/google/uuid"
108
"golang.org/x/xerrors"
119

1210
"cdr.dev/slog"
1311
"github.com/coder/coder/v2/coderd/database"
14-
"github.com/coder/coder/v2/coderd/database/dbtime"
1512
)
1613

1714
// activityBumpWorkspace automatically bumps the workspace's auto-off timer
@@ -21,72 +18,7 @@ func activityBumpWorkspace(ctx context.Context, log slog.Logger, db database.Sto
2118
// low priority operations fail first.
2219
ctx, cancel := context.WithTimeout(ctx, time.Second*15)
2320
defer cancel()
24-
25-
err := db.InTx(func(s database.Store) error {
26-
build, err := s.GetLatestWorkspaceBuildByWorkspaceID(ctx, workspaceID)
27-
if errors.Is(err, sql.ErrNoRows) {
28-
return nil
29-
} else if err != nil {
30-
return xerrors.Errorf("get latest workspace build: %w", err)
31-
}
32-
33-
job, err := s.GetProvisionerJobByID(ctx, build.JobID)
34-
if err != nil {
35-
return xerrors.Errorf("get provisioner job: %w", err)
36-
}
37-
38-
if build.Transition != database.WorkspaceTransitionStart || !job.CompletedAt.Valid {
39-
return nil
40-
}
41-
42-
if build.Deadline.IsZero() {
43-
// Workspace shutdown is manual
44-
return nil
45-
}
46-
47-
workspace, err := s.GetWorkspaceByID(ctx, workspaceID)
48-
if err != nil {
49-
return xerrors.Errorf("get workspace: %w", err)
50-
}
51-
52-
var (
53-
// We bump by the original TTL to prevent counter-intuitive behavior
54-
// as the TTL wraps. For example, if I set the TTL to 12 hours, sign off
55-
// work at midnight, come back at 10am, I would want another full day
56-
// of uptime. In the prior implementation, the workspace would enter
57-
// a state of always expiring 1 hour in the future
58-
bumpAmount = time.Duration(workspace.Ttl.Int64)
59-
// DB writes are expensive so we only bump when 5% of the deadline
60-
// has elapsed.
61-
bumpEvery = bumpAmount / 20
62-
timeSinceLastBump = bumpAmount - time.Until(build.Deadline)
63-
)
64-
65-
if timeSinceLastBump < bumpEvery {
66-
return nil
67-
}
68-
69-
if bumpAmount == 0 {
70-
return nil
71-
}
72-
73-
newDeadline := dbtime.Now().Add(bumpAmount)
74-
if !build.MaxDeadline.IsZero() && newDeadline.After(build.MaxDeadline) {
75-
newDeadline = build.MaxDeadline
76-
}
77-
78-
if err := s.UpdateWorkspaceBuildByID(ctx, database.UpdateWorkspaceBuildByIDParams{
79-
ID: build.ID,
80-
UpdatedAt: dbtime.Now(),
81-
ProvisionerState: build.ProvisionerState,
82-
Deadline: newDeadline,
83-
MaxDeadline: build.MaxDeadline,
84-
}); err != nil {
85-
return xerrors.Errorf("update workspace build: %w", err)
86-
}
87-
return nil
88-
}, nil)
89-
if err != nil {
21+
if err := db.ActivityBumpWorkspace(ctx, workspaceID); err != nil {
9022
if !xerrors.Is(err, context.Canceled) && !database.IsQueryCanceledError(err) {
9123
// Bump will fail if the context is canceled, but this is ok.
9224
log.Error(ctx, "bump failed", slog.Error(err),

0 commit comments

Comments
 (0)