From defc37eebf5c1879e2ac1fa4fb0aeecd9c3a1104 Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Wed, 17 Feb 2021 17:58:21 +0900 Subject: [PATCH 1/8] :recycle: Revise meta-redis gRPC error statuses and details Signed-off-by: Rintaro Okamura --- pkg/meta/redis/handler/grpc/handler.go | 236 +++++++++++++++++++++++-- 1 file changed, 217 insertions(+), 19 deletions(-) diff --git a/pkg/meta/redis/handler/grpc/handler.go b/pkg/meta/redis/handler/grpc/handler.go index 79403935d1..53bd8a4228 100644 --- a/pkg/meta/redis/handler/grpc/handler.go +++ b/pkg/meta/redis/handler/grpc/handler.go @@ -24,8 +24,8 @@ import ( "github.com/vdaas/vald/apis/grpc/v1/meta" "github.com/vdaas/vald/apis/grpc/v1/payload" "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 +55,38 @@ 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +105,38 @@ 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +152,38 @@ 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +202,38 @@ 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +248,21 @@ 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{ + RequestId: kv.GetKey(), + ServingData: errdetails.Serialize(kv), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +281,21 @@ 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{ + // RequestId: query, + ServingData: errdetails.Serialize(kvs), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +311,38 @@ 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +361,38 @@ 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +408,38 @@ 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +458,38 @@ 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 } From 9bff8d7bb5cc54d9b3d6c983d4b560766724524d Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Wed, 24 Feb 2021 17:52:48 +0900 Subject: [PATCH 2/8] :recycle: Revise meta-cassandra gRPC error statuses and details Signed-off-by: Rintaro Okamura --- pkg/meta/cassandra/handler/grpc/handler.go | 355 ++++++++++++++++++--- 1 file changed, 313 insertions(+), 42 deletions(-) diff --git a/pkg/meta/cassandra/handler/grpc/handler.go b/pkg/meta/cassandra/handler/grpc/handler.go index 93872bb7b3..26370f3044 100644 --- a/pkg/meta/cassandra/handler/grpc/handler.go +++ b/pkg/meta/cassandra/handler/grpc/handler.go @@ -24,8 +24,8 @@ import ( "github.com/vdaas/vald/apis/grpc/v1/meta" "github.com/vdaas/vald/apis/grpc/v1/payload" "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" @@ -56,24 +56,55 @@ 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("GetMeta API Cassandra unavailable", err, info.Get()) - + 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +125,56 @@ 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return mv, status.WrapWithUnavailable("GetMetas API Cassandra unavailable", err, info.Get()) + return mv, 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +192,55 @@ 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("GetMetaInverse API Cassandra unavailable", err, info.Get()) - + 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +261,55 @@ 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return mk, status.WrapWithUnavailable("GetMetasInverse API Cassandra unavailable", err, info.Get()) - + return mk, 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 @@ -200,10 +325,21 @@ 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) + err = status.WrapWithInternal(fmt.Sprintf("SetMeta API: failed to store: key %s val %s", kv.GetKey(), kv.GetVal()), err, + &errdetails.RequestInfo{ + RequestId: kv.GetKey(), + ServingData: errdetails.Serialize(kv), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } - return nil, status.WrapWithInternal(fmt.Sprintf("SetMeta API Cassandra key %s val %s failed to store", kv.GetKey(), kv.GetVal()), err, info.Get()) + return nil, err } return new(payload.Empty), nil } @@ -222,10 +358,21 @@ 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) + err = status.WrapWithInternal(fmt.Sprintf("SetMetas API: failed to store %#v", query), err, + &errdetails.RequestInfo{ + // RequestId: query, + ServingData: errdetails.Serialize(kvs), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } - return nil, status.WrapWithInternal(fmt.Sprintf("SetMetas API Cassandra failed to store %#v", query), err, info.Get()) + return nil, err } return new(payload.Empty), nil } @@ -242,24 +389,55 @@ 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("DeleteMeta API Cassandra unavailable", err, info.Get()) - + 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{ + RequestId: key.GetKey(), + ServingData: errdetails.Serialize(key), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +458,55 @@ 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("DeleteMetas API Cassandra unavailable", err, info.Get()) - + 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(keys), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +524,55 @@ 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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.GetVal()), err, + &errdetails.RequestInfo{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("DeleteMetaInverse API Cassandra unavailable", err, info.Get()) - + 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{ + RequestId: val.GetVal(), + ServingData: errdetails.Serialize(val), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 +593,55 @@ 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } - return nil, status.WrapWithUnavailable("DeleteMetasInverse API Cassandra unavailable", err, info.Get()) - + 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{ + // RequestId: keys.GetKeys(), + ServingData: errdetails.Serialize(vals), + }, + &errdetails.ResourceInfo{ + ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", + // ResourceName: , + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), + }) 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 From b06730f5d49f454ed32a653d8bf1a0c16322e9ad Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Wed, 24 Feb 2021 18:37:47 +0900 Subject: [PATCH 3/8] :wrench: Add info.Get to error details Signed-off-by: Rintaro Okamura --- pkg/meta/cassandra/handler/grpc/handler.go | 53 +++++++++++----------- pkg/meta/redis/handler/grpc/handler.go | 37 +++++++-------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/pkg/meta/cassandra/handler/grpc/handler.go b/pkg/meta/cassandra/handler/grpc/handler.go index 26370f3044..214d117982 100644 --- a/pkg/meta/cassandra/handler/grpc/handler.go +++ b/pkg/meta/cassandra/handler/grpc/handler.go @@ -24,6 +24,7 @@ import ( "github.com/vdaas/vald/apis/grpc/v1/meta" "github.com/vdaas/vald/apis/grpc/v1/payload" "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" @@ -66,7 +67,7 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -83,7 +84,7 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } @@ -100,7 +101,7 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -135,7 +136,7 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -152,7 +153,7 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } @@ -170,7 +171,7 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -202,7 +203,7 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -219,7 +220,7 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } @@ -236,7 +237,7 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -271,7 +272,7 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -288,7 +289,7 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } @@ -305,7 +306,7 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -335,7 +336,7 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } @@ -368,7 +369,7 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } @@ -399,7 +400,7 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -416,7 +417,7 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } @@ -433,7 +434,7 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -468,7 +469,7 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -485,7 +486,7 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } @@ -502,7 +503,7 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -534,7 +535,7 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -551,7 +552,7 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } @@ -568,7 +569,7 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -603,7 +604,7 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -620,7 +621,7 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } @@ -637,7 +638,7 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } diff --git a/pkg/meta/redis/handler/grpc/handler.go b/pkg/meta/redis/handler/grpc/handler.go index 53bd8a4228..1e85c4bbd3 100644 --- a/pkg/meta/redis/handler/grpc/handler.go +++ b/pkg/meta/redis/handler/grpc/handler.go @@ -24,6 +24,7 @@ import ( "github.com/vdaas/vald/apis/grpc/v1/meta" "github.com/vdaas/vald/apis/grpc/v1/payload" "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" @@ -65,7 +66,7 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -82,7 +83,7 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -115,7 +116,7 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -132,7 +133,7 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -162,7 +163,7 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -179,7 +180,7 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -212,7 +213,7 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -229,7 +230,7 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -258,7 +259,7 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } @@ -291,7 +292,7 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) } @@ -321,7 +322,7 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -338,7 +339,7 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -371,7 +372,7 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -388,7 +389,7 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -418,7 +419,7 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -435,7 +436,7 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } @@ -468,7 +469,7 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) } @@ -485,7 +486,7 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals // ResourceName: , Owner: errdetails.ValdResourceOwner, Description: err.Error(), - }) + }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) } From 41eb2880352416ecc4e517a15a76d38d3036cf2d Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Thu, 25 Feb 2021 11:24:22 +0900 Subject: [PATCH 4/8] :wrench: Fill resourceName and remove RequestInfo Signed-off-by: Rintaro Okamura --- pkg/meta/cassandra/handler/grpc/handler.go | 260 +++++++-------------- pkg/meta/redis/handler/grpc/handler.go | 179 +++++--------- 2 files changed, 131 insertions(+), 308 deletions(-) diff --git a/pkg/meta/cassandra/handler/grpc/handler.go b/pkg/meta/cassandra/handler/grpc/handler.go index 214d117982..75244e4db7 100644 --- a/pkg/meta/cassandra/handler/grpc/handler.go +++ b/pkg/meta/cassandra/handler/grpc/handler.go @@ -58,15 +58,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -75,15 +71,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) @@ -92,15 +84,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -127,15 +115,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -144,15 +128,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) @@ -162,15 +142,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -194,15 +170,11 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -211,15 +183,11 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) @@ -228,15 +196,11 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -263,15 +227,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -280,15 +240,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) @@ -297,15 +253,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -327,15 +279,11 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo 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{ - RequestId: kv.GetKey(), - ServingData: errdetails.Serialize(kv), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", kv.GetKey()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) @@ -360,15 +308,11 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa 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{ - // RequestId: query, - ServingData: errdetails.Serialize(kvs), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", query), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) @@ -391,15 +335,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -408,15 +348,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) @@ -425,15 +361,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -460,15 +392,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -477,15 +405,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) @@ -494,15 +418,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -526,15 +446,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -543,15 +459,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( case errors.IsErrCassandraUnavailable(err): log.Warnf("[DeleteMetaInverse]\tunavailable\t%+v", err) err = status.WrapWithUnavailable(fmt.Sprintf("DeleteMetaInverse API: Cassandra unavailable:", val.GetVal()), err, - &errdetails.RequestInfo{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) @@ -560,15 +472,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -595,15 +503,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -612,15 +516,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnavailable(err.Error())) @@ -629,15 +529,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) diff --git a/pkg/meta/redis/handler/grpc/handler.go b/pkg/meta/redis/handler/grpc/handler.go index 1e85c4bbd3..feb7f01ea7 100644 --- a/pkg/meta/redis/handler/grpc/handler.go +++ b/pkg/meta/redis/handler/grpc/handler.go @@ -57,15 +57,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -74,15 +70,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M } 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -107,15 +99,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -124,15 +112,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay } 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -154,15 +138,10 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -171,15 +150,11 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa } 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -204,15 +179,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -221,15 +192,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( } 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.GetMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -250,15 +217,11 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo 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{ - RequestId: kv.GetKey(), - ServingData: errdetails.Serialize(kv), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: kv.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) @@ -283,15 +246,11 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa 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{ - // RequestId: query, - ServingData: errdetails.Serialize(kvs), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.SetMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", query), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeInternal(err.Error())) @@ -313,15 +272,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -330,15 +285,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa } 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{ - RequestId: key.GetKey(), - ServingData: errdetails.Serialize(key), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMeta", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: key.GetKey(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -363,15 +314,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -380,15 +327,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * } 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(keys), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetas", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -410,15 +353,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -427,15 +366,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( } 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{ - RequestId: val.GetVal(), - ServingData: errdetails.Serialize(val), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: val.GetVal(), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) @@ -460,15 +395,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeNotFound(err.Error())) @@ -477,15 +408,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals } 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{ - // RequestId: keys.GetKeys(), - ServingData: errdetails.Serialize(vals), - }, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetasInverse", - // ResourceName: , - Owner: errdetails.ValdResourceOwner, - Description: err.Error(), + ResourceName: fmt.Sprintf("%#v", vals.GetVals()), + Owner: errdetails.ValdResourceOwner, + Description: err.Error(), }, info.Get()) if span != nil { span.SetStatus(trace.StatusCodeUnknown(err.Error())) From a7bf39ee444422fb3d6aa68f0644d94c95694198 Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Mon, 1 Mar 2021 15:00:10 +0900 Subject: [PATCH 5/8] :bug: Fix sprintf Signed-off-by: Rintaro Okamura --- pkg/meta/cassandra/handler/grpc/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/meta/cassandra/handler/grpc/handler.go b/pkg/meta/cassandra/handler/grpc/handler.go index 75244e4db7..6ac8981405 100644 --- a/pkg/meta/cassandra/handler/grpc/handler.go +++ b/pkg/meta/cassandra/handler/grpc/handler.go @@ -458,7 +458,7 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( return nil, err case errors.IsErrCassandraUnavailable(err): log.Warnf("[DeleteMetaInverse]\tunavailable\t%+v", err) - err = status.WrapWithUnavailable(fmt.Sprintf("DeleteMetaInverse API: Cassandra unavailable:", val.GetVal()), err, + err = status.WrapWithUnavailable(fmt.Sprintf("DeleteMetaInverse API: Cassandra unavailable: val %s", val.GetVal()), err, &errdetails.ResourceInfo{ ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/meta/Meta.DeleteMetaInverse", ResourceName: val.GetVal(), From 5324c886e94da0a83dc25234d604a5dfaef353b4 Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Wed, 3 Mar 2021 11:49:30 +0900 Subject: [PATCH 6/8] :recycle: Embedding request payload into RequestInfo Signed-off-by: Rintaro Okamura --- pkg/meta/cassandra/handler/grpc/handler.go | 104 +++++++++++++++------ pkg/meta/redis/handler/grpc/handler.go | 71 ++++++++++---- 2 files changed, 132 insertions(+), 43 deletions(-) diff --git a/pkg/meta/cassandra/handler/grpc/handler.go b/pkg/meta/cassandra/handler/grpc/handler.go index 6ac8981405..78f908c603 100644 --- a/pkg/meta/cassandra/handler/grpc/handler.go +++ b/pkg/meta/cassandra/handler/grpc/handler.go @@ -58,9 +58,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -71,9 +73,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -84,9 +88,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -115,9 +121,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -128,9 +136,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -142,9 +152,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -170,9 +182,11 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -183,9 +197,11 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -196,9 +212,11 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -227,9 +245,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -240,9 +260,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -253,9 +275,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -279,9 +303,11 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo 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", - ResourceName: fmt.Sprintf("%#v", kv.GetKey()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -308,9 +334,11 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa 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", - ResourceName: fmt.Sprintf("%#v", query), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -335,9 +363,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -348,9 +378,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -361,9 +393,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -392,9 +426,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -405,9 +441,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -418,9 +456,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -446,9 +486,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -459,9 +501,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -472,9 +516,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -503,9 +549,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -516,9 +564,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -529,9 +579,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) diff --git a/pkg/meta/redis/handler/grpc/handler.go b/pkg/meta/redis/handler/grpc/handler.go index feb7f01ea7..74783d271c 100644 --- a/pkg/meta/redis/handler/grpc/handler.go +++ b/pkg/meta/redis/handler/grpc/handler.go @@ -57,9 +57,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -70,9 +72,11 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M } 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -99,9 +103,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -112,9 +118,11 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay } 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -138,6 +146,9 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa 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, @@ -150,9 +161,11 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa } 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -179,9 +192,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -192,9 +207,11 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( } 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -217,9 +234,11 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo 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", - ResourceName: kv.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -246,9 +265,11 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa 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", - ResourceName: fmt.Sprintf("%#v", query), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -272,9 +293,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -285,9 +308,11 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa } 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", - ResourceName: key.GetKey(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -314,9 +339,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -327,9 +354,11 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * } 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", - ResourceName: fmt.Sprintf("%#v", keys.GetKeys()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -353,9 +382,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -366,9 +397,11 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( } 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", - ResourceName: val.GetVal(), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -395,9 +428,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) @@ -408,9 +443,11 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals } 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", - ResourceName: fmt.Sprintf("%#v", vals.GetVals()), Owner: errdetails.ValdResourceOwner, Description: err.Error(), }, info.Get()) From c05b92ba13973662d860e6bedf373afdce7265e2 Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Wed, 3 Mar 2021 16:12:05 +0900 Subject: [PATCH 7/8] :art: Use Internal and FailedPrecondition statuses for Cassandra errors Signed-off-by: Rintaro Okamura --- pkg/meta/cassandra/handler/grpc/handler.go | 407 +++++++++++++++++++-- 1 file changed, 380 insertions(+), 27 deletions(-) diff --git a/pkg/meta/cassandra/handler/grpc/handler.go b/pkg/meta/cassandra/handler/grpc/handler.go index 78f908c603..2df6ae0133 100644 --- a/pkg/meta/cassandra/handler/grpc/handler.go +++ b/pkg/meta/cassandra/handler/grpc/handler.go @@ -23,6 +23,7 @@ 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" @@ -45,6 +46,23 @@ 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 (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() { @@ -85,6 +103,36 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } 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.WrapWithInternal(fmt.Sprintf("GetMeta API: failed precondition: 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.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, @@ -148,7 +196,36 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } 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.WrapWithInternal(fmt.Sprintf("GetMetas API: failed precondition: 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.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, @@ -209,6 +286,36 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } 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.WrapWithInternal(fmt.Sprintf("GetMetaInverse API: failed precondition: 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.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, @@ -272,6 +379,36 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } 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.WrapWithInternal(fmt.Sprintf("GetMetasInverse API: failed precondition: 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.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, @@ -301,20 +438,68 @@ 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) - 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())) + 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.WrapWithInternal(fmt.Sprintf("SetMeta API: failed precondition: 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.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, err } return new(payload.Empty), nil } @@ -332,20 +517,68 @@ 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) - 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())) + 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.WrapWithInternal(fmt.Sprintf("SetMetas API: failed precondition: 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.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, err } return new(payload.Empty), nil } @@ -390,6 +623,36 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } 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.WrapWithInternal(fmt.Sprintf("DeleteMeta API: failed precondition: 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.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, @@ -453,6 +716,36 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } 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.WrapWithInternal(fmt.Sprintf("DeleteMetas API: failed precondition: 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.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, @@ -513,6 +806,36 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } 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.WrapWithInternal(fmt.Sprintf("DeleteMetaInverse API: failed precondition: 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.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, @@ -576,6 +899,36 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals span.SetStatus(trace.StatusCodeUnavailable(err.Error())) } 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.WrapWithInternal(fmt.Sprintf("DeleteMetasInverse API: failed precondition: 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.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, From ea6287bda001341d1bf7c681f391ab19891605a3 Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Wed, 3 Mar 2021 18:00:21 +0900 Subject: [PATCH 8/8] :art: Use WrapWithFailedPrecondition for precondition failures Signed-off-by: Rintaro Okamura --- pkg/meta/cassandra/handler/grpc/handler.go | 88 +++++++++++++++++++--- 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/pkg/meta/cassandra/handler/grpc/handler.go b/pkg/meta/cassandra/handler/grpc/handler.go index 2df6ae0133..5f88d45c83 100644 --- a/pkg/meta/cassandra/handler/grpc/handler.go +++ b/pkg/meta/cassandra/handler/grpc/handler.go @@ -63,6 +63,44 @@ func isFailedPrecondition(err error) bool { 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() { @@ -120,10 +158,13 @@ func (s *server) GetMeta(ctx context.Context, key *payload.Meta_Key) (*payload.M return nil, err case isFailedPrecondition(err): log.Warnf("[GetMeta]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("GetMeta API: failed precondition: key %s", key.GetKey()), 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, @@ -213,10 +254,13 @@ func (s *server) GetMetas(ctx context.Context, keys *payload.Meta_Keys) (mv *pay return nil, err case isFailedPrecondition(err): log.Warnf("[GetMetas]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("GetMetas API: failed precondition: keys %#v", keys.GetKeys()), 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, @@ -303,10 +347,13 @@ func (s *server) GetMetaInverse(ctx context.Context, val *payload.Meta_Val) (*pa return nil, err case isFailedPrecondition(err): log.Warnf("[GetMetaInverse]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("GetMetaInverse API: failed precondition: val %s", val.GetVal()), 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, @@ -396,10 +443,13 @@ func (s *server) GetMetasInverse(ctx context.Context, vals *payload.Meta_Vals) ( return nil, err case isFailedPrecondition(err): log.Warnf("[GetMetasInverse]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("GetMetasInverse API: failed precondition: vals %#v", vals.GetVals()), 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, @@ -471,10 +521,13 @@ func (s *server) SetMeta(ctx context.Context, kv *payload.Meta_KeyVal) (_ *paylo return nil, err case isFailedPrecondition(err): log.Warnf("[SetMeta]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("SetMeta API: failed precondition: key %s val %s", kv.GetKey(), kv.GetVal()), 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, @@ -550,10 +603,13 @@ func (s *server) SetMetas(ctx context.Context, kvs *payload.Meta_KeyVals) (_ *pa return nil, err case isFailedPrecondition(err): log.Warnf("[SetMetas]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("SetMetas API: failed precondition: kvs %#v", query), 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, @@ -640,10 +696,13 @@ func (s *server) DeleteMeta(ctx context.Context, key *payload.Meta_Key) (*payloa return nil, err case isFailedPrecondition(err): log.Warnf("[DeleteMeta]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("DeleteMeta API: failed precondition: key %s", key.GetKey()), 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, @@ -733,10 +792,13 @@ func (s *server) DeleteMetas(ctx context.Context, keys *payload.Meta_Keys) (mv * return nil, err case isFailedPrecondition(err): log.Warnf("[DeleteMetas]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("DeleteMetas API: failed precondition: keys %#v", keys.GetKeys()), 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, @@ -823,10 +885,13 @@ func (s *server) DeleteMetaInverse(ctx context.Context, val *payload.Meta_Val) ( return nil, err case isFailedPrecondition(err): log.Warnf("[DeleteMetaInverse]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("DeleteMetaInverse API: failed precondition: val %s", val.GetVal()), 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, @@ -916,10 +981,13 @@ func (s *server) DeleteMetasInverse(ctx context.Context, vals *payload.Meta_Vals return nil, err case isFailedPrecondition(err): log.Warnf("[DeleteMetasInverse]\tfailed precondition\t%+v", err) - err = status.WrapWithInternal(fmt.Sprintf("DeleteMetasInverse API: failed precondition: vals %#v", vals.GetVals()), 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,