Skip to content

Commit

Permalink
fix: deleted unnecessary error resource info
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Oct 1, 2024
1 parent 51f4a0e commit a41cfac
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions pkg/gateway/mirror/service/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/vdaas/vald/internal/net"
"github.com/vdaas/vald/internal/net/grpc"
"github.com/vdaas/vald/internal/net/grpc/codes"
"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/internal/sync"
Expand Down Expand Up @@ -178,12 +177,6 @@ func (m *mirr) registers(
}
}()

reqInfo := &errdetails.RequestInfo{
ServingData: errdetails.Serialize(tgts),
}
resInfo := &errdetails.ResourceInfo{
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + mirror.RegisterRPCName,
}
resTgts := make([]*payload.Mirror_Target, 0, len(tgts.GetTargets()))
exists := make(map[string]bool)
var result sync.Map[string, error] // map[target host: error]
Expand All @@ -203,37 +196,36 @@ func (m *mirr) registers(
switch {
case errors.Is(err, context.Canceled):
err = status.WrapWithCanceled(
mirror.RegisterRPCName+" API canceld", err, reqInfo, resInfo,
mirror.RegisterRPCName+" API canceld", err,

Check warning on line 199 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L199

Added line #L199 was not covered by tests
)
attrs = trace.StatusCodeCancelled(err.Error())
case errors.Is(err, context.DeadlineExceeded):
err = status.WrapWithCanceled(
mirror.RegisterRPCName+" API deadline exceeded", err, reqInfo, resInfo,
mirror.RegisterRPCName+" API deadline exceeded", err,

Check warning on line 204 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L204

Added line #L204 was not covered by tests
)
attrs = trace.StatusCodeDeadlineExceeded(err.Error())
case errors.Is(err, errors.ErrGRPCClientConnNotFound("*")):
err = status.WrapWithInternal(
mirror.RegisterRPCName+" API connection not found", err, reqInfo, resInfo,
mirror.RegisterRPCName+" API connection not found", err,

Check warning on line 209 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L209

Added line #L209 was not covered by tests
)
attrs = trace.StatusCodeInternal(err.Error())
case errors.Is(err, errors.ErrTargetNotFound):
err = status.WrapWithInvalidArgument(
mirror.RegisterRPCName+" API target not found", err, reqInfo, resInfo,
mirror.RegisterRPCName+" API target not found", err,

Check warning on line 214 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L214

Added line #L214 was not covered by tests
)
attrs = trace.StatusCodeInvalidArgument(err.Error())
default:
var (
st *status.Status
msg string
)
st, msg, err = status.ParseError(err, codes.Internal,
"failed to parse "+mirror.RegisterRPCName+" gRPC error response", reqInfo, resInfo,
)
attrs = trace.FromGRPCStatus(st.Code(), msg)
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 219 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L218-L219

Added lines #L218 - L219 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code() and st.Message(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+mirror.RegisterRPCName+" gRPC error response")

Check warning on line 222 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L221-L222

Added lines #L221 - L222 were not covered by tests
}
attrs = trace.FromGRPCStatus(st.Code(), st.Message())

Check warning on line 224 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L224

Added line #L224 was not covered by tests

// When the ingress resource is deleted, the controller's default backend results(Unimplemented error) are returned so that the connection should be disconnected.
// If it is a different namespace on the same cluster, the connection is automatically disconnected because the net.grpc health check fails.
if st != nil && st.Code() == codes.Unimplemented {
if st.Code() == codes.Unimplemented {

Check warning on line 228 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L228

Added line #L228 was not covered by tests
host, port, err := net.SplitHostPort(target)
if err != nil {
log.Warn(err)
Expand All @@ -247,7 +239,7 @@ func (m *mirr) registers(
}
}
}
log.Error("failed to send Register API to %s\t: %v", target, err)
log.Errorf("failed to send Register API to %s\t: %v", target, err)

Check warning on line 242 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L242

Added line #L242 was not covered by tests
if span != nil {
span.RecordError(err)
span.SetAttributes(attrs...)
Expand Down Expand Up @@ -278,7 +270,7 @@ func (m *mirr) registers(
if err != nil {
if errors.Is(err, errors.ErrGRPCClientConnNotFound("*")) {
err = status.WrapWithInternal(
mirror.RegisterRPCName+" API connection not found", err, reqInfo, resInfo,
mirror.RegisterRPCName+" API connection not found", err,

Check warning on line 273 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L273

Added line #L273 was not covered by tests
)
log.Warn(err)
if span != nil {
Expand All @@ -288,11 +280,11 @@ func (m *mirr) registers(
}
return nil, err
}
log.Error(err)

Check warning on line 283 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L283

Added line #L283 was not covered by tests

st, msg, err := status.ParseError(err, codes.Internal,
"failed to parse "+mirror.RegisterRPCName+" gRPC error response", reqInfo, resInfo,
"failed to parse "+mirror.RegisterRPCName+" gRPC error response",

Check warning on line 286 in pkg/gateway/mirror/service/mirror.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/service/mirror.go#L286

Added line #L286 was not covered by tests
)
log.Warn(err)
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
Expand Down

0 comments on commit a41cfac

Please sign in to comment.