Repository navigation
fix: reduce cost of prebuild failure - #17697
Conversation
ab27056 to
3ef469a
Compare
1e9c551 to
fcb3e5d
Compare
dannykopping
left a comment
There was a problem hiding this comment.
Query looks good, we need more visibility of this problem and its remediation, though.
| func (q *querier) GetPresetsAtFailureLimit(ctx context.Context, hardLimit int64) ([]database.GetPresetsAtFailureLimitRow, error) { | ||
| // GetPresetsAtFailureLimit returns a list of template version presets that have reached the hard failure limit. | ||
| // Request the same authorization permissions as GetPresetsBackoff, since the methods are similar. | ||
| if err := q.authorizeContext(ctx, policy.ActionViewInsights, rbac.ResourceTemplate.All()); err != nil { |
There was a problem hiding this comment.
I still think "insights" is a weird auth context to use here.
Why did we choose this again @SasSwart?
There was a problem hiding this comment.
@dannykopping
Basically we have 3 actions:
ReadTemplate.All()UseTemplate.All()ViewInsightsTemplate.All()
Read is for reading the content of template
Use is for creating workspaces
ViewInsights is for gathering stats & metrics across templates
Looks like GetPresetsBackoff falls into ViewInsights category - because we gathering statistics across all template presets, calculating number of failed builds, etc...
I had a discussion with Steven regarding this, but I'm open to suggestions.
There was a problem hiding this comment.
Repurposing other RBAC roles just because they overlap logically feels like a bad design choice.
Each feature should have its own RBAC policy.
There was a problem hiding this comment.
We can introduce new resource type here: https://github.com/coder/coder/blob/main/coderd/rbac/object_gen.go
Then use it like this:
if err := q.authorizeContext(ctx, policy.ActionViewInsights, rbac.ResourcePrebuilds.All()); err != nil {}Optionally introduce new action type as well, and use it like this:
if err := q.authorizeContext(ctx, policy.ActionCollectStatistics, rbac.ResourcePrebuilds.All()); err != nil {}But I think we don't want to introduce too many action types.
cc @Emyrk
There was a problem hiding this comment.
We can do this in a follow-up, by the way 👍
There was a problem hiding this comment.
I don't have all the context for prebuilds. Can we throw a quick disc chat on the calendar?
e88e301 to
0fdd096
Compare
ab90612 to
5c60065
Compare
dannykopping
left a comment
There was a problem hiding this comment.
Looking good so far, but I don't see any metric added which we previously discussed.
Given the size of the PR, it can be a follow-up.
Relates to #17432
Part 1:
Notes:
GetPresetsAtFailureLimitSQL query is added, which is similar toGetPresetsBackoff, they use same CTEs:filtered_builds,time_sorted_builds, but they are still different.Query is executed on every loop iteration. We can consider marking specific preset as permanently failed as an optimization to avoid executing query on every loop iteration. But I decided don't do it for now.
By default
FailureHardLimitis set to 3.FailureHardLimitis configurable. Setting it to zero - means that hard limit is disabled.Part 2
Notes:
PrebuildFailureLimitReachednotification is added.log.Warnon every loop iteration.validation_failednot used in this PR, but I think it will be used in next one, so I wanted to save us an extra migration.Latest notification views: