mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
feat: save last occurrence of failed events and fix instance filtering (#4710)
* fix: filter failed events and current sequence correctly * fix failed events sorting column * feat: save last occurrence of failed event * fix failedEvents query and update sql statements * change sql statement to only create index * fix linting * fix linting * Update internal/query/failed_events.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * update job name on test-docs to match the one from test-code Co-authored-by: Silvan <silvan.reusser@gmail.com>
This commit is contained in:
@@ -28,8 +28,8 @@ func expectFailureCount(tableName string, projectionName, instanceID string, fai
|
||||
|
||||
func expectUpdateFailureCount(tableName string, projectionName, instanceID string, seq, failureCount uint64) func(sqlmock.Sqlmock) {
|
||||
return func(m sqlmock.Sqlmock) {
|
||||
m.ExpectExec(`INSERT INTO `+tableName+` \(projection_name, failed_sequence, failure_count, error, instance_id\) VALUES \(\$1, \$2, \$3, \$4\, \$5\) ON CONFLICT \(projection_name, failed_sequence, instance_id\) DO UPDATE SET failure_count = EXCLUDED\.failure_count, error = EXCLUDED\.error`).
|
||||
WithArgs(projectionName, seq, failureCount, sqlmock.AnyArg(), instanceID).WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
m.ExpectExec(`INSERT INTO `+tableName+` \(projection_name, failed_sequence, failure_count, error, instance_id, last_failed\) VALUES \(\$1, \$2, \$3, \$4\, \$5\, \$6\) ON CONFLICT \(projection_name, failed_sequence, instance_id\) DO UPDATE SET failure_count = EXCLUDED\.failure_count, error = EXCLUDED\.error, last_failed = EXCLUDED\.last_failed`).
|
||||
WithArgs(projectionName, seq, failureCount, sqlmock.AnyArg(), instanceID, "NOW()").WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -11,9 +11,9 @@ import (
|
||||
|
||||
const (
|
||||
setFailureCountStmtFormat = "INSERT INTO %s" +
|
||||
" (projection_name, failed_sequence, failure_count, error, instance_id)" +
|
||||
" VALUES ($1, $2, $3, $4, $5) ON CONFLICT (projection_name, failed_sequence, instance_id)" +
|
||||
" DO UPDATE SET failure_count = EXCLUDED.failure_count, error = EXCLUDED.error"
|
||||
" (projection_name, failed_sequence, failure_count, error, instance_id, last_failed)" +
|
||||
" VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (projection_name, failed_sequence, instance_id)" +
|
||||
" DO UPDATE SET failure_count = EXCLUDED.failure_count, error = EXCLUDED.error, last_failed = EXCLUDED.last_failed"
|
||||
failureCountStmtFormat = "WITH failures AS (SELECT failure_count FROM %s WHERE projection_name = $1 AND failed_sequence = $2 AND instance_id = $3)" +
|
||||
" SELECT COALESCE((SELECT failure_count FROM failures), 0) AS failure_count"
|
||||
)
|
||||
@@ -43,7 +43,7 @@ func (h *StatementHandler) failureCount(tx *sql.Tx, seq uint64, instanceID strin
|
||||
}
|
||||
|
||||
func (h *StatementHandler) setFailureCount(tx *sql.Tx, seq uint64, count uint, err error, instanceID string) error {
|
||||
_, dbErr := tx.Exec(h.setFailureCountStmt, h.ProjectionName, seq, count, err.Error(), instanceID)
|
||||
_, dbErr := tx.Exec(h.setFailureCountStmt, h.ProjectionName, seq, count, err.Error(), instanceID, "NOW()")
|
||||
if dbErr != nil {
|
||||
return errors.ThrowInternal(dbErr, "CRDB-4Ht4x", "set failure count failed")
|
||||
}
|
||||
|
@@ -135,7 +135,7 @@ func (s *spooledHandler) awaitError(cancel func(), errs chan error, workerID str
|
||||
select {
|
||||
case err := <-errs:
|
||||
cancel()
|
||||
logging.Log("SPOOL-OT8di").OnError(err).WithField("view", s.ViewModel()).WithField("worker", workerID).Debug("load canceled")
|
||||
logging.OnError(err).WithField("view", s.ViewModel()).WithField("worker", workerID).Debug("load canceled")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,7 @@ func HandleError(event *models.Event, failedErr error,
|
||||
failedEvent.FailureCount++
|
||||
failedEvent.ErrMsg = failedErr.Error()
|
||||
failedEvent.InstanceID = event.InstanceID
|
||||
failedEvent.LastFailed = time.Now()
|
||||
err = processFailedEvent(failedEvent)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -17,6 +17,10 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
var (
|
||||
testNow = time.Now()
|
||||
)
|
||||
|
||||
type testHandler struct {
|
||||
cycleDuration time.Duration
|
||||
processSleep time.Duration
|
||||
@@ -429,6 +433,7 @@ func TestHandleError(t *testing.T) {
|
||||
FailureCount: 6,
|
||||
ViewName: "super.table",
|
||||
InstanceID: instanceID,
|
||||
LastFailed: testNow,
|
||||
}, nil
|
||||
},
|
||||
errorCountUntilSkip: 5,
|
||||
@@ -449,6 +454,7 @@ func TestHandleError(t *testing.T) {
|
||||
FailureCount: 5,
|
||||
ViewName: "super.table",
|
||||
InstanceID: instanceID,
|
||||
LastFailed: testNow,
|
||||
}, nil
|
||||
},
|
||||
errorCountUntilSkip: 6,
|
||||
@@ -469,6 +475,7 @@ func TestHandleError(t *testing.T) {
|
||||
FailureCount: 3,
|
||||
ViewName: "super.table",
|
||||
InstanceID: instanceID,
|
||||
LastFailed: testNow,
|
||||
}, nil
|
||||
},
|
||||
errorCountUntilSkip: 5,
|
||||
|
Reference in New Issue
Block a user