-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initializing new storage control client (#1865)
* adding parent struct * adding new control client * creating new storage control client on flag value true * adding unit tests * unit tests using new assertion * remove unnecerry changes * triggering e2e tests * review changes * lint fix * lint fix * lint fix * removing unnecessary changes for go.mod * review comment * review comment * rebasing * local changes * adding retry option for control client * Update go.mod * linux tests * formating in control client file * formating in control client file * adding unit test * lint fix * lint fix * linux tests * linux tests * linux tests * adding comment for clientOpts * review comment * review comment * review comment * Update storage_handle.go
- Loading branch information
Showing
9 changed files
with
192 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2024 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package storageutil | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
control "cloud.google.com/go/storage/control/apiv2" | ||
"github.com/googleapis/gax-go/v2" | ||
"github.com/googlecloudplatform/gcsfuse/v2/internal/logger" | ||
"google.golang.org/api/option" | ||
) | ||
|
||
func storageControlClientRetryOptions(clientConfig *StorageClientConfig) []gax.CallOption { | ||
return []gax.CallOption{gax.WithRetry(func() gax.Retryer { | ||
return gax.OnErrorFunc(gax.Backoff{ | ||
Max: clientConfig.MaxRetrySleep, | ||
Multiplier: clientConfig.RetryMultiplier, | ||
}, ShouldRetry) | ||
})} | ||
} | ||
|
||
func setRetryConfigForFolderAPIs(sc *control.StorageControlClient, clientConfig *StorageClientConfig) { | ||
sc.CallOptions.CreateFolder = storageControlClientRetryOptions(clientConfig) | ||
sc.CallOptions.DeleteFolder = storageControlClientRetryOptions(clientConfig) | ||
sc.CallOptions.RenameFolder = storageControlClientRetryOptions(clientConfig) | ||
sc.CallOptions.GetFolder = storageControlClientRetryOptions(clientConfig) | ||
sc.CallOptions.GetStorageLayout = storageControlClientRetryOptions(clientConfig) | ||
} | ||
|
||
func CreateGRPCControlClient(ctx context.Context, clientOpts []option.ClientOption, clientConfig *StorageClientConfig) (controlClient *control.StorageControlClient, err error) { | ||
if err := os.Setenv("GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS", "true"); err != nil { | ||
logger.Fatal("error setting direct path env var: %v", err) | ||
} | ||
|
||
controlClient, err = control.NewStorageControlClient(ctx, clientOpts...) | ||
if err != nil { | ||
return nil, fmt.Errorf("NewStorageControlClient: %w", err) | ||
} | ||
|
||
// Set retries for control client. | ||
setRetryConfigForFolderAPIs(controlClient, clientConfig) | ||
|
||
// Unset the environment variable, since it's used only while creation of grpc client. | ||
if err := os.Unsetenv("GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS"); err != nil { | ||
logger.Fatal("error while unsetting direct path env var: %v", err) | ||
} | ||
|
||
return controlClient, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package storageutil | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
"google.golang.org/api/option" | ||
) | ||
|
||
type ControlClientTest struct { | ||
suite.Suite | ||
} | ||
|
||
func TestControlClientTestSuite(t *testing.T) { | ||
suite.Run(t, new(ControlClientTest)) | ||
} | ||
|
||
func (testSuite *ControlClientTest) SetupTest() { | ||
} | ||
|
||
func (testSuite *ControlClientTest) TearDownTest() { | ||
} | ||
|
||
func (testSuite *ControlClientTest) TestStorageControlClientRetryOptions() { | ||
clientConfig := GetDefaultStorageClientConfig() | ||
|
||
gaxOpts := storageControlClientRetryOptions(&clientConfig) | ||
|
||
assert.NotNil(testSuite.T(), gaxOpts) | ||
} | ||
|
||
func (testSuite *ControlClientTest) TestStorageControlClient() { | ||
var clientOpts []option.ClientOption | ||
clientOpts = append(clientOpts, option.WithoutAuthentication()) | ||
clientConfig := GetDefaultStorageClientConfig() | ||
|
||
controlClient, err := CreateGRPCControlClient(context.Background(), clientOpts, &clientConfig) | ||
|
||
assert.Nil(testSuite.T(), err) | ||
assert.NotNil(testSuite.T(), controlClient) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters