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

Backport PR #2811 to release/v1.7 for add Search_Config validation #2817

Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions internal/errors/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@

// ErrIndexNotFound represents an error that the index not found.
ErrIndexNotFound = New("index not found")

// ErrInvalidSearchConfig represents an error that the invalid Search Configuration.
ErrInvalidSearchConfig = func(msg string) error {
return Errorf("Invalid Search_Config: %s", msg)
}

Check warning on line 32 in internal/errors/lb.go

View check run for this annotation

Codecov / codecov/patch

internal/errors/lb.go#L30-L32

Added lines #L30 - L32 were not covered by tests
)
4 changes: 4 additions & 0 deletions pkg/gateway/lb/handler/grpc/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
}
}()

if bcfg == nil {
return nil, nil, errors.ErrInvalidSearchConfig("bcfg is nil in aggregationSearch")
}

Check warning on line 70 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L68-L70

Added lines #L68 - L70 were not covered by tests

num := aggr.GetNum()
min := int(bcfg.GetMinNum())

Expand Down
22 changes: 22 additions & 0 deletions pkg/gateway/lb/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,28 @@
}
}()

if cfg == nil {
err = errors.ErrInvalidSearchConfig("search config is nil in doSearch")
err = status.WrapWithInvalidArgument(apiName+"/doSearch", err, &errdetails.RequestInfo{
RequestId: "Search_Config is nil",
ServingData: "Search_Config is nil",
},
&errdetails.BadRequest{
FieldViolations: []*errdetails.BadRequestFieldViolation{
{
Field: "Search_Config is nil",
Description: err.Error(),
},
},
})
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeInvalidArgument(err.Error())...)
span.SetStatus(trace.StatusError, err.Error())
}
return nil, nil, err

Check warning on line 460 in pkg/gateway/lb/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/handler.go#L441-L460

Added lines #L441 - L460 were not covered by tests
}

var (
num = int(cfg.GetNum())
fnum int
Expand Down
5 changes: 5 additions & 0 deletions pkg/tools/cli/loadtest/service/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
}
ret = &payload.Search_Request{
Vector: v.([]float32),
Config: &payload.Search_Config{
Num: 10,
Radius: -1,
Epsilon: 0.1,
},

Check warning on line 41 in pkg/tools/cli/loadtest/service/search.go

View check run for this annotation

Codecov / codecov/patch

pkg/tools/cli/loadtest/service/search.go#L37-L41

Added lines #L37 - L41 were not covered by tests
}
}
return ret
Expand Down
Loading