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
@@ -0,0 +1,64 @@
|
||||
package wsbuilder_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/dynamicparameters"
|
||||
"github.com/coder/coder/v2/coderd/wsbuilder"
|
||||
)
|
||||
|
||||
func TestBuildErrorResponseDelegation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("plain_error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
be := wsbuilder.BuildError{
|
||||
Status: http.StatusBadRequest,
|
||||
Message: "bad",
|
||||
Wrapped: xerrors.New("oops"),
|
||||
}
|
||||
|
||||
status, resp := be.Response()
|
||||
require.Equal(t, http.StatusBadRequest, status)
|
||||
require.Equal(t, "bad", resp.Message)
|
||||
require.Contains(t, resp.Detail, "oops")
|
||||
require.Empty(t, resp.Validations)
|
||||
})
|
||||
|
||||
t.Run("responder_error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
inner := &dynamicparameters.DiagnosticError{
|
||||
Message: "resolve parameters",
|
||||
KeyedDiagnostics: map[string]hcl.Diagnostics{
|
||||
"param1": {
|
||||
{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "required parameter",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
be := wsbuilder.BuildError{
|
||||
Status: http.StatusBadRequest,
|
||||
Message: "build error wrapper",
|
||||
Wrapped: inner,
|
||||
}
|
||||
|
||||
status, resp := be.Response()
|
||||
|
||||
// Should delegate to the inner DiagnosticError's response.
|
||||
innerStatus, innerResp := inner.Response()
|
||||
require.Equal(t, innerStatus, status)
|
||||
require.Equal(t, innerResp.Message, resp.Message)
|
||||
require.Len(t, resp.Validations, 1)
|
||||
require.Equal(t, "param1", resp.Validations[0].Field)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user