Skip to content

Commit 1aca85a

Browse files
committed
cleanup + lint/fmt
Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent c48b946 commit 1aca85a

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

coderd/coderd.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,6 @@ type API struct {
18621862

18631863
metricsCache *metricscache.Cache
18641864
workspaceCreationAttemptsTotal *prometheus.CounterVec
1865-
workspaceCreationOutcomesTotal *prometheus.CounterVec
18661865
updateChecker *updatecheck.Checker
18671866
WorkspaceAppsProvider workspaceapps.SignedTokenProvider
18681867
workspaceAppServer *workspaceapps.Server

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"time"
2020

2121
"github.com/google/uuid"
22-
"github.com/prometheus/client_golang/prometheus"
2322
"github.com/sqlc-dev/pqtype"
2423
semconv "go.opentelemetry.io/otel/semconv/v1.14.0"
2524
"go.opentelemetry.io/otel/trace"
@@ -97,14 +96,12 @@ func (s *server) incrementWorkspaceCreationOutcomesMetric(ctx context.Context, w
9796
}
9897
}
9998

100-
if s.workspaceCreationOutcomesTotal != nil {
101-
s.workspaceCreationOutcomesTotal.WithLabelValues(
102-
workspace.OrganizationName,
103-
workspace.TemplateName,
104-
presetName,
105-
status,
106-
).Inc()
107-
}
99+
s.metrics.workspaceCreationOutcomesTotal.WithLabelValues(
100+
workspace.OrganizationName,
101+
workspace.TemplateName,
102+
presetName,
103+
status,
104+
).Inc()
108105
}
109106
}
110107

@@ -157,8 +154,6 @@ type server struct {
157154
UsageInserter *atomic.Pointer[usage.Inserter]
158155
Experiments codersdk.Experiments
159156

160-
workspaceCreationOutcomesTotal *prometheus.CounterVec
161-
162157
OIDCConfig promoauth.OAuth2Config
163158

164159
Clock quartz.Clock
@@ -294,11 +289,6 @@ func NewServer(
294289
Experiments: experiments,
295290
}
296291

297-
// Set workspace creation outcomes metric from metrics struct if available.
298-
if metrics != nil {
299-
s.workspaceCreationOutcomesTotal = metrics.workspaceCreationOutcomesTotal
300-
}
301-
302292
if s.heartbeatFn == nil {
303293
s.heartbeatFn = s.defaultHeartbeat
304294
}
@@ -2332,7 +2322,9 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
23322322

23332323
// Increment workspace creation outcomes metric for first 'start' builds.
23342324
// This counts regular (non-prebuilt) workspace creation outcomes (success/failure).
2335-
s.incrementWorkspaceCreationOutcomesMetric(ctx, workspace, workspaceBuild, job)
2325+
if s.metrics != nil {
2326+
s.incrementWorkspaceCreationOutcomesMetric(ctx, workspace, workspaceBuild, job)
2327+
}
23362328

23372329
// Post-transaction operations (operations that do not require transactions or
23382330
// are external to the database, like audit logging, notifications, etc.)

coderd/provisionerdserver/provisionerdserver_metrics_internal_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,17 @@ func TestWorkspaceCreationOutcomesMetricLogic(t *testing.T) {
181181
))
182182

183183
// Create a test server instance with the test metrics.
184+
184185
testServer := &server{
185-
Database: db,
186-
workspaceCreationOutcomesTotal: testMetrics.workspaceCreationOutcomesTotal,
186+
Database: db,
187+
metrics: testMetrics,
187188
}
188189

189190
// Call the actual metric increment function.
190191
testServer.incrementWorkspaceCreationOutcomesMetric(ctx, workspace, workspaceBuild, job)
191192

192193
// Verify the metric.
193-
newValue := promtest.ToFloat64(testMetrics.workspaceCreationOutcomesTotal.WithLabelValues(
194+
newValue := promtest.ToFloat64(testServer.metrics.workspaceCreationOutcomesTotal.WithLabelValues(
194195
orgName,
195196
templateName,
196197
expectedPresetName,

enterprise/coderd/workspaces_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,9 +2940,7 @@ func TestWorkspaceProvisionerdServerMetrics(t *testing.T) {
29402940
db, pb := dbtestutil.NewDB(t, dbtestutil.WithDumpOnFailure())
29412941
logger := testutil.Logger(t)
29422942
reg := prometheus.NewRegistry()
2943-
provisionerdserverMetrics := provisionerdserver.NewMetrics(logger)
2944-
err := provisionerdserverMetrics.Register(reg)
2945-
require.NoError(t, err)
2943+
provisionerdserverMetrics := provisionerdserver.NewMetrics(logger, reg)
29462944
client, _, api, owner := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
29472945
Options: &coderdtest.Options{
29482946
Database: db,

0 commit comments

Comments
 (0)