- Notifications
You must be signed in to change notification settings - Fork948
feat: add managed agent license limit checks#18937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
- Adds a query for counting managed agent workspace builds between two timestamps- The "Actual" field in the feature entitlement for managed agents is now populated with the value read from the database- The wsbuilder package now validates AI agent usage against the limit when a license is installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM, couple minor points; I don't need to re-review.
@@ -279,7 +281,7 @@ func (e *Executor) runOnce(t time.Time) Stats { | |||
} | |||
if nextTransition != "" { | |||
builder := wsbuilder.New(ws, nextTransition). | |||
builder := wsbuilder.New(ws, nextTransition, *e.buildUsageChecker.Load()). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This could panic; can you add some protection for it?
func (q *querier) GetManagedAgentCount(ctx context.Context, arg database.GetManagedAgentCountParams) (int64, error) { | ||
// Must be able to read all workspaces to check usage. | ||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceWorkspace); err != nil { | ||
return 0, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please wrap err; could get confusing if there's an authz error on a seemingly unrelated resource.
wb.transition = 'start'::workspace_transition | ||
AND wb.has_ai_task = true | ||
-- Exclude failed builds since they can't use AI managed agents anyway. | ||
AND pj.job_status NOT IN ('canceled'::provisioner_job_status, 'failed'::provisioner_job_status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe it'll be more future-proof to whitelist instead of blacklist statuses...pending
,running
orsucceeded
are the only states you care about, right? This currently ignores other statuses likecanceling
,unknown
, etc.
@@ -335,7 +335,7 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) { | |||
return | |||
} | |||
builder:=wsbuilder.New(workspace,database.WorkspaceTransition(createBuild.Transition)). | |||
builder:=wsbuilder.New(workspace,database.WorkspaceTransition(createBuild.Transition),*api.BuildUsageChecker.Load()). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can panic
returnBuildError{http.StatusInternalServerError,"failed to check build usage",err} | ||
} | ||
if!resp.Permitted { | ||
returnBuildError{http.StatusForbidden,"Build is not permitted: "+resp.Message,nil} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nit: capitalisation consistency
Most of the code is new tests and updating old ones.
Closescoder/internal#777