diff --git a/pkg/meta/cassandra/handler/grpc/handler.go b/pkg/meta/cassandra/handler/grpc/handler.go index 93872bb7b3..5f88d45c83 100644 --- a/pkg/meta/cassandra/handler/grpc/handler.go +++ b/pkg/meta/cassandra/handler/grpc/handler.go @@ -23,9 +23,11 @@ import ( "github.com/vdaas/vald/apis/grpc/v1/meta" "github.com/vdaas/vald/apis/grpc/v1/payload" + "github.com/vdaas/vald/internal/db/nosql/cassandra" "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/info" "github.com/vdaas/vald/internal/log" + "github.com/vdaas/vald/internal/net/grpc/errdetails" "github.com/vdaas/vald/internal/net/grpc/status" "github.com/vdaas/vald/internal/observability/trace" "github.com/vdaas/vald/pkg/meta/cassandra/service" @@ -44,6 +46,61 @@ func New(opts ...Option) meta.MetaServer { return s } +func isInternalError(err error) bool { + return errors.As(err, &cassandra.ErrUnsupported) || + errors.As(err, &cassandra.ErrTooManyStmts) || + errors.As(err, &cassandra.ErrUseStmt) || + errors.As(err, &cassandra.ErrSessionClosed) || + errors.As(err, &cassandra.ErrNoKeyspace) || + errors.As(err, &cassandra.ErrNoMetadata) || + errors.As(err, &cassandra.ErrHostQueryFailed) +} + +func isFailedPrecondition(err error) bool { + return errors.As(err, &cassandra.ErrNoConnections) || + errors.As(err, &cassandra.ErrKeyspaceDoesNotExist) || + errors.As(err, &cassandra.ErrNoHosts) || + errors.As(err, &cassandra.ErrNoConnectionsStarted) +} + +func getPreconditionFailureDetails(err error) (res []*errdetails.PreconditionFailureViolation) { + res = make([]*errdetails.PreconditionFailureViolation, 0) + + if errors.As(err, &cassandra.ErrNoConnections) { + res = append(res, &errdetails.PreconditionFailureViolation{ + Type: "No connections", + Subject: "Cassandra", + Description: cassandra.ErrNoConnections.Error(), + }) + } + + if errors.As(err, &cassandra.ErrKeyspaceDoesNotExist) { + res = append(res, &errdetails.PreconditionFailureViolation{ + Type: "Keyspace does not exist", + Subject: "Cassandra", + Description: cassandra.ErrKeyspaceDoesNotExist.Error(), + }) + } + + if errors.As(err, &cassandra.ErrNoHosts) { + res = append(res, &errdetails.PreconditionFailureViolation{ + Type: "No hosts", + Subject: "Cassandra", + Description: cassandra.ErrNoHosts.Error(), + }) + } + + if errors.As(err, &cassandra.ErrNoConnectionsStarted) { + res = append(res, &errdetails.PreconditionFailureViolation{ + Type: "No connections started", + Subject: "Cassandra", + Description: cassandra.ErrNoConnectionsStarted.Error(), + }) + } + + return res +} + func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.Meta_Val, error) { ctx, span := trace.StartSpan(ctx, "vald/meta-cassandra.GetMeta") defer func() { @@ -56,24 +113,82 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M switch { case errors.IsErrCassandraNotFound(err): log.Warnf("[GetMeta]\tnot found\t%v\t%s", key.GetKey(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("GetMeta API: not found: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("GetMeta API Cassandra key %s not found", key.GetKey()), err, info.Get()) - + return nil, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[GetMeta]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("GetMeta API: Cassandra unavailable: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("GetMeta API Cassandra unavailable", err, info.Get()) - + return nil, err + case isInternalError(err): + log.Warnf("[GetMeta]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("GetMeta API: internal error occurred: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[GetMeta]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("GetMeta API: failed precondition: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err default: log.Errorf("[GetMeta]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("GetMeta API: unknown error occurred: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return nil, status.WrapWithUnknown(fmt.Sprintf("GetMeta API Cassandra unknown error occurred key %s", key.GetKey()), err, info.Get()) + return nil, err } } return &payload.Meta_Val{ @@ -94,24 +209,82 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay switch { case errors.IsErrCassandraNotFound(err): log.Warnf("[GetMetas]\tnot found\t%v\t%s", keys.GetKeys(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("GetMetas API: not found: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return mv, status.WrapWithNotFound(fmt.Sprintf("GetMetas API Cassandra entry keys %#v not found", keys.GetKeys()), err, info.Get()) - + return mv, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[GetMetas]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("GetMetas API: Cassandra unavailable: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return mv, status.WrapWithUnavailable("GetMetas API Cassandra unavailable", err, info.Get()) - + return mv, err + case isInternalError(err): + log.Warnf("[GetMetas]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("GetMetas API: internal error occurred: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[GetMetas]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("GetMetas API: failed precondition: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err default: log.Errorf("[GetMetas]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("GetMetas API: unknown error occurred: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return mv, status.WrapWithUnknown(fmt.Sprintf("GetMetas API Cassandra entry keys %#v unknown error occurred", keys.GetKeys()), err, info.Get()) + return mv, err } } return mv, nil @@ -129,24 +302,82 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa switch { case errors.IsErrCassandraNotFound(err): log.Warnf("[GetMetaInverse]\tnot found\t%v\t%s", val.GetVal(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("GetMetaInverse API: not found: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("GetMetaInverse API Cassandra val %s not found", val.GetVal()), err, info.Get()) - + return nil, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[GetMetaInverse]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("GetMetaInverse API: Cassandra unavailable: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("GetMetaInverse API Cassandra unavailable", err, info.Get()) - + return nil, err + case isInternalError(err): + log.Warnf("[GetMetaInverse]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("GetMetaInverse API: internal error occurred: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[GetMetaInverse]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("GetMetaInverse API: failed precondition: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err default: log.Errorf("[GetMetaInverse]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("GetMetaInverse API: unknown error occurred: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return nil, status.WrapWithUnknown(fmt.Sprintf("GetMetaInverse API Cassandra val %s unknown error occurred", val.GetVal()), err, info.Get()) + return nil, err } } return &payload.Meta_Key{ @@ -167,24 +398,82 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( switch { case errors.IsErrCassandraNotFound(err): log.Warnf("[GetMetasInverse]\tnot found\t%v\t%s", vals.GetVals(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("GetMetasInverse API: not found: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return mk, status.WrapWithNotFound(fmt.Sprintf("GetMetasInverse API Cassandra vals %#v not found", vals.GetVals()), err, info.Get()) - + return mk, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[GetMetasInverse]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("GetMetasInverse API: Cassandra unavailable: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return mk, status.WrapWithUnavailable("GetMetasInverse API Cassandra unavailable", err, info.Get()) - + return mk, err + case isInternalError(err): + log.Warnf("[GetMetasInverse]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("GetMetasInverse API: internal error occurred: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[GetMetasInverse]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("GetMetasInverse API: failed precondition: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err default: log.Errorf("[GetMetasInverse]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("GetMetasInverse API: unknown error occurred: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return mk, status.WrapWithUnknown(fmt.Sprintf("GetMetasInverse API Cassandra vals %#v unknown error occurred", vals.GetVals()), err, info.Get()) + return mk, err } } return mk, nil @@ -199,11 +488,71 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo }() err = s.cassandra.Set(kv.GetKey(), kv.GetVal()) if err != nil { - log.Errorf("[SetMeta]\tunknown error\t%+v", err) - if span != nil { - span.SetStatus(trace.StatusCodeInternal(err.Error())) + switch { + case errors.IsErrCassandraUnavailable(err): + log.Warnf("[SetMeta]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("SetMeta API: Cassandra unavailable: key %s, val %s", kv.GetKey(), kv.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kv), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeUnavailable(err.Error())) + } + return nil, err + case isInternalError(err): + log.Warnf("[SetMeta]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("SetMeta API: internal error occurred: key %s val %s", kv.GetKey(), kv.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kv), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[SetMeta]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("SetMeta API: failed precondition: key %s val %s", kv.GetKey(), kv.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kv), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err + default: + log.Errorf("[SetMeta]\tunknown error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("SetMeta API: failed to store: key %s val %s", kv.GetKey(), kv.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kv), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err } - return nil, status.WrapWithInternal(fmt.Sprintf("SetMeta API Cassandra key %s val %s failed to store", kv.GetKey(), kv.GetVal()), err, info.Get()) } return new(payload.Empty), nil } @@ -221,11 +570,71 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa } err = s.cassandra.SetMultiple(query) if err != nil { - log.Errorf("[SetMetas]\tunknown error\t%+v", err) - if span != nil { - span.SetStatus(trace.StatusCodeInternal(err.Error())) + switch { + case errors.IsErrCassandraUnavailable(err): + log.Warnf("[SetMetas]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("SetMetas API: Cassandra unavailable: kvs %#v", query), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kvs), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeUnavailable(err.Error())) + } + return nil, err + case isInternalError(err): + log.Warnf("[SetMetas]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("SetMetas API: internal error occurred: kvs %#v", query), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kvs), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[SetMetas]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("SetMetas API: failed precondition: kvs %#v", query), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kvs), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err + default: + log.Errorf("[SetMetas]\tunknown error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("SetMetas API: failed to store: kvs %#v", query), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kvs), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err } - return nil, status.WrapWithInternal(fmt.Sprintf("SetMetas API Cassandra failed to store %#v", query), err, info.Get()) } return new(payload.Empty), nil } @@ -242,24 +651,82 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa switch { case errors.IsErrCassandraNotFound(err): log.Warnf("[DeleteMeta]\tnot found\t%v\t%s", key.GetKey(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("DeleteMeta API: not found: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("DeleteMeta API Cassandra key %s not found", key.GetKey()), err, info.Get()) - + return nil, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[DeleteMeta]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("DeleteMeta API: Cassandra unavailable: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("DeleteMeta API Cassandra unavailable", err, info.Get()) - + return nil, err + case isInternalError(err): + log.Warnf("[DeleteMeta]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("DeleteMeta API: internal error occurred: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[DeleteMeta]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("DeleteMeta API: failed precondition: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err default: log.Errorf("[DeleteMeta]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("DeleteMeta API: unknown error occurred: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return nil, status.WrapWithUnknown(fmt.Sprintf("DeleteMeta API Cassandra unknown error occurred key %s", key.GetKey()), err, info.Get()) + return nil, err } } return &payload.Meta_Val{ @@ -280,24 +747,82 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * switch { case errors.IsErrCassandraNotFound(err): log.Warnf("[DeleteMetas]\tnot found\t%v\t%s", keys.GetKeys(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("DeleteMetas API: not found: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return mv, status.WrapWithNotFound(fmt.Sprintf("DeleteMetas API Cassandra entry keys %#v not found", keys.GetKeys()), err, info.Get()) - + return mv, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[DeleteMetas]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("DeleteMetas API: Cassandra unavailable: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("DeleteMetas API Cassandra unavailable", err, info.Get()) - + return nil, err + case isInternalError(err): + log.Warnf("[DeleteMetas]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("DeleteMetas API: internal error occurred: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[DeleteMetas]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("DeleteMetas API: failed precondition: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err default: log.Errorf("[DeleteMetas]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("DeleteMetas API: unknown error occurred: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return mv, status.WrapWithUnknown(fmt.Sprintf("DeleteMetas API Cassandra entry keys %#v unknown error occurred", keys.GetKeys()), err, info.Get()) + return mv, err } } return mv, nil @@ -315,24 +840,82 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( switch { case errors.IsErrCassandraNotFound(err): log.Warnf("[DeleteMetaInverse]\tnot found\t%v\t%s", val.GetVal(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("DeleteMetaInverse API: not found: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("DeleteMetaInverse API Cassandra val %s not found", val.GetVal()), err, info.Get()) - + return nil, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[DeleteMetaInverse]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("DeleteMetaInverse API: Cassandra unavailable: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("DeleteMetaInverse API Cassandra unavailable", err, info.Get()) - + return nil, err + case isInternalError(err): + log.Warnf("[DeleteMetaInverse]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("DeleteMetaInverse API: internal error occurred: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[DeleteMetaInverse]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("DeleteMetaInverse API: failed precondition: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err default: log.Errorf("[DeleteMetaInverse]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("DeleteMetaInverse API: unknown error occurred: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return nil, status.WrapWithUnknown(fmt.Sprintf("DeleteMetaInverse API val %s unknown error occurred", val.GetVal()), err, info.Get()) + return nil, err } } return &payload.Meta_Key{ @@ -353,24 +936,82 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals switch { case errors.IsErrCassandraNotFound(err): log.Warnf("[DeleteMetasInverse]\tnot found\t%v\t%s", vals.GetVals(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("DeleteMetasInverse API: not found: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return mk, status.WrapWithNotFound(fmt.Sprintf("DeleteMetasInverse API Cassandra vals %#v not found", vals.GetVals()), err, info.Get()) - + return mk, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[DeleteMetasInverse]\tunavailable\t%+v", err) + err = status.WrapWithUnavailable(fmt.Sprintf("DeleteMetasInverse API: Cassandra unavailable: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("DeleteMetasInverse API Cassandra unavailable", err, info.Get()) - + return nil, err + case isInternalError(err): + log.Warnf("[DeleteMetasInverse]\tinternal error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("DeleteMetasInverse API: internal error occurred: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeInternal(err.Error())) + } + return nil, err + case isFailedPrecondition(err): + log.Warnf("[DeleteMetasInverse]\tfailed precondition\t%+v", err) + err = status.WrapWithFailedPrecondition(fmt.Sprintf("DeleteMetasInverse API: failed precondition: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.PreconditionFailure{ + Violations: getPreconditionFailureDetails(err), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) + if span != nil { + span.SetStatus(trace.StatusCodeFailedPrecondition(err.Error())) + } + return nil, err default: log.Errorf("[DeleteMetasInverse]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("DeleteMetasInverse API: unknown error occurred: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return mk, status.WrapWithUnknown(fmt.Sprintf("DeleteMetasInverse API vals %#v unknown error occurred", vals.GetVals()), err, info.Get()) + return mk, err } } return mk, nil diff --git a/pkg/meta/redis/handler/grpc/handler.go b/pkg/meta/redis/handler/grpc/handler.go index 79403935d1..74783d271c 100644 --- a/pkg/meta/redis/handler/grpc/handler.go +++ b/pkg/meta/redis/handler/grpc/handler.go @@ -26,6 +26,7 @@ import ( "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/info" "github.com/vdaas/vald/internal/log" + "github.com/vdaas/vald/internal/net/grpc/errdetails" "github.com/vdaas/vald/internal/net/grpc/status" "github.com/vdaas/vald/internal/observability/trace" "github.com/vdaas/vald/pkg/meta/redis/service" @@ -55,16 +56,34 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M if err != nil { if errors.IsErrRedisNotFound(err) { log.Warnf("[GetMeta]\tnot found\t%v\t%s", key.GetKey(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("GetMeta API: not found: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("GetMeta API key %s not found", key.GetKey()), err, info.Get()) + return nil, err } log.Errorf("[GetMeta]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("GetMeta API: unknown error occurred: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return nil, status.WrapWithUnknown(fmt.Sprintf("GetMeta API unknown error occurred key %s", key.GetKey()), err, info.Get()) + return nil, err } return &payload.Meta_Val{ Val: val, @@ -83,16 +102,34 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay if err != nil { if errors.IsErrRedisNotFound(err) { log.Warnf("[GetMetas]\tnot found\t%v\t%s", keys.GetKeys(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("GetMetas API: not found: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return mv, status.WrapWithNotFound(fmt.Sprintf("GetMetas API Redis entry keys %#v not found", keys.GetKeys()), err, info.Get()) + return mv, err } log.Errorf("[GetMetas]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("GetMetas API: unknown error occurred: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return mv, status.WrapWithUnknown(fmt.Sprintf("GetMetas API Redis entry keys %#v unknown error occurred", keys.GetKeys()), err, info.Get()) + return mv, err } return mv, nil } @@ -108,16 +145,34 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa if err != nil { if errors.IsErrRedisNotFound(err) { log.Warnf("[GetMetaInverse]\tnot found\t%v\t%s", val.GetVal(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("GetMetaInverse API: not found: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("GetMetaInverse API val %s not found", val.GetVal()), err, info.Get()) + return nil, err } log.Errorf("[GetMetaInverse]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("GetMetaInverse API: unknown error occurred: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return nil, status.WrapWithUnknown(fmt.Sprintf("GetMetaInverse API val %s unknown error occurred", val.GetVal()), err, info.Get()) + return nil, err } return &payload.Meta_Key{ Key: key, @@ -136,16 +191,34 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( if err != nil { if errors.IsErrRedisNotFound(err) { log.Warnf("[GetMetasInverse]\tnot found\t%v\t%s", vals.GetVals(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("GetMetasInverse API: not found: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return mk, status.WrapWithNotFound(fmt.Sprintf("GetMetasInverse API vals %#v not found", vals.GetVals()), err, info.Get()) + return mk, err } log.Errorf("[GetMetasInverse]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("GetMetasInverse API: unknown error occurred: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return mk, status.WrapWithUnknown(fmt.Sprintf("GetMetasInverse API vals %#v unknown error occurred", vals.GetVals()), err, info.Get()) + return mk, err } return mk, nil } @@ -160,10 +233,19 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo err = s.redis.Set(ctx, kv.GetKey(), kv.GetVal()) if err != nil { log.Errorf("[SetMeta]\tunknown error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("SetMeta API: failed to store: key %s val %s", kv.GetKey(), kv.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kv), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } - return nil, status.WrapWithInternal(fmt.Sprintf("SetMeta API key %s val %s failed to store", kv.GetKey(), kv.GetVal()), err, info.Get()) + return nil, err } return new(payload.Empty), nil } @@ -182,10 +264,19 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa err = s.redis.SetMultiple(ctx, query) if err != nil { log.Errorf("[SetMetas]\tunknown error\t%+v", err) + err = status.WrapWithInternal(fmt.Sprintf("SetMetas API: failed to store: %#v", query), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(kvs), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } - return nil, status.WrapWithInternal(fmt.Sprintf("SetMetas API failed to store %#v", query), err, info.Get()) + return nil, err } return new(payload.Empty), nil } @@ -201,16 +292,34 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa if err != nil { if errors.IsErrRedisNotFound(err) { log.Warnf("[DeleteMeta]\tnot found\t%v\t%s", key.GetKey(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("DeleteMeta API: not found: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("DeleteMeta API key %s not found", key.GetKey()), err, info.Get()) + return nil, err } log.Errorf("[DeleteMeta]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("DeleteMeta API: unknown error occurred: key %s", key.GetKey()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return nil, status.WrapWithUnknown(fmt.Sprintf("DeleteMeta API unknown error occurred key %s", key.GetKey()), err, info.Get()) + return nil, err } return &payload.Meta_Val{ Val: val, @@ -229,16 +338,34 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * if err != nil { if errors.IsErrRedisNotFound(err) { log.Warnf("[DeleteMetas]\tnot found\t%v\t%s", keys.GetKeys(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("DeleteMetas API: not found: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return mv, status.WrapWithNotFound(fmt.Sprintf("DeleteMetas API Redis entry keys %#v not found", keys.GetKeys()), err, info.Get()) + return mv, err } log.Errorf("[DeleteMetas]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("DeleteMetas API: unknown error occurred: keys %#v", keys.GetKeys()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return mv, status.WrapWithUnknown(fmt.Sprintf("DeleteMetas API Redis entry keys %#v unknown error occurred", keys.GetKeys()), err, info.Get()) + return mv, err } return mv, nil } @@ -254,16 +381,34 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( if err != nil { if errors.IsErrRedisNotFound(err) { log.Warnf("[DeleteMetaInverse]\tnot found\t%v\t%s", val.GetVal(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("DeleteMetaInverse API: not found: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return nil, status.WrapWithNotFound(fmt.Sprintf("DeleteMetaInverse API val %s not found", val.GetVal()), err, info.Get()) + return nil, err } log.Errorf("[DeleteMetaInverse]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("DeleteMetaInverse API: unknown error occurred: val %s", val.GetVal()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return nil, status.WrapWithUnknown(fmt.Sprintf("DeleteMetaInverse API val %s unknown error occurred", val.GetVal()), err, info.Get()) + return nil, err } return &payload.Meta_Key{ Key: key, @@ -282,16 +427,34 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals if err != nil { if errors.IsErrRedisNotFound(err) { log.Warnf("[DeleteMetasInverse]\tnot found\t%v\t%s", vals.GetVals(), err.Error()) + err = status.WrapWithNotFound(fmt.Sprintf("DeleteMetasInverse API: not found: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } - return mk, status.WrapWithNotFound(fmt.Sprintf("DeleteMetasInverse API vals %#v not found", vals.GetVals()), err, info.Get()) + return mk, err } log.Errorf("[DeleteMetasInverse]\tunknown error\t%+v", err) + err = status.WrapWithUnknown(fmt.Sprintf("DeleteMetasInverse API: unknown error occurred: vals %#v", vals.GetVals()), err, + &errdetails.RequestInfo{ + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } - return mk, status.WrapWithUnknown(fmt.Sprintf("DeleteMetasInverse API vals %#v unknown error occurred", vals.GetVals()), err, info.Get()) + return mk, err } return mk, nil }