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

pubsub: gRPC Dial Option is ignored if PUBSUB_EMULATOR_HOST is set #10039

Closed
toga4 opened this issue Apr 25, 2024 · 1 comment · Fixed by #10040
Closed

pubsub: gRPC Dial Option is ignored if PUBSUB_EMULATOR_HOST is set #10039

toga4 opened this issue Apr 25, 2024 · 1 comment · Fixed by #10040
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. triage me I really want to be triaged.

Comments

@toga4
Copy link
Contributor

toga4 commented Apr 25, 2024

Client

PubSub

Environment

MacOS

Go Environment

$ go version
go version go1.22.2 darwin/arm64
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/tomoki.t/Library/Caches/go-build'
GOENV='/Users/tomoki.t/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/tomoki.t/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/tomoki.t/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/d5/bmk880x11pz8xh80bh9djr3m0000gn/T/go-build1444610399=/tmp/go-build -gno-record-gcc-switches -fno-common'

Code

e.g.

func main() {
	os.Setenv("PUBSUB_EMULATOR_HOST", "localhost:8085")
	ctx := context.Background()

	client, err := pubsub.NewClient(
		ctx,
		"foo-project",
		option.WithGRPCDialOption(
			grpc.WithChainUnaryInterceptor(func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
				fmt.Println("grpc.WithChainUnaryInterceptor")
				return invoker(ctx, method, req, reply, cc, opts...)
			}),
		),
	)
	if err != nil {
		panic(err)
	}
	defer client.Close()

	topic := client.Topic("foo-topic")
	result := topic.Publish(ctx, &pubsub.Message{
		Data: []byte("Hello, World!"),
	})

	if _, err := result.Get(ctx); err != nil {
		panic(err)
	}
}

Expected behavior

Expected to see output from the grpc.WithChainUnaryInterceptor indicating that the interceptor is being called.

Actual behavior

No output from the interceptor is observed, suggesting it's not being called.

Additional context

When PUBSUB_EMULATOR_HOST is set, a gRPC connection is generated using only grpc.WithInsecure, which results in all gRPC DialOptions being ignored.

var o []option.ClientOption
// Environment variables for gcloud emulator:
// https://cloud.google.com/sdk/gcloud/reference/beta/emulators/pubsub/
if addr := os.Getenv("PUBSUB_EMULATOR_HOST"); addr != "" {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("grpc.Dial: %w", err)
}
o = []option.ClientOption{option.WithGRPCConn(conn)}
o = append(o, option.WithTelemetryDisabled())

@toga4 toga4 added the triage me I really want to be triaged. label Apr 25, 2024
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Apr 25, 2024
@hongalex
Copy link
Member

hongalex commented May 6, 2024

Thank for you the PR and your patience while I get this merged in. Will try to get this merged in this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. triage me I really want to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants