From 0ce445f6921cb3555344164693422e986526b0ce Mon Sep 17 00:00:00 2001 From: Mikhail Montsev Date: Wed, 10 Jan 2024 21:45:38 +0100 Subject: [PATCH] [Disk Manager] internal/pkg/tasks should not depend on internal/pkg/errors (#104) --- .../internal/pkg/auth/credentials.go | 2 +- .../internal/pkg/client/client.go | 2 +- .../internal/pkg/clients/nbs/factory.go | 2 +- .../pkg/clients/nbs/multi_zone_client.go | 2 +- .../internal/pkg/clients/nbs/session.go | 2 +- .../internal/pkg/clients/nfs/factory.go | 2 +- .../internal/pkg/dataplane/nbs/common.go | 2 +- .../snapshot/storage/compressor/compressor.go | 2 +- .../internal/pkg/errors/errors.go | 130 ------------------ .../disk_manager/internal/pkg/errors/ya.make | 7 - .../internal/pkg/persistence/s3.go | 2 +- .../internal/pkg/persistence/s3_metrics.go | 2 +- .../internal/pkg/persistence/ydb.go | 2 +- .../internal/pkg/persistence/ydb_metrics.go | 2 +- .../internal/pkg/tasks/errors/errors.go | 81 +++++++++-- cloud/disk_manager/internal/pkg/ya.make | 1 - 16 files changed, 80 insertions(+), 163 deletions(-) delete mode 100644 cloud/disk_manager/internal/pkg/errors/errors.go delete mode 100644 cloud/disk_manager/internal/pkg/errors/ya.make diff --git a/cloud/disk_manager/internal/pkg/auth/credentials.go b/cloud/disk_manager/internal/pkg/auth/credentials.go index ad41cda206f..e19aaf4cd09 100644 --- a/cloud/disk_manager/internal/pkg/auth/credentials.go +++ b/cloud/disk_manager/internal/pkg/auth/credentials.go @@ -7,8 +7,8 @@ import ( "hash/crc32" auth_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/auth/config" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/pkg/auth" metadata "github.com/ydb-platform/ydb-go-yc-metadata" "github.com/ydb-platform/ydb-go-yc-metadata/trace" diff --git a/cloud/disk_manager/internal/pkg/client/client.go b/cloud/disk_manager/internal/pkg/client/client.go index fc91992667c..35d4d9903bb 100644 --- a/cloud/disk_manager/internal/pkg/client/client.go +++ b/cloud/disk_manager/internal/pkg/client/client.go @@ -15,8 +15,8 @@ import ( "github.com/ydb-platform/nbs/cloud/disk_manager/api/yandex/cloud/priv/disk_manager/v1" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/api" client_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/configs/client/config" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" sdk_client "github.com/ydb-platform/nbs/cloud/disk_manager/pkg/client" sdk_client_config "github.com/ydb-platform/nbs/cloud/disk_manager/pkg/client/config" "google.golang.org/grpc" diff --git a/cloud/disk_manager/internal/pkg/clients/nbs/factory.go b/cloud/disk_manager/internal/pkg/clients/nbs/factory.go index 51b76a375dc..f833905eb26 100644 --- a/cloud/disk_manager/internal/pkg/clients/nbs/factory.go +++ b/cloud/disk_manager/internal/pkg/clients/nbs/factory.go @@ -8,9 +8,9 @@ import ( nbs_client "github.com/ydb-platform/nbs/cloud/blockstore/public/sdk/go/client" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/auth" nbs_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/clients/nbs/config" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" coreprotos "github.com/ydb-platform/nbs/cloud/storage/core/protos" "golang.org/x/exp/maps" "google.golang.org/grpc" diff --git a/cloud/disk_manager/internal/pkg/clients/nbs/multi_zone_client.go b/cloud/disk_manager/internal/pkg/clients/nbs/multi_zone_client.go index 1432f345154..043c557db8c 100644 --- a/cloud/disk_manager/internal/pkg/clients/nbs/multi_zone_client.go +++ b/cloud/disk_manager/internal/pkg/clients/nbs/multi_zone_client.go @@ -5,8 +5,8 @@ import ( "github.com/ydb-platform/nbs/cloud/blockstore/public/api/protos" nbs_client "github.com/ydb-platform/nbs/cloud/blockstore/public/sdk/go/client" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/cloud/disk_manager/internal/pkg/clients/nbs/session.go b/cloud/disk_manager/internal/pkg/clients/nbs/session.go index 6187788bfde..2e8b2822087 100644 --- a/cloud/disk_manager/internal/pkg/clients/nbs/session.go +++ b/cloud/disk_manager/internal/pkg/clients/nbs/session.go @@ -11,9 +11,9 @@ import ( "github.com/ydb-platform/nbs/cloud/blockstore/public/api/protos" nbs_client "github.com/ydb-platform/nbs/cloud/blockstore/public/sdk/go/client" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/common" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/cloud/disk_manager/internal/pkg/clients/nfs/factory.go b/cloud/disk_manager/internal/pkg/clients/nfs/factory.go index 8bfe0f8356c..7c7274ee82f 100644 --- a/cloud/disk_manager/internal/pkg/clients/nfs/factory.go +++ b/cloud/disk_manager/internal/pkg/clients/nfs/factory.go @@ -8,9 +8,9 @@ import ( "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/auth" nfs_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/clients/nfs/config" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/common" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" nfs_client "github.com/ydb-platform/nbs/cloud/filestore/public/sdk/go/client" "golang.org/x/exp/maps" ) diff --git a/cloud/disk_manager/internal/pkg/dataplane/nbs/common.go b/cloud/disk_manager/internal/pkg/dataplane/nbs/common.go index 18275ef9b97..44f06b27944 100644 --- a/cloud/disk_manager/internal/pkg/dataplane/nbs/common.go +++ b/cloud/disk_manager/internal/pkg/dataplane/nbs/common.go @@ -1,7 +1,7 @@ package nbs import ( - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/cloud/disk_manager/internal/pkg/dataplane/snapshot/storage/compressor/compressor.go b/cloud/disk_manager/internal/pkg/dataplane/snapshot/storage/compressor/compressor.go index d3bb4a1b91c..34c376af5a6 100644 --- a/cloud/disk_manager/internal/pkg/dataplane/snapshot/storage/compressor/compressor.go +++ b/cloud/disk_manager/internal/pkg/dataplane/snapshot/storage/compressor/compressor.go @@ -12,7 +12,7 @@ import ( zstdcgo "github.com/DataDog/zstd" "github.com/pierrec/lz4" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/dataplane/snapshot/storage/metrics" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" "github.com/ydb-platform/nbs/library/go/blockcodecs" _ "github.com/ydb-platform/nbs/library/go/blockcodecs/all" ) diff --git a/cloud/disk_manager/internal/pkg/errors/errors.go b/cloud/disk_manager/internal/pkg/errors/errors.go deleted file mode 100644 index f60a5fc4cd0..00000000000 --- a/cloud/disk_manager/internal/pkg/errors/errors.go +++ /dev/null @@ -1,130 +0,0 @@ -package errors - -import ( - "errors" - "fmt" - "runtime/debug" -) - -//////////////////////////////////////////////////////////////////////////////// - -func New(text string) error { - return errors.New(text) -} - -func As(err error, target interface{}) bool { - return errors.As(err, target) -} - -func Is(err, target error) bool { - return errors.Is(err, target) -} - -//////////////////////////////////////////////////////////////////////////////// - -type RetriableError struct { - Err error - IgnoreRetryLimit bool -} - -func NewRetriableError(err error) *RetriableError { - return &RetriableError{ - Err: err, - } -} - -func NewRetriableErrorf(format string, a ...any) *RetriableError { - return NewRetriableError(fmt.Errorf(format, a...)) -} - -func NewRetriableErrorWithIgnoreRetryLimit(err error) *RetriableError { - return &RetriableError{ - Err: err, - IgnoreRetryLimit: true, - } -} - -func NewRetriableErrorWithIgnoreRetryLimitf(format string, a ...any) *RetriableError { - return NewRetriableErrorWithIgnoreRetryLimit(fmt.Errorf(format, a...)) -} - -func NewEmptyRetriableError() *RetriableError { - return &RetriableError{} -} - -func (e *RetriableError) Error() string { - return fmt.Sprintf("Retriable error, IgnoreRetryLimit=%v: %v", e.IgnoreRetryLimit, e.Err) -} - -func (e *RetriableError) Unwrap() error { - return e.Err -} - -func (e *RetriableError) Is(target error) bool { - t, ok := target.(*RetriableError) - if !ok { - return false - } - - return t.Err == nil || (e.Err == t.Err) -} - -//////////////////////////////////////////////////////////////////////////////// - -type NonRetriableError struct { - Err error - Silent bool - stackTrace []byte -} - -func NewNonRetriableError(err error) *NonRetriableError { - return newNonRetriableError(err, false) -} - -func NewNonRetriableErrorf(format string, a ...any) *NonRetriableError { - return newNonRetriableError(fmt.Errorf(format, a...), false) -} - -func NewSilentNonRetriableError(err error) *NonRetriableError { - return newNonRetriableError(err, true) -} - -func NewSilentNonRetriableErrorf(format string, a ...any) *NonRetriableError { - return newNonRetriableError(fmt.Errorf(format, a...), true) -} - -func NewEmptyNonRetriableError() *NonRetriableError { - return newNonRetriableError(nil, false) -} - -func newNonRetriableError(err error, silent bool) *NonRetriableError { - return &NonRetriableError{ - Err: err, - Silent: silent, - stackTrace: debug.Stack(), - } -} - -func (e *NonRetriableError) Error() string { - msg := fmt.Sprintf("Non retriable error, Silent=%v: %v", e.Silent, e.Err) - return appendStackTrace(msg, e.stackTrace) -} - -func (e *NonRetriableError) Unwrap() error { - return e.Err -} - -func (e *NonRetriableError) Is(target error) bool { - t, ok := target.(*NonRetriableError) - if !ok { - return false - } - - return t.Err == nil || (e.Err == t.Err) -} - -//////////////////////////////////////////////////////////////////////////////// - -func appendStackTrace(errorMessage string, stackTrace []byte) string { - return fmt.Sprintf("%s\n%s", errorMessage, stackTrace) -} diff --git a/cloud/disk_manager/internal/pkg/errors/ya.make b/cloud/disk_manager/internal/pkg/errors/ya.make deleted file mode 100644 index 22a9f407033..00000000000 --- a/cloud/disk_manager/internal/pkg/errors/ya.make +++ /dev/null @@ -1,7 +0,0 @@ -GO_LIBRARY() - -SRCS( - errors.go -) - -END() diff --git a/cloud/disk_manager/internal/pkg/persistence/s3.go b/cloud/disk_manager/internal/pkg/persistence/s3.go index 632071e2ef1..bf690f2ecea 100644 --- a/cloud/disk_manager/internal/pkg/persistence/s3.go +++ b/cloud/disk_manager/internal/pkg/persistence/s3.go @@ -13,9 +13,9 @@ import ( aws_credentials "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" aws_s3 "github.com/aws/aws-sdk-go/service/s3" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics" persistence_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/persistence/config" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/cloud/disk_manager/internal/pkg/persistence/s3_metrics.go b/cloud/disk_manager/internal/pkg/persistence/s3_metrics.go index bd3b91d9e8d..83d17fcffa6 100644 --- a/cloud/disk_manager/internal/pkg/persistence/s3_metrics.go +++ b/cloud/disk_manager/internal/pkg/persistence/s3_metrics.go @@ -4,9 +4,9 @@ import ( "context" "time" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/cloud/disk_manager/internal/pkg/persistence/ydb.go b/cloud/disk_manager/internal/pkg/persistence/ydb.go index d27c31996c0..2b7f5c54b1e 100644 --- a/cloud/disk_manager/internal/pkg/persistence/ydb.go +++ b/cloud/disk_manager/internal/pkg/persistence/ydb.go @@ -10,10 +10,10 @@ import ( "strings" "time" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics" persistence_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/persistence/config" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" "github.com/ydb-platform/ydb-go-sdk/v3" ydb_credentials "github.com/ydb-platform/ydb-go-sdk/v3/credentials" "github.com/ydb-platform/ydb-go-sdk/v3/sugar" diff --git a/cloud/disk_manager/internal/pkg/persistence/ydb_metrics.go b/cloud/disk_manager/internal/pkg/persistence/ydb_metrics.go index 63a844dca09..83159d8c394 100644 --- a/cloud/disk_manager/internal/pkg/persistence/ydb_metrics.go +++ b/cloud/disk_manager/internal/pkg/persistence/ydb_metrics.go @@ -5,9 +5,9 @@ import ( "strings" "time" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics" + "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors" "github.com/ydb-platform/ydb-go-sdk/v3" ydb_metrics "github.com/ydb-platform/ydb-go-sdk/v3/metrics" ydb_trace "github.com/ydb-platform/ydb-go-sdk/v3/trace" diff --git a/cloud/disk_manager/internal/pkg/tasks/errors/errors.go b/cloud/disk_manager/internal/pkg/tasks/errors/errors.go index 525ada03343..67289253ca1 100644 --- a/cloud/disk_manager/internal/pkg/tasks/errors/errors.go +++ b/cloud/disk_manager/internal/pkg/tasks/errors/errors.go @@ -1,60 +1,115 @@ package errors import ( + "errors" "fmt" "runtime/debug" - "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors" "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/common/protos" grpc_status "google.golang.org/grpc/status" ) //////////////////////////////////////////////////////////////////////////////// -type RetriableError = errors.RetriableError +type RetriableError struct { + Err error + IgnoreRetryLimit bool +} func NewRetriableError(err error) *RetriableError { - return errors.NewRetriableError(err) + return &RetriableError{ + Err: err, + } } func NewRetriableErrorf(format string, a ...any) *RetriableError { - return errors.NewRetriableErrorf(format, a...) + return NewRetriableError(fmt.Errorf(format, a...)) } func NewRetriableErrorWithIgnoreRetryLimit(err error) *RetriableError { - return errors.NewRetriableErrorWithIgnoreRetryLimit(err) + return &RetriableError{ + Err: err, + IgnoreRetryLimit: true, + } } func NewRetriableErrorWithIgnoreRetryLimitf(format string, a ...any) *RetriableError { - return errors.NewRetriableErrorWithIgnoreRetryLimitf(format, a...) + return NewRetriableErrorWithIgnoreRetryLimit(fmt.Errorf(format, a...)) } func NewEmptyRetriableError() *RetriableError { - return errors.NewEmptyRetriableError() + return &RetriableError{} +} + +func (e *RetriableError) Error() string { + return fmt.Sprintf("Retriable error, IgnoreRetryLimit=%v: %v", e.IgnoreRetryLimit, e.Err) +} + +func (e *RetriableError) Unwrap() error { + return e.Err +} + +func (e *RetriableError) Is(target error) bool { + t, ok := target.(*RetriableError) + if !ok { + return false + } + + return t.Err == nil || (e.Err == t.Err) } //////////////////////////////////////////////////////////////////////////////// -type NonRetriableError = errors.NonRetriableError +type NonRetriableError struct { + Err error + Silent bool + stackTrace []byte +} func NewNonRetriableError(err error) *NonRetriableError { - return errors.NewNonRetriableError(err) + return newNonRetriableError(err, false) } func NewNonRetriableErrorf(format string, a ...any) *NonRetriableError { - return errors.NewNonRetriableErrorf(format, a...) + return newNonRetriableError(fmt.Errorf(format, a...), false) } func NewSilentNonRetriableError(err error) *NonRetriableError { - return errors.NewSilentNonRetriableError(err) + return newNonRetriableError(err, true) } func NewSilentNonRetriableErrorf(format string, a ...any) *NonRetriableError { - return errors.NewSilentNonRetriableErrorf(format, a...) + return newNonRetriableError(fmt.Errorf(format, a...), true) } func NewEmptyNonRetriableError() *NonRetriableError { - return errors.NewEmptyNonRetriableError() + return newNonRetriableError(nil, false) +} + +func newNonRetriableError(err error, silent bool) *NonRetriableError { + return &NonRetriableError{ + Err: err, + Silent: silent, + stackTrace: debug.Stack(), + } +} + +func (e *NonRetriableError) Error() string { + msg := fmt.Sprintf("Non retriable error, Silent=%v: %v", e.Silent, e.Err) + return appendStackTrace(msg, e.stackTrace) +} + +func (e *NonRetriableError) Unwrap() error { + return e.Err +} + +func (e *NonRetriableError) Is(target error) bool { + t, ok := target.(*NonRetriableError) + if !ok { + return false + } + + return t.Err == nil || (e.Err == t.Err) } //////////////////////////////////////////////////////////////////////////////// diff --git a/cloud/disk_manager/internal/pkg/ya.make b/cloud/disk_manager/internal/pkg/ya.make index 76eafe16eca..e0616e27a54 100644 --- a/cloud/disk_manager/internal/pkg/ya.make +++ b/cloud/disk_manager/internal/pkg/ya.make @@ -5,7 +5,6 @@ RECURSE( clients common dataplane - errors facade headers logging