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

Commit5369204

Browse files
authored
[2.26 backport] perf(enterprise): remove expensive GetWorkspaces query from entitlements (#19747) (#19756)
This PR addresses the significant database load issue where theGetWorkspaces query was causing performance problems in the licenseentitlements code.cherry picked from commit3074547
1 parentc0f1b9d commit5369204

File tree

2 files changed

+8
-49
lines changed

2 files changed

+8
-49
lines changed

‎enterprise/coderd/license/license.go‎

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ func Entitlements(
9696
return codersdk.Entitlements{},xerrors.Errorf("query active user count: %w",err)
9797
}
9898

99-
// nolint:gocritic // Getting external workspaces is a system function.
100-
externalWorkspaces,err:=db.GetWorkspaces(dbauthz.AsSystemRestricted(ctx), database.GetWorkspacesParams{
101-
HasExternalAgent: sql.NullBool{
102-
Bool:true,
103-
Valid:true,
104-
},
105-
})
106-
iferr!=nil {
107-
return codersdk.Entitlements{},xerrors.Errorf("query external workspaces: %w",err)
108-
}
109-
11099
// nolint:gocritic // Getting external templates is a system function.
111100
externalTemplates,err:=db.GetTemplatesWithFilter(dbauthz.AsSystemRestricted(ctx), database.GetTemplatesWithFilterParams{
112101
HasExternalAgent: sql.NullBool{
@@ -119,11 +108,10 @@ func Entitlements(
119108
}
120109

121110
entitlements,err:=LicensesEntitlements(ctx,now,licenses,enablements,keys,FeatureArguments{
122-
ActiveUserCount:activeUserCount,
123-
ReplicaCount:replicaCount,
124-
ExternalAuthCount:externalAuthCount,
125-
ExternalWorkspaceCount:int64(len(externalWorkspaces)),
126-
ExternalTemplateCount:int64(len(externalTemplates)),
111+
ActiveUserCount:activeUserCount,
112+
ReplicaCount:replicaCount,
113+
ExternalAuthCount:externalAuthCount,
114+
ExternalTemplateCount:int64(len(externalTemplates)),
127115
ManagedAgentCountFn:func(ctx context.Context,startTime time.Time,endTime time.Time) (int64,error) {
128116
// This is not super accurate, as the start and end times will be
129117
// truncated to the date in UTC timezone. This is an optimization
@@ -149,11 +137,10 @@ func Entitlements(
149137
}
150138

151139
typeFeatureArgumentsstruct {
152-
ActiveUserCountint64
153-
ReplicaCountint
154-
ExternalAuthCountint
155-
ExternalWorkspaceCountint64
156-
ExternalTemplateCountint64
140+
ActiveUserCountint64
141+
ReplicaCountint
142+
ExternalAuthCountint
143+
ExternalTemplateCountint64
157144
// Unfortunately, managed agent count is not a simple count of the current
158145
// state of the world, but a count between two points in time determined by
159146
// the licenses.
@@ -477,18 +464,6 @@ func LicensesEntitlements(
477464
}
478465
}
479466

480-
iffeatureArguments.ExternalWorkspaceCount>0 {
481-
feature:=entitlements.Features[codersdk.FeatureWorkspaceExternalAgent]
482-
switchfeature.Entitlement {
483-
casecodersdk.EntitlementNotEntitled:
484-
entitlements.Errors=append(entitlements.Errors,
485-
"You have external workspaces but your license is not entitled to this feature.")
486-
casecodersdk.EntitlementGracePeriod:
487-
entitlements.Warnings=append(entitlements.Warnings,
488-
"You have external workspaces but your license is expired.")
489-
}
490-
}
491-
492467
iffeatureArguments.ExternalTemplateCount>0 {
493468
feature:=entitlements.Features[codersdk.FeatureWorkspaceExternalAgent]
494469
switchfeature.Entitlement {

‎enterprise/coderd/license/license_test.go‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,6 @@ func TestEntitlements(t *testing.T) {
843843
returntrue
844844
})).
845845
Return(int64(175),nil)
846-
mDB.EXPECT().
847-
GetWorkspaces(gomock.Any(),gomock.Any()).
848-
Return([]database.GetWorkspacesRow{},nil)
849846
mDB.EXPECT().
850847
GetTemplatesWithFilter(gomock.Any(),gomock.Any()).
851848
Return([]database.Template{},nil)
@@ -1236,19 +1233,6 @@ func TestLicenseEntitlements(t *testing.T) {
12361233
assert.Equal(t,int64(200),*feature.Actual)
12371234
},
12381235
},
1239-
{
1240-
Name:"ExternalWorkspace",
1241-
Licenses: []*coderdenttest.LicenseOptions{
1242-
enterpriseLicense().UserLimit(100),
1243-
},
1244-
Arguments: license.FeatureArguments{
1245-
ExternalWorkspaceCount:1,
1246-
},
1247-
AssertEntitlements:func(t*testing.T,entitlements codersdk.Entitlements) {
1248-
assert.Equal(t,codersdk.EntitlementEntitled,entitlements.Features[codersdk.FeatureWorkspaceExternalAgent].Entitlement)
1249-
assert.True(t,entitlements.Features[codersdk.FeatureWorkspaceExternalAgent].Enabled)
1250-
},
1251-
},
12521236
{
12531237
Name:"ExternalTemplate",
12541238
Licenses: []*coderdenttest.LicenseOptions{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp