这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(storage): introduce dp detector based on grpc metrics #11100

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

Merged
merged 20 commits into from
Nov 13, 2024
Merged

Conversation

frankyn
Copy link
Contributor

@frankyn frankyn commented Nov 7, 2024

Got a thumbs up from @zasweq from Go gRPC team.

@frankyn frankyn marked this pull request as ready for review November 7, 2024 21:35
@frankyn frankyn requested review from a team as code owners November 7, 2024 21:35
@tritone tritone changed the title feat: introduce dp detector based on grpc metrics feat(storage): introduce dp detector based on grpc metrics Nov 8, 2024
@tritone tritone added the api: storage Issues related to the Cloud Storage API. label Nov 8, 2024
Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Few comments, thanks for your work on this!

// CheckDirectConnectivitySupported checks if Direct Connectivity is available
// for a specific bucket.
//
// Implementation currently uses client-side metrics for gRPC to detect
Copy link
Contributor

Choose a reason for hiding this comment

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

Can leave out this sentence from the godoc and mention inline below, it's too technical for the public docs.

func TestIntegration_DetectDirectConnectivity(t *testing.T) {
ctx := skipHTTP("direct connectivity isn't available for json")
multiTransportTest(ctx, t, func(t *testing.T, ctx context.Context, bucket string, _ string, _ *Client) {
_, err := CheckDirectConnectivitySupported(ctx, bucket)
Copy link
Contributor

Choose a reason for hiding this comment

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

I get why we are not actually checking the result (because the test should still work off GCE) but it feels a little annoying to not be able to validate correctness at all. Any ideas on a way to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, we can do ResourceDetection and if in GCE we expect direct path for a co-located bucket. Worth trying and seeing what happens.

@@ -233,6 +239,73 @@ func NewGRPCClient(ctx context.Context, opts ...option.ClientOption) (*Client, e
return &Client{tc: tc}, nil
}

// CheckDirectConnectivitySupported checks if Direct Connectivity is available
// for a specific bucket.
Copy link
Contributor

Choose a reason for hiding this comment

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

for a specific bucket from the environment where the client is running.

@@ -233,6 +239,73 @@ func NewGRPCClient(ctx context.Context, opts ...option.ClientOption) (*Client, e
return &Client{tc: tc}, nil
}

// CheckDirectConnectivitySupported checks if Direct Connectivity is available
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd call it "gRPC direct connectivity" (mention gRPC & use lower case to match cloud docs).

// Implementation currently uses client-side metrics for gRPC to detect
// Direct Connectivity using grpc.lb.locality label.
//
// You may configure the client by passing in options from the [google.golang.org/api/option]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd specifically say to pass in any client options that you are planning on passing to [NewGRPCClient]

//
// You may configure the client by passing in options from the [google.golang.org/api/option]
// package.
func CheckDirectConnectivitySupported(ctx context.Context, bucket string, opts ...option.ClientOption) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should just make this return an error, and nil error means DP worked?

I think we should wrap and return any errors from the metrics stuff to help debug if things go wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this idea; instead of returning a boolean emit an err when DP isn't available otherwise no error means DP is available.

t.Fatalf("resource.New: %v", err)
}
if v, present := detectedAttrs.Set().Value("cloud.platform"); present && v.AsString() == "gcp_compute_engine" {
err := CheckDirectConnectivitySupported(ctx, bucket)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'd have to create the bucket in the test to make sure it is in the same region as the VM.

Does the resource detector allow parsing the region?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call addressed.

@frankyn frankyn requested a review from tritone November 11, 2024 18:29
Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Two more minor nits, otherwise LGTM. Approving now once you fix.

t.Fatalf("CheckDirectConnectivitySupported: region not detected")
}
region := v.AsString()
newBucketName := "go-integration-dc-" + region + "-" + uidSpace.New()
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the prefix arg from multiTransportTest to name the bucket and insure it gets cleaned up.

combinedOpts := append(opts, WithDisabledClientMetrics(), option.WithGRPCDialOption(opentelemetry.DialOption(opentelemetry.Options{MetricsOptions: mo})))
client, err := NewGRPCClient(ctx, combinedOpts...)
if err != nil {
return fmt.Errorf("checkDirectConnectivitySupported: %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.

These errors should reference the function being called for stack traces purposes, and use the %w verb for error wrapping (e.g. fmt.Errorf("storage.NewGRPCClient: %w", err)). Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tritone i introduced an error named ErrDirectConnectivityNotDetected in the latest commit; IIUC the client has errors to make it easier to check rather than string checking the error.

https://github.com/googleapis/google-cloud-go/pull/11100/files#diff-2a93e444b612bd9853c32889fb82c4041760536f84356bb0db04738c19b62ddeR74

WDYT?

@frankyn frankyn enabled auto-merge (squash) November 13, 2024 19:10
@frankyn frankyn merged commit 60c2323 into main Nov 13, 2024
9 checks passed
@frankyn frankyn deleted the dp-detector branch November 13, 2024 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants