mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: mark presets as validation_failed to prevent endless prebuild retries (#22085)
## Description - Updates `wsbuilder` to return a `BuildError` with `http.StatusBadRequest` to signify a "validation error" on missing or invalid parameters - Adds a short-circuit in `prebuilds.StoreReconciler` to mark presets for which creating a build returns a "validation error" as "validation failed" and skip further attempts to reconcile. - Adds a test to verify the above - Introduces a new Prometheus metric `coderd_prebuilt_workspaces_preset_validation_failed` to track the above Closes: https://github.com/coder/coder/issues/21237 --------- Co-authored-by: Cian Johnston <cian@coder.com>
This commit is contained in:
co-authored by
Cian Johnston
parent
dea451de41
commit
ca234f346d
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/dynamicparameters"
|
||||
"github.com/coder/coder/v2/coderd/files"
|
||||
"github.com/coder/coder/v2/coderd/httpapi"
|
||||
"github.com/coder/coder/v2/coderd/httpapi/httperror"
|
||||
"github.com/coder/coder/v2/coderd/prebuilds"
|
||||
"github.com/coder/coder/v2/coderd/provisionerdserver"
|
||||
"github.com/coder/coder/v2/coderd/rbac"
|
||||
@@ -280,6 +281,13 @@ func (e BuildError) Unwrap() error {
|
||||
}
|
||||
|
||||
func (e BuildError) Response() (int, codersdk.Response) {
|
||||
// If the wrapped error knows how to produce its own response
|
||||
// (e.g. DiagnosticError with Validations), prefer that over
|
||||
// the generic BuildError response.
|
||||
if inner, ok := httperror.IsResponder(e.Wrapped); ok {
|
||||
return inner.Response()
|
||||
}
|
||||
|
||||
return e.Status, codersdk.Response{
|
||||
Message: e.Message,
|
||||
Detail: e.Error(),
|
||||
@@ -875,7 +883,7 @@ func (b *Builder) getDynamicParameters() (names, values []string, err error) {
|
||||
b.richParameterValues,
|
||||
presetParameterValues)
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("resolve parameters: %w", err)
|
||||
return nil, nil, BuildError{http.StatusBadRequest, "resolve parameters", err}
|
||||
}
|
||||
|
||||
names = make([]string, 0, len(buildValues))
|
||||
@@ -1112,7 +1120,7 @@ func (b *Builder) getDynamicProvisionerTags() (map[string]string, error) {
|
||||
output, diags := render.Render(b.ctx, b.workspace.OwnerID, vals)
|
||||
tagErr := dynamicparameters.CheckTags(output, diags)
|
||||
if tagErr != nil {
|
||||
return nil, tagErr
|
||||
return nil, BuildError{http.StatusBadRequest, "workspace tags validation failed", tagErr}
|
||||
}
|
||||
|
||||
for k, v := range output.WorkspaceTags.Tags() {
|
||||
|
||||
Reference in New Issue
Block a user