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

Commit4fab14b

Browse files
authored
fix: limit the scope of the template average build time query to the last 100 (#19648)
This PR shouldresolvecoder/internal#719 bylimiting the `workspace_builds` rows selected by the query to the mostrecent 100 builds of a template, as opposed to all builds in the last30d. For our own internal templates with the most builds (1700-2000 in a30d period) this should cut the query execution time by about 80%.Unless we have some restriction on keeping the 30d period, contractrelated or otherwise, this seems like a safe change to make. In additionto the execution speed improvements it also means the memory for thequery is bounded as well.If we want to keep a 30d time period for the avg build time value Ithink it's worth exploring a purpose built solution such as histogramstructures where the build times could be bucketized by template ID asthey're observed.---------Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent6574299 commit4fab14b

File tree

8 files changed

+15
-24
lines changed

8 files changed

+15
-24
lines changed

‎coderd/database/dbauthz/dbauthz.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2792,7 +2792,7 @@ func (q *querier) GetTemplateAppInsightsByTemplate(ctx context.Context, arg data
27922792
}
27932793

27942794
// Only used by metrics cache.
2795-
func (q*querier)GetTemplateAverageBuildTime(ctx context.Context,argdatabase.GetTemplateAverageBuildTimeParams) (database.GetTemplateAverageBuildTimeRow,error) {
2795+
func (q*querier)GetTemplateAverageBuildTime(ctx context.Context,arguuid.NullUUID) (database.GetTemplateAverageBuildTimeRow,error) {
27962796
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceSystem);err!=nil {
27972797
return database.GetTemplateAverageBuildTimeRow{},err
27982798
}

‎coderd/database/dbauthz/dbauthz_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3160,7 +3160,7 @@ func (s *MethodTestSuite) TestSystemFunctions() {
31603160
check.Args(arg).Asserts(rbac.ResourceSystem,policy.ActionRead).Returns(p)
31613161
}))
31623162
s.Run("GetTemplateAverageBuildTime",s.Mocked(func(dbm*dbmock.MockStore,_*gofakeit.Faker,check*expects) {
3163-
arg:=database.GetTemplateAverageBuildTimeParams{}
3163+
arg:=uuid.NullUUID{}
31643164
dbm.EXPECT().GetTemplateAverageBuildTime(gomock.Any(),arg).Return(database.GetTemplateAverageBuildTimeRow{},nil).AnyTimes()
31653165
check.Args(arg).Asserts(rbac.ResourceSystem,policy.ActionRead)
31663166
}))

‎coderd/database/dbmetrics/querymetrics.go‎

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

‎coderd/database/dbmock/dbmock.go‎

Lines changed: 4 additions & 4 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 & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go‎

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

‎coderd/database/queries/templates.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ JOIN provisioner_jobs pj ON
203203
WHERE
204204
template_versions.template_id= @template_idAND
205205
(pj.completed_atIS NOT NULL)AND (pj.started_atIS NOT NULL)AND
206-
(pj.started_at> @start_time)AND
207206
(pj.canceled_at ISNULL)AND
208207
((pj.error ISNULL)OR (pj.error=''))
209208
ORDER BY
210209
workspace_builds.created_atDESC
210+
LIMIT100
211211
)
212212
SELECT
213213
-- Postgres offers no clear way to DRY this short of a function or other

‎coderd/metricscache/metricscache.go‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,12 @@ func (c *Cache) refreshTemplateBuildTimes(ctx context.Context) error {
101101
for_,template:=rangetemplates {
102102
ids=append(ids,template.ID)
103103

104-
templateAvgBuildTime,err:=c.database.GetTemplateAverageBuildTime(ctx, database.GetTemplateAverageBuildTimeParams{
105-
TemplateID:uuid.NullUUID{
104+
templateAvgBuildTime,err:=c.database.GetTemplateAverageBuildTime(ctx,
105+
uuid.NullUUID{
106106
UUID:template.ID,
107107
Valid:true,
108108
},
109-
StartTime: sql.NullTime{
110-
Time:dbtime.Time(c.clock.Now().AddDate(0,0,-30)),
111-
Valid:true,
112-
},
113-
})
109+
)
114110
iferr!=nil {
115111
returnerr
116112
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp