mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +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:
@@ -1,9 +1,13 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type FailedEvent struct {
|
||||
Database string
|
||||
ViewName string
|
||||
FailedSequence uint64
|
||||
FailureCount uint64
|
||||
ErrMsg string
|
||||
InstanceID string
|
||||
LastFailed time.Time
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
@@ -11,11 +12,47 @@ import (
|
||||
)
|
||||
|
||||
type FailedEvent struct {
|
||||
ViewName string `gorm:"column:view_name;primary_key"`
|
||||
FailedSequence uint64 `gorm:"column:failed_sequence;primary_key"`
|
||||
FailureCount uint64 `gorm:"column:failure_count"`
|
||||
ErrMsg string `gorm:"column:err_msg"`
|
||||
InstanceID string `gorm:"column:instance_id"`
|
||||
ViewName string `gorm:"column:view_name;primary_key"`
|
||||
FailedSequence uint64 `gorm:"column:failed_sequence;primary_key"`
|
||||
FailureCount uint64 `gorm:"column:failure_count"`
|
||||
ErrMsg string `gorm:"column:err_msg"`
|
||||
InstanceID string `gorm:"column:instance_id"`
|
||||
LastFailed time.Time `gorm:"column:last_failed"`
|
||||
}
|
||||
|
||||
type failedEventSearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn failedEventSearchKey
|
||||
Asc bool
|
||||
Queries []*FailedEventSearchQuery
|
||||
}
|
||||
|
||||
func (f failedEventSearchRequest) GetLimit() uint64 {
|
||||
return f.Limit
|
||||
}
|
||||
|
||||
func (f failedEventSearchRequest) GetOffset() uint64 {
|
||||
return f.Offset
|
||||
}
|
||||
|
||||
func (f failedEventSearchRequest) GetSortingColumn() ColumnKey {
|
||||
if f.SortingColumn == failedEventSearchKey(FailedEventKeyUndefined) {
|
||||
return nil
|
||||
}
|
||||
return f.SortingColumn
|
||||
}
|
||||
|
||||
func (f failedEventSearchRequest) GetAsc() bool {
|
||||
return f.Asc
|
||||
}
|
||||
|
||||
func (f failedEventSearchRequest) GetQueries() []SearchQuery {
|
||||
result := make([]SearchQuery, len(f.Queries))
|
||||
for i, q := range f.Queries {
|
||||
result[i] = q
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
type FailedEventSearchQuery struct {
|
||||
@@ -43,6 +80,7 @@ const (
|
||||
FailedEventKeyViewName
|
||||
FailedEventKeyFailedSequence
|
||||
FailedEventKeyInstanceID
|
||||
FailedEventKeyLastFailed
|
||||
)
|
||||
|
||||
type failedEventSearchKey FailedEventSearchKey
|
||||
@@ -55,6 +93,8 @@ func (key failedEventSearchKey) ToColumnName() string {
|
||||
return "failed_sequence"
|
||||
case FailedEventKeyInstanceID:
|
||||
return "instance_id"
|
||||
case FailedEventKeyLastFailed:
|
||||
return "last_failed"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
@@ -65,6 +105,7 @@ func FailedEventFromModel(failedEvent *view_model.FailedEvent) *FailedEvent {
|
||||
ViewName: failedEvent.Database + "." + failedEvent.ViewName,
|
||||
FailureCount: failedEvent.FailureCount,
|
||||
FailedSequence: failedEvent.FailedSequence,
|
||||
InstanceID: failedEvent.InstanceID,
|
||||
ErrMsg: failedEvent.ErrMsg,
|
||||
}
|
||||
}
|
||||
@@ -76,6 +117,7 @@ func FailedEventToModel(failedEvent *FailedEvent) *view_model.FailedEvent {
|
||||
FailureCount: failedEvent.FailureCount,
|
||||
FailedSequence: failedEvent.FailedSequence,
|
||||
ErrMsg: failedEvent.ErrMsg,
|
||||
LastFailed: failedEvent.LastFailed,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,9 +165,13 @@ func LatestFailedEvent(db *gorm.DB, table, viewName, instanceID string, sequence
|
||||
|
||||
}
|
||||
|
||||
func AllFailedEvents(db *gorm.DB, table string) ([]*FailedEvent, error) {
|
||||
func AllFailedEvents(db *gorm.DB, table, instanceID string) ([]*FailedEvent, error) {
|
||||
queries := make([]*FailedEventSearchQuery, 0, 1)
|
||||
if instanceID != "" {
|
||||
queries = append(queries, &FailedEventSearchQuery{Key: FailedEventKeyInstanceID, Method: domain.SearchMethodEquals, Value: instanceID})
|
||||
}
|
||||
failedEvents := make([]*FailedEvent, 0)
|
||||
query := PrepareSearchQuery(table, GeneralSearchRequest{})
|
||||
query := PrepareSearchQuery(table, &failedEventSearchRequest{SortingColumn: failedEventSearchKey(FailedEventKeyLastFailed), Queries: queries})
|
||||
_, err := query(db, &failedEvents)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -192,9 +192,13 @@ func LatestSequences(db *gorm.DB, table, viewName string, instanceIDs ...string)
|
||||
return sequences, nil
|
||||
}
|
||||
|
||||
func AllCurrentSequences(db *gorm.DB, table string) ([]*CurrentSequence, error) {
|
||||
func AllCurrentSequences(db *gorm.DB, table, instanceID string) ([]*CurrentSequence, error) {
|
||||
queries := make([]sequenceSearchQuery, 0, 1)
|
||||
if instanceID != "" {
|
||||
queries = append(queries, sequenceSearchQuery{key: sequenceSearchKey(SequenceSearchKeyInstanceID), value: instanceID})
|
||||
}
|
||||
sequences := make([]*CurrentSequence, 0)
|
||||
query := PrepareSearchQuery(table, GeneralSearchRequest{})
|
||||
query := PrepareSearchQuery(table, &sequenceSearchRequest{queries: queries})
|
||||
_, err := query(db, &sequences)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user