Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add invalid id argument handling #1667

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TENSORFLOW_C_VERSION := $(eval TENSORFLOW_C_VERSION := $(shell cat versions/TENS
OPERATOR_SDK_VERSION := $(eval OPERATOR_SDK_VERSION := $(shell cat versions/OPERATOR_SDK_VERSION))$(OPERATOR_SDK_VERSION)

KIND_VERSION ?= v0.13.0
HELM_VERSION ?= v3.8.2
HELM_VERSION ?= v3.9.0
HELM_DOCS_VERSION ?= 1.10.0
YQ_VERSION ?= v4.25.1
VALDCLI_VERSION ?= v1.5.2
Expand Down
16 changes: 16 additions & 0 deletions pkg/agent/core/ngt/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (s *server) Exists(ctx context.Context, uid *payload.Object_ID) (res *paylo
ResourceType: ngtResourceType + "/ngt.Exists",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})

if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
log.Warn(err)
return nil, err
}
Expand Down Expand Up @@ -310,6 +314,9 @@ func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest)
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
log.Warn(err)
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
return nil, err
}
vec, dst, err := s.ngt.SearchByID(
Expand Down Expand Up @@ -813,6 +820,9 @@ func (s *server) LinearSearchByID(ctx context.Context, req *payload.Search_IDReq
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
log.Warn(err)
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
return nil, err
}
vec, dst, err := s.ngt.LinearSearchByID(
Expand Down Expand Up @@ -2021,6 +2031,9 @@ func (s *server) Remove(ctx context.Context, req *payload.Remove_Request) (res *
ResourceType: ngtResourceType + "/ngt.Remove",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
log.Warn(err)
return nil, err
}
Expand Down Expand Up @@ -2229,6 +2242,9 @@ func (s *server) GetObject(ctx context.Context, id *payload.Object_VectorRequest
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
log.Warn(err)
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
return nil, err
}
vec, err := s.ngt.GetObject(uuid)
Expand Down
122 changes: 112 additions & 10 deletions pkg/gateway/lb/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,33 @@ func (s *server) Exists(ctx context.Context, meta *payload.Object_ID) (id *paylo
span.End()
}
}()

uuid := meta.GetId()
if len(uuid) == 0 {
err = errors.ErrInvalidUUID(uuid)
err = status.WrapWithInvalidArgument(fmt.Sprintf("Exists API invalid argument for uuid \"%s\" detected", uuid), err,
&errdetails.RequestInfo{
RequestId: uuid,
ServingData: errdetails.Serialize(meta),
},
&errdetails.BadRequest{
FieldViolations: []*errdetails.BadRequestFieldViolation{
{
Field: "uuid",
Description: err.Error(),
},
},
},
&errdetails.ResourceInfo{
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.Exists",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
log.Warn(err)
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
return nil, err
}
ich := make(chan *payload.Object_ID, 1)
ech := make(chan error, 1)
s.eg.Go(func() error {
Expand All @@ -90,7 +117,7 @@ func (s *server) Exists(ctx context.Context, meta *payload.Object_ID) (id *paylo
}
}()
oid, err := vc.Exists(sctx, &payload.Object_ID{
Id: meta.GetId(),
Id: uuid,
}, copts...)
if err != nil {
switch {
Expand All @@ -117,9 +144,9 @@ func (s *server) Exists(ctx context.Context, meta *payload.Object_ID) (id *paylo
st *status.Status
msg string
)
st, msg, err = status.ParseError(err, codes.NotFound, fmt.Sprintf("error Exists API meta %s's uuid not found", meta.GetId()),
st, msg, err = status.ParseError(err, codes.NotFound, fmt.Sprintf("error Exists API meta %s's uuid not found", uuid),
&errdetails.RequestInfo{
RequestId: meta.GetId(),
RequestId: uuid,
ServingData: errdetails.Serialize(meta),
},
&errdetails.ResourceInfo{
Expand Down Expand Up @@ -152,11 +179,11 @@ func (s *server) Exists(ctx context.Context, meta *payload.Object_ID) (id *paylo
}
if err != nil || id == nil || id.GetId() == "" {
if err == nil {
err = errors.ErrObjectIDNotFound(meta.GetId())
err = errors.ErrObjectIDNotFound(uuid)
}
st, msg, err := status.ParseError(err, codes.NotFound, fmt.Sprintf("error Exists API meta %s's uuid not found", meta.GetId()),
st, msg, err := status.ParseError(err, codes.NotFound, fmt.Sprintf("error Exists API meta %s's uuid not found", uuid),
&errdetails.RequestInfo{
RequestId: meta.GetId(),
RequestId: uuid,
ServingData: errdetails.Serialize(meta),
},
&errdetails.ResourceInfo{
Expand Down Expand Up @@ -244,7 +271,8 @@ func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest)
span.End()
}
}()
if len(req.GetId()) == 0 {
uuid := req.GetId()
if len(uuid) == 0 {
err = errors.ErrInvalidMetaDataConfig
err = status.WrapWithInvalidArgument("SearchByID API invalid uuid", err,
&errdetails.RequestInfo{
Expand All @@ -258,6 +286,10 @@ func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest)
Description: err.Error(),
},
},
},
&errdetails.ResourceInfo{
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.SearchByID",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
Expand All @@ -266,7 +298,7 @@ func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest)
}
oreq := &payload.Object_VectorRequest{
Id: &payload.Object_ID{
Id: req.GetId(),
Id: uuid,
},
Filters: req.GetConfig().GetEgressFilters(),
}
Expand Down Expand Up @@ -1321,8 +1353,31 @@ func (s *server) Insert(ctx context.Context, req *payload.Insert_Request) (ce *p
span.End()
}
}()
vec := req.GetVector().GetVector()
uuid := req.GetVector().GetId()
if len(uuid) == 0 {
err = errors.ErrInvalidMetaDataConfig
err = status.WrapWithInvalidArgument("Insert API invalid uuid", err,
&errdetails.RequestInfo{
ServingData: errdetails.Serialize(req),
},
&errdetails.BadRequest{
FieldViolations: []*errdetails.BadRequestFieldViolation{
{
Field: "invalid id",
Description: err.Error(),
},
},
},
&errdetails.ResourceInfo{
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.Insert",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
return nil, err
}
vec := req.GetVector().GetVector()
vl := len(vec)
if vl < algorithm.MinimumVectorDimensionSize {
err = errors.ErrInvalidDimensionSize(vl, 0)
Expand Down Expand Up @@ -1699,8 +1754,31 @@ func (s *server) Update(ctx context.Context, req *payload.Update_Request) (res *
span.End()
}
}()
vec := req.GetVector().GetVector()
uuid := req.GetVector().GetId()
if len(uuid) == 0 {
err = errors.ErrInvalidMetaDataConfig
err = status.WrapWithInvalidArgument("Update API invalid uuid", err,
&errdetails.RequestInfo{
ServingData: errdetails.Serialize(req),
},
&errdetails.BadRequest{
FieldViolations: []*errdetails.BadRequestFieldViolation{
{
Field: "invalid id",
Description: err.Error(),
},
},
},
&errdetails.ResourceInfo{
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.Update",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
return nil, err
}
vec := req.GetVector().GetVector()
vl := len(vec)
if vl < algorithm.MinimumVectorDimensionSize {
err = errors.ErrInvalidDimensionSize(vl, 0)
Expand Down Expand Up @@ -2030,6 +2108,30 @@ func (s *server) Upsert(ctx context.Context, req *payload.Upsert_Request) (loc *

vec := req.GetVector()
uuid := vec.GetId()
if len(uuid) == 0 {
err = errors.ErrInvalidMetaDataConfig
err = status.WrapWithInvalidArgument("Upsert API invalid uuid", err,
&errdetails.RequestInfo{
ServingData: errdetails.Serialize(req),
},
&errdetails.BadRequest{
FieldViolations: []*errdetails.BadRequestFieldViolation{
{
Field: "invalid id",
Description: err.Error(),
},
},
},
&errdetails.ResourceInfo{
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.Upsert",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
if span != nil {
span.SetStatus(trace.StatusCodeInvalidArgument(err.Error()))
}
return nil, err
}

vl := len(vec.GetVector())
if vl < algorithm.MinimumVectorDimensionSize {
err = errors.ErrInvalidDimensionSize(vl, 0)
Expand Down