Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture CassandraLWT error and log/bump metrics for it. #4888

Merged
merged 7 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,7 @@ const (
PersistenceErrExecutionAlreadyStartedCounter
PersistenceErrDomainAlreadyExistsCounter
PersistenceErrBadRequestCounter
PersistenceErrCassandraLWTCounter
PersistenceSampledCounter
PersistenceEmptyResponseCounter

Expand Down Expand Up @@ -2343,6 +2344,7 @@ var MetricDefs = map[ServiceIdx]map[int]metricDefinition{
PersistenceErrExecutionAlreadyStartedCounter: {metricName: "persistence_errors_execution_already_started", metricType: Counter},
PersistenceErrDomainAlreadyExistsCounter: {metricName: "persistence_errors_domain_already_exists", metricType: Counter},
PersistenceErrBadRequestCounter: {metricName: "persistence_errors_bad_request", metricType: Counter},
PersistenceErrCassandraLWTCounter: {metricName: "persistence_errors_cassandra_lwt", metricType: Counter},
PersistenceSampledCounter: {metricName: "persistence_sampled", metricType: Counter},
PersistenceEmptyResponseCounter: {metricName: "persistence_empty_response", metricType: Counter},
CadenceClientRequests: {metricName: "cadence_client_requests", metricType: Counter},
Expand Down
10 changes: 10 additions & 0 deletions common/persistence/dataManagerInterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ type (
Msg string
}

// CassandraLWTError is returned when we get UNAVAILABLE error code from Cassandra with message containing
// "Cannot perform LWT operation"
CassandraLWTError struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this file DB-agnostic, so I'd prefer to use more generic names like DBUnavailableError which could be meaningful for plugins such as MongoDB.

Also see my similar comment in common/persistence/nosql/nosqlplugin/interfaces.go.

Msg string
}

// TransactionSizeLimitError is returned when the transaction size is too large
TransactionSizeLimitError struct {
Msg string
Expand Down Expand Up @@ -1862,6 +1868,10 @@ func (e *TimeoutError) Error() string {
return e.Msg
}

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

func (e *TransactionSizeLimitError) Error() string {
return e.Msg
}
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/nosql/nosqlplugin/cassandra/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ func (db *cdb) IsTimeoutError(err error) bool {
func (db *cdb) IsThrottlingError(err error) bool {
return db.client.IsThrottlingError(err)
}

func (db *cdb) IsCassandraLWTError(err error) bool {
return db.client.IsCassandraLWTError(err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package public

import (
"context"
"strings"

gogocql "github.com/gocql/gocql"

Expand Down Expand Up @@ -70,3 +71,16 @@ func (c client) IsThrottlingError(err error) bool {
}
return false
}

func (c client) IsCassandraLWTError(err error) bool {
if req, ok := err.(gogocql.RequestError); ok {
// 0x1000 == UNAVAILABLE
if req.Code() != 0x1000 {
return false
}
if strings.Contains(req.Message(), "Cannot perform LWT operation") {
return true
}
}
return false
}
1 change: 1 addition & 0 deletions common/persistence/nosql/nosqlplugin/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type (
IsTimeoutError(error) bool
IsNotFoundError(error) bool
IsThrottlingError(error) bool
IsCassandraLWTError(error) bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cassandra-specific func in the nosql interface doesn't look good. Can you give this a more generic name so that it looks less ugly for non-Cassandra nosql plugins? Perhaps something like IsDBUnavailableError.

}

/**
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/nosql/nosqlplugin/mongodb/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ func (db *mdb) IsTimeoutError(err error) bool {
func (db *mdb) IsThrottlingError(err error) bool {
return false
}

func (db *mdb) IsCassandraLWTError(err error) bool {
return false
}
6 changes: 6 additions & 0 deletions common/persistence/nosql/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func convertCommonErrors(
}
}

if errChecker.IsCassandraLWTError(err) {
return &p.CassandraLWTError{
Msg: fmt.Sprintf("#{operation} operation failed. Error: #{err}"),
}
}

return &types.InternalServiceError{
Message: fmt.Sprintf("%v operation failed. Error: %v", operation, err),
}
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/persistenceMetricClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func (p *persistenceMetricsClientBase) updateErrorMetric(scope int, err error) {
case *types.ServiceBusyError:
p.metricClient.IncCounter(scope, metrics.PersistenceErrBusyCounter)
p.metricClient.IncCounter(scope, metrics.PersistenceFailures)
case *CassandraLWTError:
p.metricClient.IncCounter(scope, metrics.PersistenceErrCassandraLWTCounter)
p.metricClient.IncCounter(scope, metrics.PersistenceFailures)
p.logger.Error("Cassandra LWT Error.", tag.Error(err), tag.MetricScope(scope))
default:
p.logger.Error("Operation failed with internal error.", tag.Error(err), tag.MetricScope(scope))
p.metricClient.IncCounter(scope, metrics.PersistenceFailures)
Expand Down