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 #2584 to release/v1.7 for Implement ngt property get API #2588

Merged

Conversation

vdaas-ci
Copy link
Collaborator

@vdaas-ci vdaas-ci commented Aug 22, 2024

Description

Add API for getting NGT Property

Related Issue

Versions

  • Vald Version: v1.7.13
  • Go Version: v1.22.6
  • Rust Version: v1.80.0
  • Docker Version: v27.1.1
  • Kubernetes Version: v1.30.3
  • Helm Version: v3.15.3
  • NGT Version: v2.2.4
  • Faiss Version: v1.8.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

  • New Features

    • Introduced detailed API documentation for index properties, enhancing usability and clarity.
    • Added a new RPC method to retrieve index properties.
    • Introduced new message types to manage index property configurations.
    • Added methods for retrieving detailed properties of the NGT index.
    • Enhanced server capabilities to handle concurrent requests for index property details.
  • Enhancements

    • New endpoint for retrieving index property details via GET request.
    • Expanded functionality in client and server implementations to support retrieval of index properties.
  • Documentation

    • Updated API documentation to reflect new endpoints and data structures.
    • Configured Codecov to ignore specific paths in coverage reporting for improved clarity.
  • Version Update

    • Updated version number from 1.22.6 to 1.23.0.

* add property to proto

Signed-off-by: Kosuke Morimoto <[email protected]>

* build proto files

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix rust API

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix unit test

Signed-off-by: Kosuke Morimoto <[email protected]>

* make format

Signed-off-by: Kosuke Morimoto <[email protected]>

* make format

Signed-off-by: Kosuke Morimoto <[email protected]>

* update

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix test

Signed-off-by: Kosuke Morimoto <[email protected]>

* add unit test

Signed-off-by: Kosuke Morimoto <[email protected]>

* style: format code with Gofumpt and Prettier

This commit fixes the style issues introduced in de3ef81 according to the output
from Gofumpt and Prettier.

Details: #2584

* add codecov.yml to ignore generated code

Signed-off-by: Kosuke Morimoto <[email protected]>

* make format

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix conflict

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* style: format code with Gofumpt and Prettier

This commit fixes the style issues introduced in 1d43dbb according to the output
from Gofumpt and Prettier.

Details: #2584

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* format

Signed-off-by: Kosuke Morimoto <[email protected]>

* add codecov ignore

Signed-off-by: Kosuke Morimoto <[email protected]>

* add unit test

Signed-off-by: Kosuke Morimoto <[email protected]>

---------

Signed-off-by: Kosuke Morimoto <[email protected]>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Copy link

cloudflare-workers-and-pages bot commented Aug 22, 2024

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: bf54494
Status: ✅  Deploy successful!
Preview URL: https://7a07f736.vald.pages.dev
Branch Preview URL: https://backport-release-v1-7-featur-6hhp.vald.pages.dev

View logs

Copy link
Contributor

coderabbitai bot commented Aug 22, 2024

Important

Review skipped

Review was skipped due to path filters

Files ignored due to path filters (2)
  • apis/grpc/v1/payload/payload.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • rust/Cargo.lock is excluded by !**/*.lock

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The changes introduce enhancements to the API documentation and functionality related to index properties across several components. New sections, methods, and data structures have been added to improve the management and retrieval of index properties through both gRPC and RESTful interfaces. Additionally, updates to Go module versions have been made across multiple files, ensuring consistency in the development environment.

Changes

Files Change Summary
apis/docs/v1/docs.md Added sections for Info.Index.Property, Info.Index.PropertyDetail, and Info.Index.PropertyDetail.DetailsEntry for detailed index property documentation.
apis/grpc/v1/vald/vald.go Introduced IndexPropertyRPCName constant to support RPC calls related to index properties.
apis/proto/v1/payload/payload.proto Added new message types Property and PropertyDetail for better indexing property representation.
apis/proto/v1/vald/index.proto Introduced IndexProperty RPC method for retrieving index properties via an HTTP GET endpoint.
apis/swagger/v1/vald/index.swagger.json Added new endpoint /index/property and schemas for IndexProperty and IndexPropertyDetail.
codecov.yml Added new configuration file to manage Codecov coverage reporting.
example/client/go.mod Updated Go version to 1.23.0 and module versions.
go.mod Updated Go version to 1.23.0 and dependencies.
internal/client/v1/client/vald/vald.go Added IndexProperty method to client structs for gRPC calls.
internal/core/algorithm/ngt/ngt.go Added GetProperty method and Property struct for NGT index management.
pkg/agent/core/ngt/handler/grpc/index.go Added IndexProperty method to server for handling index property requests.
rust/libs/proto/src/payload.v1.rs Introduced Property and PropertyDetail structures for indexing properties.
versions/GO_VERSION Updated version number from 1.22.6 to 1.23.0.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vdaas-ci
Copy link
Collaborator Author

[WARNING:CONFLICT] You may require to fix the conflict. Please check.

@vdaas-ci
Copy link
Collaborator Author

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (5)
internal/core/algorithm/ngt/ngt.go (1)

162-197: Define Property struct.

The Property struct encapsulates various NGT index properties. Ensure all fields are necessary and consider adding comments for clarity.

	Property struct {
+		// Dimension represents the dimensionality of the index.
		Dimension                     int32
+		// ThreadPoolSize specifies the size of the thread pool.
		ThreadPoolSize                int32
		// ... (add comments for other fields as needed)
	}
apis/docs/v1/docs.md (3)

328-368: Add descriptions for fields in Info.Index.Property.

The fields in this section are clearly listed, but adding descriptions would enhance understanding and usability of the documentation.


371-378: Add descriptions for fields in Info.Index.PropertyDetail.

Providing descriptions for the fields would improve the clarity and usability of the documentation.


381-387: Add descriptions for fields in Info.Index.PropertyDetail.DetailsEntry.

Including descriptions for the fields would enhance the documentation's clarity and usability.

internal/core/algorithm/ngt/ngt_test.go (1)

4769-4885: LGTM! Minor readability improvement suggested.

The test function Test_ngt_Property is well-structured and comprehensive. It effectively validates the properties of the NGT structure.

For improved readability, consider using a loop to iterate over the properties being checked in the checkFunc. This can reduce repetitive code and make it easier to add additional checks in the future.

Example:

checkFunc := func(w want, p *Property, err error) error {
	if err := defaultCheckFunc(w, p, err); err != nil {
		return err
	}

	properties := map[string]interface{}{
		"Dimension":    p.Dimension,
		"ObjectType":   p.ObjectType,
		"DistanceType": p.DistanceType,
		"IndexType":    p.IndexType,
		"DatabaseType": p.DatabaseType,
		"GraphType":    p.GraphType,
	}

	for name, got := range properties {
		want := reflect.ValueOf(w.want).Elem().FieldByName(name).Interface()
		if !reflect.DeepEqual(got, want) {
			return errors.Errorf("got_%s: \"%v\", want_%s: \"%v\"", name, got, name, want)
		}
	}

	return nil
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7fe3c9c and 78e4254.

Files ignored due to path filters (9)
  • apis/grpc/v1/agent/sidecar/sidecar_vtproto.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/payload/payload.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/payload/payload.pb.json.go is excluded by !**/*.pb.json.go
  • apis/grpc/v1/payload/payload_vtproto.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/vald/index.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/vald/index_vtproto.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • example/client/go.sum is excluded by !**/*.sum
  • go.sum is excluded by !**/*.sum
  • rust/Cargo.lock is excluded by !**/*.lock
Files selected for processing (25)
  • apis/docs/v1/docs.md (3 hunks)
  • apis/grpc/v1/vald/vald.go (1 hunks)
  • apis/proto/v1/payload/payload.proto (1 hunks)
  • apis/proto/v1/vald/index.proto (1 hunks)
  • apis/swagger/v1/vald/index.swagger.json (2 hunks)
  • codecov.yml (1 hunks)
  • example/client/go.mod (2 hunks)
  • example/client/go.mod.default (1 hunks)
  • go.mod (16 hunks)
  • hack/go.mod.default (1 hunks)
  • internal/client/v1/client/vald/vald.go (2 hunks)
  • internal/core/algorithm/ngt/ngt.go (7 hunks)
  • internal/core/algorithm/ngt/ngt_test.go (1 hunks)
  • internal/core/algorithm/ngt/option.go (1 hunks)
  • internal/net/http/client/client_test.go (1 hunks)
  • pkg/agent/core/ngt/handler/grpc/index.go (1 hunks)
  • pkg/agent/core/ngt/handler/grpc/index_test.go (2 hunks)
  • pkg/agent/core/ngt/service/ngt.go (2 hunks)
  • pkg/gateway/lb/handler/grpc/handler.go (1 hunks)
  • rust/bin/agent/src/handler/index.rs (1 hunks)
  • rust/libs/proto/src/filter.egress.v1.tonic.rs (2 hunks)
  • rust/libs/proto/src/filter.ingress.v1.tonic.rs (2 hunks)
  • rust/libs/proto/src/payload.v1.rs (1 hunks)
  • rust/libs/proto/src/vald.v1.tonic.rs (9 hunks)
  • versions/GO_VERSION (1 hunks)
Files skipped from review due to trivial changes (5)
  • codecov.yml
  • example/client/go.mod.default
  • rust/libs/proto/src/filter.egress.v1.tonic.rs
  • rust/libs/proto/src/filter.ingress.v1.tonic.rs
  • versions/GO_VERSION
Additional comments not posted (29)
example/client/go.mod (2)

3-3: Upgrade to Go 1.23.0.

The Go version has been updated from 1.22.6 to 1.23.0. Ensure compatibility with the rest of the codebase and verify if any new language features or changes need to be addressed.


14-16: Dependency updates for google.golang.org/genproto.

The google.golang.org/genproto dependencies have been updated to a newer version. Verify that these updates do not introduce breaking changes and are compatible with the rest of the codebase.

apis/proto/v1/vald/index.proto (1)

49-52: Addition of IndexProperty RPC method.

The IndexProperty method has been added to the Index service, providing a way to retrieve index properties. Ensure that the corresponding server-side implementation and client-side usage are correctly handled.

apis/grpc/v1/vald/vald.go (1)

142-142: Addition of IndexPropertyRPCName is appropriate.

The new constant IndexPropertyRPCName is added consistently with the existing pattern of RPC name constants.

internal/net/http/client/client_test.go (1)

49-49: Ignoring dialsInProgress in transportComparator is valid.

Adding "dialsInProgress" to the ignored fields in the comparator is a sensible change, as it likely represents a transient state that should not affect test outcomes.

pkg/agent/core/ngt/handler/grpc/index.go (1)

244-262: Addition of IndexProperty method is well-implemented.

The new IndexProperty method follows the existing patterns for error handling and tracing, making it a consistent and well-structured addition to the codebase.

internal/core/algorithm/ngt/option.go (1)

112-112: LGTM! Initialization change enhances clarity.

The initialization of d to DistanceNone provides a clear starting state, which is beneficial for the subsequent logic.

apis/swagger/v1/vald/index.swagger.json (2)

169-300: New object definitions IndexProperty and IndexPropertyDetail added.

The new object definitions provide a structured way to represent index properties, enhancing the API's functionality.


57-77: New endpoint /index/property added.

The addition of the /index/property endpoint enhances the API by providing a way to retrieve index properties.

Ensure that this endpoint is properly integrated and tested within the system.

Run the following script to check for the integration of the new endpoint in the codebase:

apis/proto/v1/payload/payload.proto (2)

594-630: New message type Property added.

The Property message type encapsulates detailed index properties, enhancing the data model.


632-635: New message type PropertyDetail added.

The PropertyDetail message type allows for flexible handling of multiple index properties using a map structure.

Ensure that these new message types are correctly utilized in the codebase.

Run the following script to check for the usage of the new message types:

Verification successful

New message types Property and PropertyDetail are correctly utilized.

The Property and PropertyDetail message types are integrated into various parts of the codebase, including RPC calls and service definitions, confirming their correct utilization.

  • PropertyDetail is used in RPC calls such as IndexProperty.
  • Property is referenced in multiple files, including C++ and Rust code.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `Property` and `PropertyDetail` message types.

# Test: Search for the message types usage. Expect: Occurrences of the new message types in the codebase.
rg --type proto 'Property|PropertyDetail'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the usage of `Property` and `PropertyDetail` message types in .proto files.

# Find all .proto files and search for the message types usage.
fd --extension proto --exec rg 'Property|PropertyDetail' {}

Length of output: 276


Script:

#!/bin/bash
# Description: Verify the usage of `Property` and `PropertyDetail` message types in the entire codebase.

# Search for the message types usage in all files.
rg 'Property|PropertyDetail'

Length of output: 24464

hack/go.mod.default (2)

3-3: Update Go version to 1.23.0.

The Go version has been updated from 1.22.6 to 1.23.0. Ensure compatibility with the new Go version across the codebase.


5-5: Upgrade dependencies.

The replace directive indicates that several dependencies are set to upgrade. Ensure these upgrades are compatible with the rest of the codebase and do not introduce breaking changes.

internal/core/algorithm/ngt/ngt.go (4)

90-91: Add GetProperty method to NGT interface.

The GetProperty method has been added to the NGT interface to retrieve index properties. Ensure this method is properly tested and documented.


226-239: Define new types for index properties.

New types indexType, databaseType, objectAlignment, seedType, and graphType have been defined to enhance type safety. Ensure these types are used consistently throughout the codebase.


399-463: Implement stringer methods for new types.

Stringer methods have been implemented for the new types, providing human-readable representations. Ensure these methods cover all possible values and consider adding tests.


1160-1199: Implement GetProperty method.

The GetProperty method retrieves NGT index properties using C API calls. Ensure error handling is robust and consider adding unit tests for this method.

go.mod (2)

3-3: Update Go version to 1.23.0.

The Go version has been updated from 1.22.6 to 1.23.0. Ensure compatibility with the new Go version across the codebase.


Line range hint 6-321: Upgrade dependencies.

Several dependencies have been updated to newer versions. Ensure these upgrades are compatible with the rest of the codebase and do not introduce breaking changes.

internal/client/v1/client/vald/vald.go (2)

831-851: LGTM! The IndexProperty method is well-implemented.

The method correctly handles gRPC calls with context tracing and round-robin strategy for load balancing.


1295-1305: LGTM! The IndexProperty method in singleClient is correctly implemented.

The method maintains consistency with other methods in the singleClient structure.

rust/libs/proto/src/payload.v1.rs (2)

959-1031: LGTM! The Property struct is well-defined.

The fields are appropriately annotated for serialization using the Prost library.


1032-1038: LGTM! The PropertyDetail struct is correctly implemented.

The use of a HashMap is appropriate for organizing and retrieving multiple indexing properties.

pkg/agent/core/ngt/service/ngt.go (1)

2048-2089: LGTM! The IndexProperty method is well-implemented.

The method efficiently retrieves and constructs a detailed structure of index properties.

pkg/agent/core/ngt/handler/grpc/index_test.go (1)

2623-2623: Good use of goleak.VerifyNone.

The use of goleak.VerifyNone helps ensure that there are no goroutine leaks during the test execution.

apis/docs/v1/docs.md (1)

1635-1635: Addition of IndexProperty RPC method is appropriate.

The IndexProperty method is a valuable addition to the RPC section, aligning with the API's functionality.

pkg/gateway/lb/handler/grpc/handler.go (1)

4065-4179: Verify error handling and consider performance optimizations.

The IndexProperty function is well-structured with robust error handling and tracing capabilities. However, ensure that all potential errors are correctly handled, especially in the context of concurrent operations. Additionally, consider optimizing the performance by evaluating the use of channels and mutexes, particularly in high-concurrency scenarios.

Run the following script to verify the error handling and concurrency management in the codebase:

Verification successful

Error handling and concurrency management are correctly implemented.

The IndexProperty function in pkg/gateway/lb/handler/grpc/handler.go demonstrates robust error handling and appropriate use of concurrency mechanisms. The function effectively uses a mutex to manage concurrent access to shared resources and handles various error scenarios comprehensively.

  • Location: pkg/gateway/lb/handler/grpc/handler.go, lines 4065-4179
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling and concurrency management in the `IndexProperty` function.

# Test: Search for error handling and mutex usage. Expect: Correct usage and handling.
rg --type go -A 5 'func (s \*server) IndexProperty'

Length of output: 53


Script:

#!/bin/bash
# Description: Verify error handling and concurrency management in the `IndexProperty` function.

# Test: Search for the complete implementation of the `IndexProperty` function.
ast-grep --lang go --pattern 'func (s *server) IndexProperty($_, $_) ($_, $_) {
  $$$
}'

Length of output: 10833

rust/libs/proto/src/vald.v1.tonic.rs (2)

1836-1864: Addition of index_property method in index_client.

The addition of the index_property method is well-structured and follows the existing pattern for gRPC client methods. It includes proper error handling and codec configuration.


1908-1918: Addition of index_property method in index_server.

The index_property method is correctly defined and aligns with the structure of other server methods. It provides a clear interface for implementing the retrieval of index properties.

Comment on lines +81 to +85
async fn index_property(
&self,
request: tonic::Request<Empty>,
) -> std::result::Result<tonic::Response<info::index::PropertyDetail>, tonic::Status> {
todo!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the index_property function.

The index_property function is currently a placeholder. Implement the logic to handle RPC requests for retrieving index properties.

Would you like assistance in implementing this function or opening a GitHub issue to track this task?

Comment on lines +2477 to +2652
},
want: want{
wantRes: &payload.Info_Index_PropertyDetail{
Details: map[string]*payload.Info_Index_Property{
name: {},
},
},
},
checkFunc: func(w want, gotRes *payload.Info_Index_PropertyDetail, err error) error {
if !errors.Is(err, w.err) {
return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err)
}
if val, ok := gotRes.Details[name]; ok {
gotType := reflect.TypeOf(val)
wantType := reflect.TypeOf(&payload.Info_Index_Property{})
if gotType != wantType {
return errors.Errorf("got_type: \"%s\", want_type: \"%s\"", gotType, wantType)
}
} else {
return errors.Errorf("do not exists key: %s", name)
}
return nil
},
beforeFunc: func(t *testing.T, args args) {
t.Helper()
},
afterFunc: func(t *testing.T, args args) {
t.Helper()
},
},

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
ctx:nil,
in1:nil,
},
fields: fields {
name:"",
ip:"",
ngt:nil,
eg:nil,
streamConcurrency:0,
UnimplementedAgentServer:nil,
UnimplementedValdServer:nil,
},
want: want{},
checkFunc: defaultCheckFunc,
beforeFunc: func(t *testing.T, args args) {
t.Helper()
},
afterFunc: func(t *testing.T, args args) {
t.Helper()
},
}
}(),
*/
}

for _, tc := range tests {
test := tc
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

defer goleak.VerifyNone(tt, goleak.IgnoreCurrent())
if test.beforeFunc != nil {
test.beforeFunc(tt, test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(tt, test.args)
}
checkFunc := test.checkFunc
if test.checkFunc == nil {
checkFunc = defaultCheckFunc
}
eg, _ := errgroup.New(ctx)
ngt, err := service.New(test.fields.svcCfg, append(test.fields.svcOpts, service.WithErrGroup(eg))...)
if err != nil {
tt.Errorf("failed to init ngt service, error = %v", err)
}
s, err := New(
WithErrGroup(eg),
WithNGT(ngt),
WithIP(ip),
WithName(name),
)

gotRes, err := s.IndexProperty(ctx, test.args.in)
if err := checkFunc(test.want, gotRes, err); err != nil {
tt.Errorf("error = %v", err)
}
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding more test cases for IndexProperty.

The current test function only includes one test case. Consider adding more cases to cover different scenarios and edge cases for the IndexProperty method.

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 19.37984% with 208 lines in your changes missing coverage. Please review.

Please upload report for BASE (release/v1.7@7fe3c9c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pkg/gateway/lb/handler/grpc/handler.go 0.00% 92 Missing ⚠️
internal/core/algorithm/ngt/ngt.go 43.95% 51 Missing ⚠️
pkg/agent/core/ngt/service/ngt.go 0.00% 40 Missing ⚠️
internal/client/v1/client/vald/vald.go 0.00% 21 Missing ⚠️
pkg/agent/core/ngt/handler/grpc/index.go 69.23% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##             release/v1.7    #2588   +/-   ##
===============================================
  Coverage                ?   24.55%           
===============================================
  Files                   ?      530           
  Lines                   ?    45505           
  Branches                ?        0           
===============================================
  Hits                    ?    11172           
  Misses                  ?    33586           
  Partials                ?      747           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (9)
pkg/agent/core/ngt/handler/grpc/index.go (1)

253-255: Handle errors with detailed logging.

The error returned from s.ngt.IndexProperty() is not logged. Consider adding logging for better traceability.

Apply this diff to add error logging:

 if err != nil {
+  log.Error(err)
   return nil, err
 }
apis/swagger/v1/vald/index.swagger.json (1)

169-299: Review property descriptions for completeness.

Some properties in the IndexProperty schema lack descriptions. Consider adding descriptions for all properties to enhance clarity.

apis/proto/v1/payload/payload.proto (1)

595-630: Add field comments for clarity.

Consider adding comments for each field in the Property message to describe their purpose and usage.

pkg/agent/core/ngt/handler/grpc/index_test.go (1)

2477-2652: LGTM! Consider adding more test cases.

The test function Test_server_IndexProperty is well-structured and correctly tests the IndexProperty method. However, it currently includes only one test case. Consider adding more test cases to cover additional scenarios and edge cases.

apis/docs/v1/docs.md (2)

326-368: Add descriptions for each field in Info.Index.Property.

The section outlines various attributes associated with index properties, but it lacks descriptions for each field. Adding descriptions will improve clarity and usability.


379-387: Add descriptions for fields in Info.Index.PropertyDetail.DetailsEntry.

The section defines the structure for individual detail entries but lacks descriptions for the fields. Adding descriptions will enhance understanding.

pkg/gateway/lb/handler/grpc/handler.go (1)

4065-4067: Consider Adding Documentation for IndexProperty.

Adding a brief comment explaining the purpose and functionality of the IndexProperty method would improve code readability and maintainability.

// IndexProperty retrieves and aggregates index property details from multiple agents.
rust/libs/proto/src/vald.v1.tonic.rs (2)

1836-1864: Incomplete Implementation Detected for index_property Method

The index_property method is defined and referenced in the codebase, but its implementation in rust/bin/agent/src/handler/index.rs is incomplete, marked with todo!(). Ensure this method is fully implemented and integrated into the codebase.

  • rust/bin/agent/src/handler/index.rs: Implementation is incomplete.
Analysis chain

LGTM! Verify the method usage in the codebase.

The index_property method is correctly implemented. Ensure that all calls to this method are correctly integrated into the codebase.

Run the following script to verify the method usage:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `index_property` are correctly integrated.

# Test: Search for the function usage. Expect: Occurrences of the new method.
rg --type rust -A 5 $'index_property'

Length of output: 1981


1908-1918: Incomplete Integration of index_property Method

The index_property method is defined but not yet fully integrated or called within the codebase. It appears in the following locations:

  • Defined with todo!() in rust/bin/agent/src/handler/index.rs, indicating incomplete implementation.
  • Part of a trait implementation in rust/libs/proto/src/vald.v1.tonic.rs.

Ensure that this method is fully implemented and properly integrated into the application.

Analysis chain

LGTM! Verify the method usage in the codebase.

The index_property method is correctly implemented. Ensure that all calls to this method are correctly integrated into the codebase.

Run the following script to verify the method usage:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `index_property` are correctly integrated.

# Test: Search for the function usage. Expect: Occurrences of the new method.
rg --type rust -A 5 $'index_property'

Length of output: 1981


Script:

#!/bin/bash
# Description: Search for calls to the `index_property` method to verify its integration.

# Test: Search for calls to the `index_property` method.
rg --type rust 'index_property\('

Length of output: 365

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7fe3c9c and 78e4254.

Files ignored due to path filters (9)
  • apis/grpc/v1/agent/sidecar/sidecar_vtproto.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/payload/payload.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/payload/payload.pb.json.go is excluded by !**/*.pb.json.go
  • apis/grpc/v1/payload/payload_vtproto.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/vald/index.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/vald/index_vtproto.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • example/client/go.sum is excluded by !**/*.sum
  • go.sum is excluded by !**/*.sum
  • rust/Cargo.lock is excluded by !**/*.lock
Files selected for processing (25)
  • apis/docs/v1/docs.md (3 hunks)
  • apis/grpc/v1/vald/vald.go (1 hunks)
  • apis/proto/v1/payload/payload.proto (1 hunks)
  • apis/proto/v1/vald/index.proto (1 hunks)
  • apis/swagger/v1/vald/index.swagger.json (2 hunks)
  • codecov.yml (1 hunks)
  • example/client/go.mod (2 hunks)
  • example/client/go.mod.default (1 hunks)
  • go.mod (16 hunks)
  • hack/go.mod.default (1 hunks)
  • internal/client/v1/client/vald/vald.go (2 hunks)
  • internal/core/algorithm/ngt/ngt.go (7 hunks)
  • internal/core/algorithm/ngt/ngt_test.go (1 hunks)
  • internal/core/algorithm/ngt/option.go (1 hunks)
  • internal/net/http/client/client_test.go (1 hunks)
  • pkg/agent/core/ngt/handler/grpc/index.go (1 hunks)
  • pkg/agent/core/ngt/handler/grpc/index_test.go (2 hunks)
  • pkg/agent/core/ngt/service/ngt.go (2 hunks)
  • pkg/gateway/lb/handler/grpc/handler.go (1 hunks)
  • rust/bin/agent/src/handler/index.rs (1 hunks)
  • rust/libs/proto/src/filter.egress.v1.tonic.rs (2 hunks)
  • rust/libs/proto/src/filter.ingress.v1.tonic.rs (2 hunks)
  • rust/libs/proto/src/payload.v1.rs (1 hunks)
  • rust/libs/proto/src/vald.v1.tonic.rs (9 hunks)
  • versions/GO_VERSION (1 hunks)
Files skipped from review due to trivial changes (5)
  • codecov.yml
  • internal/core/algorithm/ngt/option.go
  • rust/libs/proto/src/filter.egress.v1.tonic.rs
  • rust/libs/proto/src/filter.ingress.v1.tonic.rs
  • versions/GO_VERSION
Additional context used
GitHub Check: codecov/patch
internal/core/algorithm/ngt/ngt.go

[warning] 399-404: internal/core/algorithm/ngt/ngt.go#L399-L404
Added lines #L399 - L404 were not covered by tests


[warning] 406-406: internal/core/algorithm/ngt/ngt.go#L406
Added line #L406 was not covered by tests


[warning] 409-414: internal/core/algorithm/ngt/ngt.go#L409-L414
Added lines #L409 - L414 were not covered by tests


[warning] 416-416: internal/core/algorithm/ngt/ngt.go#L416
Added line #L416 was not covered by tests


[warning] 419-424: internal/core/algorithm/ngt/ngt.go#L419-L424
Added lines #L419 - L424 were not covered by tests


[warning] 426-426: internal/core/algorithm/ngt/ngt.go#L426
Added line #L426 was not covered by tests


[warning] 429-438: internal/core/algorithm/ngt/ngt.go#L429-L438
Added lines #L429 - L438 were not covered by tests


[warning] 440-440: internal/core/algorithm/ngt/ngt.go#L440
Added line #L440 was not covered by tests


[warning] 443-460: internal/core/algorithm/ngt/ngt.go#L443-L460
Added lines #L443 - L460 were not covered by tests


[warning] 462-462: internal/core/algorithm/ngt/ngt.go#L462
Added line #L462 was not covered by tests

Additional comments not posted (25)
example/client/go.mod.default (1)

3-3: Go version update acknowledged.

The Go version has been updated to 1.23.0. Ensure compatibility with the updated version.

example/client/go.mod (1)

3-3: Go version and dependency updates acknowledged.

The Go version has been updated to 1.23.0, and several dependencies have been updated. Ensure compatibility with the updated versions.

Also applies to: 14-16

apis/proto/v1/vald/index.proto (1)

49-52: New RPC method IndexProperty added.

The addition of the IndexProperty RPC method enhances the service's functionality by providing a way to retrieve index properties.

rust/bin/agent/src/handler/index.rs (1)

80-86: Documentation and structure look good.

The documentation and function structure are consistent with the rest of the trait implementation.

apis/grpc/v1/vald/vald.go (1)

142-142: Addition of IndexPropertyRPCName is approved.

The new constant aligns with the existing pattern for RPC names and enhances the functionality of the RPC client.

internal/net/http/client/client_test.go (1)

49-49: Update to transportComparator is approved.

The addition of "dialsInProgress" to the ignored fields enhances test robustness by excluding a non-essential field from comparisons.

apis/swagger/v1/vald/index.swagger.json (2)

57-76: Ensure operation ID consistency.

The operation ID Index_IndexProperty should be consistent with naming conventions used in other endpoints. Verify that it aligns with the project's standards.


301-312: Ensure schema title consistency.

The title "Represents index Properties for each Agents" should be consistent with other schema titles. Verify that it aligns with the project's naming conventions.

apis/proto/v1/payload/payload.proto (1)

632-635: Ensure map key consistency.

The map key in PropertyDetail should be consistent with other map keys used in the protocol. Verify that it aligns with the project's standards.

hack/go.mod.default (1)

3-3: LGTM: Go version and dependency updates.

The updates to the Go version and dependencies are appropriate and align with the project's needs.

Also applies to: 6-6, 8-8, 11-11, 12-12, 13-13, 15-15, 17-17

internal/core/algorithm/ngt/ngt.go (2)

90-91: LGTM: New GetProperty method and Property struct.

The addition of the GetProperty method and Property struct enhances the functionality by providing structured access to NGT properties.

Also applies to: 1160-1200


399-407: Add tests for stringer methods.

The stringer methods for the new types are not covered by tests. Consider adding unit tests to ensure they return the expected string representations.

Would you like assistance in generating the test cases for these methods?

Also applies to: 409-417, 419-427, 429-441, 443-463

Tools
GitHub Check: codecov/patch

[warning] 399-404: internal/core/algorithm/ngt/ngt.go#L399-L404
Added lines #L399 - L404 were not covered by tests


[warning] 406-406: internal/core/algorithm/ngt/ngt.go#L406
Added line #L406 was not covered by tests

go.mod (1)

3-3: LGTM: Go version and dependency updates.

The updates to the Go version and dependencies are appropriate and align with the project's needs.

Also applies to: 6-6, 8-8, 11-11, 12-12, 13-13, 15-15, 17-17, 39-39, 41-42, 48-69, 240-240, 296-296, 298-299, 307-307, 314-314, 317-317, 319-321

internal/client/v1/client/vald/vald.go (2)

831-851: New Method Addition: IndexProperty in client.

The IndexProperty method is well-structured, consistent with other methods in the file, and effectively manages tracing and error handling.


1295-1305: New Method Addition: IndexProperty in singleClient.

The IndexProperty method is consistent with the existing methods, effectively managing tracing and error handling.

rust/libs/proto/src/payload.v1.rs (2)

959-1031: New Struct Addition: Property.

The Property struct is well-defined with appropriate data types for each field, aligning with the intended use.


1032-1038: New Struct Addition: PropertyDetail.

The PropertyDetail struct is well-structured, effectively allowing for the management of multiple indexing configurations.

pkg/agent/core/ngt/service/ngt.go (1)

2048-2089: New Method Addition: IndexProperty in ngt.

The IndexProperty method is well-implemented, with proper error handling and data mapping, aligning with the intended functionality.

apis/docs/v1/docs.md (2)

369-378: Section Info.Index.PropertyDetail is clear and concise.

The section accurately represents index properties for each agent.


1635-1635: Addition of IndexProperty to RPC definitions is clear and consistent.

The addition aligns well with existing RPC definitions.

internal/core/algorithm/ngt/ngt_test.go (1)

4769-4885: Ensure comprehensive test coverage for all fields.

The test function Test_ngt_Property is well-structured and verifies multiple fields of the Property struct. Ensure that all relevant fields of the Property struct are covered in the test cases to maintain comprehensive test coverage.

pkg/gateway/lb/handler/grpc/handler.go (4)

4068-4073: Ensure Proper Span Closure.

The span is being checked for nil before calling End(), which is good practice. Ensure this pattern is consistently applied across all methods.


4074-4078: Initialize Detail with Capacity.

The Details map is initialized with a capacity equal to the number of agents. This is a good practice to optimize memory allocation.


4080-4140: Handle Errors in Goroutine Properly.

The goroutine uses a channel to communicate errors back to the main function. Ensure that the channel is closed properly and that all potential errors are captured.


4146-4178: Comprehensive Error Handling.

The method includes comprehensive error handling with detailed tracing and logging. This is a good practice for maintaining robust and debuggable code.

Comment on lines +80 to +86
#[doc = " Represent the RPC to get the index property.\n"]
async fn index_property(
&self,
request: tonic::Request<Empty>,
) -> std::result::Result<tonic::Response<info::index::PropertyDetail>, tonic::Status> {
todo!()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the index_property function.

The function is currently a placeholder with todo!(). Consider implementing the function to handle RPC requests for retrieving index properties.

Do you want me to help with the implementation or open a GitHub issue to track this task?

Comment on lines +244 to +262
func (s *server) IndexProperty(
ctx context.Context, _ *payload.Empty,
) (res *payload.Info_Index_PropertyDetail, err error) {
_, span := trace.StartSpan(ctx, apiName+".IndexStatisticsDetail")
defer func() {
if span != nil {
span.End()
}
}()
prop, err := s.ngt.IndexProperty()
if err != nil {
return nil, err
}
return &payload.Info_Index_PropertyDetail{
Details: map[string]*payload.Info_Index_Property{
s.name: prop,
},
}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistency in tracing span naming.

The tracing span name is set to IndexStatisticsDetail, which seems inconsistent with the method name IndexProperty. Consider updating it for clarity.

Apply this diff to correct the span name:

 _, span := trace.StartSpan(ctx, apiName+".IndexStatisticsDetail")
+_, span := trace.StartSpan(ctx, apiName+".IndexProperty")
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *server) IndexProperty(
ctx context.Context, _ *payload.Empty,
) (res *payload.Info_Index_PropertyDetail, err error) {
_, span := trace.StartSpan(ctx, apiName+".IndexStatisticsDetail")
defer func() {
if span != nil {
span.End()
}
}()
prop, err := s.ngt.IndexProperty()
if err != nil {
return nil, err
}
return &payload.Info_Index_PropertyDetail{
Details: map[string]*payload.Info_Index_Property{
s.name: prop,
},
}, nil
}
func (s *server) IndexProperty(
ctx context.Context, _ *payload.Empty,
) (res *payload.Info_Index_PropertyDetail, err error) {
_, span := trace.StartSpan(ctx, apiName+".IndexProperty")
defer func() {
if span != nil {
span.End()
}
}()
prop, err := s.ngt.IndexProperty()
if err != nil {
return nil, err
}
return &payload.Info_Index_PropertyDetail{
Details: map[string]*payload.Info_Index_Property{
s.name: prop,
},
}, nil
}

Comment on lines +4090 to +4135
prop, err = vc.IndexProperty(sctx, new(payload.Empty), copts...)
if err != nil {
var (
attrs trace.Attributes
st *status.Status
msg string
code codes.Code
)
switch {
case errors.Is(err, context.Canceled), errors.Is(err, errors.ErrRPCCallFailed(target, context.Canceled)):
attrs = trace.StatusCodeCancelled(
errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.IndexPropertyRPCName + ".BroadCast/" + target + " canceled: " + err.Error())
code = codes.Canceled
case errors.Is(err, context.DeadlineExceeded), errors.Is(err, errors.ErrRPCCallFailed(target, context.DeadlineExceeded)):
attrs = trace.StatusCodeDeadlineExceeded(
errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.IndexPropertyRPCName + ".BroadCast/" + target + " deadline_exceeded: " + err.Error())
code = codes.DeadlineExceeded
default:
st, msg, err = status.ParseError(err, codes.NotFound, "error "+vald.IndexPropertyRPCName+" API",
&errdetails.ResourceInfo{
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.IndexPropertyRPCName + ".BroadCast/" + target,
ResourceName: fmt.Sprintf("%s: %s(%s) to %s", apiName, s.name, s.ip, target),
})
if st != nil {
code = st.Code()
} else {
code = codes.NotFound
}
attrs = trace.FromGRPCStatus(code, msg)
}
if sspan != nil {
sspan.RecordError(err)
sspan.SetAttributes(attrs...)
sspan.SetStatus(trace.StatusError, err.Error())
}
if err != nil && st != nil && code != codes.Canceled && code != codes.DeadlineExceeded && code != codes.InvalidArgument && code != codes.NotFound && code != codes.OK && code != codes.Unimplemented {
return err
}
return nil
}
if prop != nil {
mu.Lock()
for key, value := range prop.Details {
detail.Details[target+"-"+key] = value
}
mu.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for Nil Property Before Accessing Details.

Before accessing prop.Details, ensure prop is not nil to avoid potential runtime panics.

 if prop != nil {
+  if prop.Details != nil {
     mu.Lock()
     for key, value := range prop.Details {
       detail.Details[target+"-"+key] = value
     }
     mu.Unlock()
+  }
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
prop, err = vc.IndexProperty(sctx, new(payload.Empty), copts...)
if err != nil {
var (
attrs trace.Attributes
st *status.Status
msg string
code codes.Code
)
switch {
case errors.Is(err, context.Canceled), errors.Is(err, errors.ErrRPCCallFailed(target, context.Canceled)):
attrs = trace.StatusCodeCancelled(
errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.IndexPropertyRPCName + ".BroadCast/" + target + " canceled: " + err.Error())
code = codes.Canceled
case errors.Is(err, context.DeadlineExceeded), errors.Is(err, errors.ErrRPCCallFailed(target, context.DeadlineExceeded)):
attrs = trace.StatusCodeDeadlineExceeded(
errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.IndexPropertyRPCName + ".BroadCast/" + target + " deadline_exceeded: " + err.Error())
code = codes.DeadlineExceeded
default:
st, msg, err = status.ParseError(err, codes.NotFound, "error "+vald.IndexPropertyRPCName+" API",
&errdetails.ResourceInfo{
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.IndexPropertyRPCName + ".BroadCast/" + target,
ResourceName: fmt.Sprintf("%s: %s(%s) to %s", apiName, s.name, s.ip, target),
})
if st != nil {
code = st.Code()
} else {
code = codes.NotFound
}
attrs = trace.FromGRPCStatus(code, msg)
}
if sspan != nil {
sspan.RecordError(err)
sspan.SetAttributes(attrs...)
sspan.SetStatus(trace.StatusError, err.Error())
}
if err != nil && st != nil && code != codes.Canceled && code != codes.DeadlineExceeded && code != codes.InvalidArgument && code != codes.NotFound && code != codes.OK && code != codes.Unimplemented {
return err
}
return nil
}
if prop != nil {
mu.Lock()
for key, value := range prop.Details {
detail.Details[target+"-"+key] = value
}
mu.Unlock()
if prop != nil {
if prop.Details != nil {
mu.Lock()
for key, value := range prop.Details {
detail.Details[target+"-"+key] = value
}
mu.Unlock()
}
}

Signed-off-by: Kosuke Morimoto <[email protected]>
Signed-off-by: Kosuke Morimoto <[email protected]>
@kmrmt kmrmt merged commit d9a410c into release/v1.7 Sep 3, 2024
161 checks passed
@kmrmt kmrmt deleted the backport/release/v1.7/feature/agent/ngt-property-api branch September 3, 2024 08:57
@kpango kpango mentioned this pull request Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment