Skip to content

Commit

Permalink
Test for error injection clients (cadence-workflow#5515)
Browse files Browse the repository at this point in the history
* switch errorinjectors to autogenerated approach
  • Loading branch information
3vilhamster authored Dec 21, 2023
1 parent feb54ff commit 1c2df58
Show file tree
Hide file tree
Showing 17 changed files with 2,657 additions and 2,525 deletions.
3 changes: 3 additions & 0 deletions common/log/tag/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ var (

StoreOperationCreateTasks = storeOperation("create-tasks")
StoreOperationGetTasks = storeOperation("get-tasks")
StoreOperationGetOrphanTasks = storeOperation("get-orphan-tasks")
StoreOperationCompleteTask = storeOperation("complete-task")
StoreOperationCompleteTasksLessThan = storeOperation("complete-tasks-less-than")
StoreOperationLeaseTaskList = storeOperation("lease-task-list")
Expand Down Expand Up @@ -248,6 +249,8 @@ var (
StoreOperationListWorkflowExecutions = storeOperation("list-wf-executions")
StoreOperationScanWorkflowExecutions = storeOperation("scan-wf-executions")
StoreOperationCountWorkflowExecutions = storeOperation("count-wf-executions")
StoreOperationDeleteUninitializedWorkflowExecution = storeOperation("delete-uninitialized-wf-execution")
StoreOperationRecordWorkflowExecutionUninitialized = storeOperation("record-wf-execution-uninitialized")

StoreOperationAppendHistoryNodes = storeOperation("append-history-nodes")
StoreOperationReadHistoryBranch = storeOperation("read-history-branch")
Expand Down
17 changes: 9 additions & 8 deletions common/persistence/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/uber/cadence/common/metrics"
p "github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/elasticsearch"
"github.com/uber/cadence/common/persistence/errorinjectors"
"github.com/uber/cadence/common/persistence/nosql"
pinotVisibility "github.com/uber/cadence/common/persistence/pinot"
"github.com/uber/cadence/common/persistence/ratelimited"
Expand Down Expand Up @@ -166,7 +167,7 @@ func (f *factoryImpl) NewTaskManager() (p.TaskManager, error) {
}
result := p.NewTaskManager(store)
if errorRate := f.config.ErrorInjectionRate(); errorRate != 0 {
result = p.NewTaskPersistenceErrorInjectionClient(result, errorRate, f.logger)
result = errorinjectors.NewTaskManager(result, errorRate, f.logger)
}
if ds.ratelimit != nil {
result = ratelimited.NewTaskManager(result, ds.ratelimit)
Expand All @@ -186,7 +187,7 @@ func (f *factoryImpl) NewShardManager() (p.ShardManager, error) {
}
result := p.NewShardManager(store)
if errorRate := f.config.ErrorInjectionRate(); errorRate != 0 {
result = p.NewShardPersistenceErrorInjectionClient(result, errorRate, f.logger)
result = errorinjectors.NewShardManager(result, errorRate, f.logger)
}
if ds.ratelimit != nil {
result = ratelimited.NewShardManager(result, ds.ratelimit)
Expand All @@ -206,7 +207,7 @@ func (f *factoryImpl) NewHistoryManager() (p.HistoryManager, error) {
}
result := p.NewHistoryV2ManagerImpl(store, f.logger, f.config.TransactionSizeLimit)
if errorRate := f.config.ErrorInjectionRate(); errorRate != 0 {
result = p.NewHistoryPersistenceErrorInjectionClient(result, errorRate, f.logger)
result = errorinjectors.NewHistoryManager(result, errorRate, f.logger)
}
if ds.ratelimit != nil {
result = ratelimited.NewHistoryManager(result, ds.ratelimit)
Expand All @@ -228,7 +229,7 @@ func (f *factoryImpl) NewDomainManager() (p.DomainManager, error) {
}
result := p.NewDomainManagerImpl(store, f.logger)
if errorRate := f.config.ErrorInjectionRate(); errorRate != 0 {
result = p.NewDomainPersistenceErrorInjectionClient(result, errorRate, f.logger)
result = errorinjectors.NewDomainManager(result, errorRate, f.logger)
}
if ds.ratelimit != nil {
result = ratelimited.NewDomainManager(result, ds.ratelimit)
Expand All @@ -248,7 +249,7 @@ func (f *factoryImpl) NewExecutionManager(shardID int) (p.ExecutionManager, erro
}
result := p.NewExecutionManagerImpl(store, f.logger)
if errorRate := f.config.ErrorInjectionRate(); errorRate != 0 {
result = p.NewWorkflowExecutionPersistenceErrorInjectionClient(result, errorRate, f.logger)
result = errorinjectors.NewExecutionManager(result, errorRate, f.logger)
}
if ds.ratelimit != nil {
result = ratelimited.NewExecutionManager(result, ds.ratelimit)
Expand Down Expand Up @@ -392,7 +393,7 @@ func (f *factoryImpl) newDBVisibilityManager(
}
result := p.NewVisibilityManagerImpl(store, f.logger)
if errorRate := f.config.ErrorInjectionRate(); errorRate != 0 {
result = p.NewVisibilityPersistenceErrorInjectionClient(result, errorRate, f.logger)
result = errorinjectors.NewVisibilityManager(result, errorRate, f.logger)
}
if ds.ratelimit != nil {
result = ratelimited.NewVisibilityManager(result, ds.ratelimit)
Expand All @@ -419,7 +420,7 @@ func (f *factoryImpl) NewDomainReplicationQueueManager() (p.QueueManager, error)
}
result := p.NewQueueManager(store)
if errorRate := f.config.ErrorInjectionRate(); errorRate != 0 {
result = p.NewQueuePersistenceErrorInjectionClient(result, errorRate, f.logger)
result = errorinjectors.NewQueueManager(result, errorRate, f.logger)
}
if ds.ratelimit != nil {
result = ratelimited.NewQueueManager(result, ds.ratelimit)
Expand All @@ -439,7 +440,7 @@ func (f *factoryImpl) NewConfigStoreManager() (p.ConfigStoreManager, error) {
}
result := p.NewConfigStoreManagerImpl(store, f.logger)
if errorRate := f.config.ErrorInjectionRate(); errorRate != 0 {
result = p.NewConfigStoreErrorInjectionPersistenceClient(result, errorRate, f.logger)
result = errorinjectors.NewConfigStoreManager(result, errorRate, f.logger)
}
if ds.ratelimit != nil {
result = ratelimited.NewConfigStoreManager(result, ds.ratelimit)
Expand Down
97 changes: 10 additions & 87 deletions common/persistence/dataManagerInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// Geneate rate limiter wrappers.
//go:generate mockgen -package $GOPACKAGE -destination dataManagerInterfaces_mock.go -self_package github.com/uber/cadence/common/persistence github.com/uber/cadence/common/persistence Task,ShardManager,ExecutionManager,ExecutionManagerFactory,TaskManager,HistoryManager,DomainManager,QueueManager,ConfigStoreManager
//go:generate gowrap gen -g -p . -i ConfigStoreManager -t ./ratelimited/template/ratelimited.tmpl -o ratelimited/configstore.go
//go:generate gowrap gen -g -p . -i DomainManager -t ./ratelimited/template/ratelimited.tmpl -o ratelimited/domain.go
Expand All @@ -28,6 +29,15 @@
//go:generate gowrap gen -g -p . -i TaskManager -t ./ratelimited/template/ratelimited.tmpl -o ratelimited/task.go
//go:generate gowrap gen -g -p . -i ShardManager -t ./ratelimited/template/ratelimited.tmpl -o ratelimited/shard.go

// Geneate error injector wrappers.
//go:generate gowrap gen -g -p . -i ConfigStoreManager -t ./errorinjectors/template/errorinjector.tmpl -o errorinjectors/configstore.go
//go:generate gowrap gen -g -p . -i ShardManager -t ./errorinjectors/template/errorinjector.tmpl -o errorinjectors/shard.go
//go:generate gowrap gen -g -p . -i ExecutionManager -t ./errorinjectors/template/errorinjector.tmpl -o errorinjectors/execution.go
//go:generate gowrap gen -g -p . -i TaskManager -t ./errorinjectors/template/errorinjector.tmpl -o errorinjectors/task.go
//go:generate gowrap gen -g -p . -i HistoryManager -t ./errorinjectors/template/errorinjector.tmpl -o errorinjectors/history.go
//go:generate gowrap gen -g -p . -i DomainManager -t ./errorinjectors/template/errorinjector.tmpl -o errorinjectors/domain.go
//go:generate gowrap gen -g -p . -i QueueManager -t ./errorinjectors/template/errorinjector.tmpl -o errorinjectors/queue.go

package persistence

import (
Expand Down Expand Up @@ -233,57 +243,6 @@ const (
)

type (
// InvalidPersistenceRequestError represents invalid request to persistence
InvalidPersistenceRequestError struct {
Msg string
}

// CurrentWorkflowConditionFailedError represents a failed conditional update for current workflow record
CurrentWorkflowConditionFailedError struct {
Msg string
}

// ConditionFailedError represents a failed conditional update for execution record
ConditionFailedError struct {
Msg string
}

// ShardAlreadyExistError is returned when conditionally creating a shard fails
ShardAlreadyExistError struct {
Msg string
}

// ShardOwnershipLostError is returned when conditional update fails due to RangeID for the shard
ShardOwnershipLostError struct {
ShardID int
Msg string
}

// WorkflowExecutionAlreadyStartedError is returned when creating a new workflow failed.
WorkflowExecutionAlreadyStartedError struct {
Msg string
StartRequestID string
RunID string
State int
CloseStatus int
LastWriteVersion int64
}

// TimeoutError is returned when a write operation fails due to a timeout
TimeoutError struct {
Msg string
}

// DBUnavailableError is returned when the database is unavailable, could be for various reasons.
DBUnavailableError struct {
Msg string
}

// TransactionSizeLimitError is returned when the transaction size is too large
TransactionSizeLimitError struct {
Msg string
}

// ShardInfo describes a shard
ShardInfo struct {
ShardID int `json:"shard_id"`
Expand Down Expand Up @@ -1894,42 +1853,6 @@ type (
}
)

func (e *InvalidPersistenceRequestError) Error() string {
return e.Msg
}

func (e *CurrentWorkflowConditionFailedError) Error() string {
return e.Msg
}

func (e *ConditionFailedError) Error() string {
return e.Msg
}

func (e *ShardAlreadyExistError) Error() string {
return e.Msg
}

func (e *ShardOwnershipLostError) Error() string {
return e.Msg
}

func (e *WorkflowExecutionAlreadyStartedError) Error() string {
return e.Msg
}

func (e *TimeoutError) Error() string {
return e.Msg
}

func (e *DBUnavailableError) Error() string {
return e.Msg
}

func (e *TransactionSizeLimitError) Error() string {
return e.Msg
}

// IsTimeoutError check whether error is TimeoutError
func IsTimeoutError(err error) bool {
_, ok := err.(*TimeoutError)
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/dataVisibilityManagerInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
// THE SOFTWARE.

//go:generate mockgen -package $GOPACKAGE -destination dataVisibilityManagerInterfaces_mock.go -self_package github.com/uber/cadence/common/persistence github.com/uber/cadence/common/persistence VisibilityManager
// Generate rate limiter wrapper.
//go:generate gowrap gen -g -p . -i VisibilityManager -t ./ratelimited/template/ratelimited.tmpl -o ratelimited/visibility.go

// Generate error injection wrapper.
//go:generate gowrap gen -g -p . -i VisibilityManager -t ./errorinjectors/template/errorinjector.tmpl -o errorinjectors/visibility.go

package persistence

import (
Expand Down
89 changes: 89 additions & 0 deletions common/persistence/errorinjectors/configstore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1c2df58

Please sign in to comment.