Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7bd4c6a

Browse files
committed
feat: add prebuild timing metrics to Prometheus
1 parentcde5b62 commit7bd4c6a

File tree

14 files changed

+355
-43
lines changed

14 files changed

+355
-43
lines changed

‎cli/server.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,12 @@ func enablePrometheus(
236236
}
237237
afterCtx(ctx,closeUsersFunc)
238238

239-
closeWorkspacesFunc,err:=prometheusmetrics.Workspaces(ctx,options.Logger.Named("workspaces_metrics"),options.PrometheusRegistry,options.Database,0)
239+
closeWorkspacesFunc,updateWorkspaceTimingsMetrics,err:=prometheusmetrics.Workspaces(ctx,options.Logger.Named("workspaces_metrics"),options.PrometheusRegistry,options.Database,0)
240240
iferr!=nil {
241241
returnnil,xerrors.Errorf("register workspaces prometheus metric: %w",err)
242242
}
243243
afterCtx(ctx,closeWorkspacesFunc)
244+
options.UpdateWorkspaceTimingMetricsFn=updateWorkspaceTimingsMetrics
244245

245246
insightsMetricsCollector,err:=insights.NewMetricsCollector(options.Database,options.Logger,0,0)
246247
iferr!=nil {

‎coderd/coderd.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ type Options struct {
241241
UpdateAgentMetricsfunc(ctx context.Context,labels prometheusmetrics.AgentMetricLabels,metrics []*agentproto.Stats_Metric)
242242
StatsBatcher workspacestats.Batcher
243243

244+
// Function to update workspace timing metrics from provisionerdserver
245+
UpdateWorkspaceTimingMetricsFn prometheusmetrics.UpdateWorkspaceTimingMetricsFn
246+
244247
// WorkspaceAppAuditSessionTimeout allows changing the timeout for audit
245248
// sessions. Raising or lowering this value will directly affect the write
246249
// load of the audit log table. This is used for testing. Default 1 hour.
@@ -1923,9 +1926,10 @@ func (api *API) CreateInMemoryTaggedProvisionerDaemon(dialCtx context.Context, n
19231926
api.UsageInserter,
19241927
api.DeploymentValues,
19251928
provisionerdserver.Options{
1926-
OIDCConfig:api.OIDCConfig,
1927-
ExternalAuthConfigs:api.ExternalAuthConfigs,
1928-
Clock:api.Clock,
1929+
OIDCConfig:api.OIDCConfig,
1930+
ExternalAuthConfigs:api.ExternalAuthConfigs,
1931+
Clock:api.Clock,
1932+
UpdateWorkspaceTimingMetricsFn:api.UpdateWorkspaceTimingMetricsFn,
19291933
},
19301934
api.NotificationsEnqueuer,
19311935
&api.PrebuildsReconciler,

‎coderd/database/dbauthz/dbauthz.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,13 @@ func (q *querier) GetQuotaConsumedForUser(ctx context.Context, params database.G
26892689
returnq.db.GetQuotaConsumedForUser(ctx,params)
26902690
}
26912691

2692+
func (q*querier)GetRegularWorkspaceCreateMetrics(ctx context.Context) ([]database.GetRegularWorkspaceCreateMetricsRow,error) {
2693+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceWorkspace.All());err!=nil {
2694+
returnnil,err
2695+
}
2696+
returnq.db.GetRegularWorkspaceCreateMetrics(ctx)
2697+
}
2698+
26922699
func (q*querier)GetReplicaByID(ctx context.Context,id uuid.UUID) (database.Replica,error) {
26932700
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceSystem);err!=nil {
26942701
return database.Replica{},err

‎coderd/database/dbauthz/dbauthz_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,10 @@ func (s *MethodTestSuite) TestWorkspace() {
32263226
d:=dbgen.WorkspaceAgentDevcontainer(s.T(),db, database.WorkspaceAgentDevcontainer{WorkspaceAgentID:agt.ID})
32273227
check.Args(agt.ID).Asserts(w,policy.ActionRead).Returns([]database.WorkspaceAgentDevcontainer{d})
32283228
}))
3229+
s.Run("GetRegularWorkspaceCreateMetrics",s.Subtest(func(_ database.Store,check*expects) {
3230+
check.Args().
3231+
Asserts(rbac.ResourceWorkspace.All(),policy.ActionRead)
3232+
}))
32293233
}
32303234

32313235
func (s*MethodTestSuite)TestWorkspacePortSharing() {

‎coderd/database/dbmetrics/querymetrics.go‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbmock/dbmock.go‎

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go‎

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

‎coderd/database/queries.sql.go‎

Lines changed: 56 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/prebuilds.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ HAVING COUNT(*) = @hard_limit::bigint;
230230
SELECT
231231
t.nameas template_name,
232232
tvp.nameas preset_name,
233-
o.nameas organization_name,
233+
o.nameas organization_name,
234234
COUNT(*)as created_count,
235235
COUNT(*) FILTER (WHEREpj.job_status='failed'::provisioner_job_status)as failed_count,
236236
COUNT(*) FILTER (

‎coderd/database/queries/workspaces.sql‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,3 +914,22 @@ SET
914914
user_acl= @user_acl
915915
WHERE
916916
id= @id;
917+
918+
-- name: GetRegularWorkspaceCreateMetrics :many
919+
SELECT
920+
t.nameAS template_name,
921+
COALESCE(tvp.name,'')AS preset_name,
922+
o.nameAS organization_name,
923+
COUNT(*)AS created_count
924+
FROM workspaces w
925+
INNER JOIN workspace_builds wbONwb.workspace_id=w.id
926+
ANDwb.build_number=1
927+
ANDwb.transition='start'::workspace_transition
928+
ANDwb.initiator_id!='c42fdf75-3097-471c-8c33-fb52454d81c0'::uuid-- The system user responsible for prebuilds.
929+
INNER JOIN templates tONt.id=w.template_id
930+
LEFT JOIN template_version_presets tvpONtvp.id=wb.template_version_preset_id
931+
INNER JOIN provisioner_jobs pjONpj.id=wb.job_id
932+
INNER JOIN organizations oONo.id=w.organization_id
933+
WHERE NOTt.deletedANDpj.job_status='succeeded'::provisioner_job_status
934+
GROUP BYt.name, COALESCE(tvp.name,''),o.name
935+
ORDER BYt.name, preset_name,o.name;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp