Skip to content

Commit c762ad2

Browse files
authored
Exclude Google Cloud Storage gRPC packages (#7988)
## What changed? Stripped Google Cloud Storage's gRPC dependencies out for builds via the Makefile. ## Why? Reduce binary size by 16MB; and reduces build times a little (ie linking). **Before** ``` -rwxr-xr-x@ 1 stephan staff 119M Jun 30 11:23 temporal-server ``` **After** ``` -rwxr-xr-x@ 1 stephan staff 103M Jun 30 11:24 temporal-server ``` ## How did you test it? - [x] built - [ ] run locally and tested manually - [ ] covered by existing tests - [x] added new unit test(s) - [ ] added new functional test(s) ## Potential risks Yes, since there are no end-to-end tests, if anyone started using `storage.NewGRPCClient` that would fail silently. I added a (crude) test to catch that.
1 parent 28857d2 commit c762ad2

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ PERSISTENCE_DRIVER ?= cassandra
4444
TEMPORAL_DB ?= temporal
4545
VISIBILITY_DB ?= temporal_visibility
4646

47-
ALL_BUILD_TAGS := $(BUILD_TAG),
47+
# The `disable_grpc_modules` build tag excludes gRPC dependencies from cloud.google.com/go/storage,
48+
# reducing binary size by 16MB since we only use the REST client (storage.NewClient), not the
49+
# gRPC client (storage.NewGRPCClient). Related issue: https://github.com/googleapis/google-cloud-go/issues/12343
50+
ALL_BUILD_TAGS := disable_grpc_modules,$(BUILD_TAG)
4851
ALL_TEST_TAGS := $(ALL_BUILD_TAGS),test_dep,$(TEST_TAG)
4952
BUILD_TAG_FLAG := -tags $(ALL_BUILD_TAGS)
5053
TEST_TAG_FLAG := -tags $(ALL_TEST_TAGS)

common/archiver/gcloud/connector/client_delegate.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ func newDefaultClientDelegate(ctx context.Context) (*clientDelegate, error) {
8686
}
8787

8888
func newClientDelegateWithCredentials(ctx context.Context, credentialsPath string) (*clientDelegate, error) {
89-
9089
jsonKey, err := os.ReadFile(credentialsPath)
9190
if err != nil {
9291
return newDefaultClientDelegate(ctx)

common/archiver/gcloud/connector/client_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"io"
88
"os"
9+
"path/filepath"
910
"strings"
1011
"testing"
1112

@@ -243,7 +244,6 @@ func (s *clientSuite) TestQuery() {
243244
}
244245

245246
func (s *clientSuite) TestQueryWithFilter() {
246-
247247
ctx := context.Background()
248248
mockBucketHandleClient := connector.NewMockBucketHandleWrapper(s.controller)
249249
mockStorageClient := connector.NewMockGcloudStorageClient(s.controller)
@@ -303,3 +303,32 @@ func newWorkflowIDPrecondition(workflowID string) connector.Precondition {
303303
return false
304304
}
305305
}
306+
307+
// Ensures that no code in this package or its parent folder accidentally uses gRPC functions
308+
// since they are stripped from the binary via `disable_grpc_modules`. This is crude but effective.
309+
func (s *clientSuite) TestNoGRPCUsage() {
310+
currentPackageFiles, err := filepath.Glob("*.go")
311+
s.NoError(err)
312+
parentPackageFiles, err := filepath.Glob("../*.go")
313+
s.NoError(err)
314+
allFiles := append(currentPackageFiles, parentPackageFiles...)
315+
316+
var checkedClientFile bool
317+
for _, file := range allFiles {
318+
if strings.HasSuffix(file, "_test.go") {
319+
continue
320+
}
321+
322+
content, err := os.ReadFile(file)
323+
s.NoError(err)
324+
325+
if strings.Contains(string(content), "NewGRPCClient") {
326+
s.T().Errorf("❌ Found forbidden gRPC usage in file: %s", file)
327+
}
328+
329+
// Check for client.go in both current and parent directories
330+
checkedClientFile = checkedClientFile || strings.HasSuffix(file, "client.go")
331+
}
332+
333+
s.True(checkedClientFile, "should have checked client.go for gRPC usage")
334+
}

0 commit comments

Comments
 (0)