diff --git a/CHANGELOG.md b/CHANGELOG.md index 81a5915a64db..01841c3e1294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - `elasticsearchreceiver`: Add integration test for elasticsearch receiver (#10165) - `datadogexporter`: Some config validation and unmarshaling steps are now done on `Validate` and `Unmarshal` instead of `Sanitize` (#8829) - `examples`: Add an example for scraping Couchbase metrics (#10894) +- `googlecloudpubsubreceiver`: Added new `Endpoint` and `Insecure` connection configuration options. (#10845) ### 🧰 Bug fixes 🧰 diff --git a/receiver/googlecloudpubsubreceiver/README.md b/receiver/googlecloudpubsubreceiver/README.md index d8b56913ca3b..a45527a9d0e8 100644 --- a/receiver/googlecloudpubsubreceiver/README.md +++ b/receiver/googlecloudpubsubreceiver/README.md @@ -20,6 +20,10 @@ The following configuration options are supported: a fallback, when no `content-type` attribute is present. * `compression` (Optional): The compression that will be used on received data from the subscription. When set it can only be `gzip`. This will only be used as a fallback, when no `content-encoding` attribute is present. +* `endpoint` (Optional): Override the default Pubsub Endpoint, useful when connecting to the PubSub emulator instance + or switching between [global and regional service endpoints](https://cloud.google.com/pubsub/docs/reference/service_apis_overview#service_endpoints). +* `insecure` (Optional): allows performing “insecure” SSL connections and transfers, useful when connecting to a local + emulator instance. Only has effect if Endpoint is not "" ```yaml receivers: diff --git a/receiver/googlecloudpubsubreceiver/config.go b/receiver/googlecloudpubsubreceiver/config.go index c54cff538c7e..d127352fde99 100644 --- a/receiver/googlecloudpubsubreceiver/config.go +++ b/receiver/googlecloudpubsubreceiver/config.go @@ -31,10 +31,10 @@ type Config struct { ProjectID string `mapstructure:"project"` // User agent that will be used by the Pubsub client to connect to the service UserAgent string `mapstructure:"user_agent"` - // Override of the Pubsub endpoint, for testing only - endpoint string + // Override of the Pubsub Endpoint, leave empty for the default endpoint + Endpoint string `mapstructure:"endpoint"` // Only has effect if Endpoint is not "" - insecure bool + Insecure bool `mapstructure:"insecure"` // Timeout for all API calls. If not set, defaults to 12 seconds. exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. diff --git a/receiver/googlecloudpubsubreceiver/receiver.go b/receiver/googlecloudpubsubreceiver/receiver.go index 55b24a0c20c5..43c6c94c7a72 100644 --- a/receiver/googlecloudpubsubreceiver/receiver.go +++ b/receiver/googlecloudpubsubreceiver/receiver.go @@ -80,16 +80,16 @@ func (receiver *pubsubReceiver) generateClientOptions() (copts []option.ClientOp if receiver.userAgent != "" { copts = append(copts, option.WithUserAgent(receiver.userAgent)) } - if receiver.config.endpoint != "" { - if receiver.config.insecure { + if receiver.config.Endpoint != "" { + if receiver.config.Insecure { var dialOpts []grpc.DialOption if receiver.userAgent != "" { dialOpts = append(dialOpts, grpc.WithUserAgent(receiver.userAgent)) } - conn, _ := grpc.Dial(receiver.config.endpoint, append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))...) + conn, _ := grpc.Dial(receiver.config.Endpoint, append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))...) copts = append(copts, option.WithGRPCConn(conn)) } else { - copts = append(copts, option.WithEndpoint(receiver.config.endpoint)) + copts = append(copts, option.WithEndpoint(receiver.config.Endpoint)) } } return copts diff --git a/receiver/googlecloudpubsubreceiver/receiver_test.go b/receiver/googlecloudpubsubreceiver/receiver_test.go index 832462cbd5e3..dacee6d176e3 100644 --- a/receiver/googlecloudpubsubreceiver/receiver_test.go +++ b/receiver/googlecloudpubsubreceiver/receiver_test.go @@ -45,8 +45,8 @@ func TestStartReceiverNoSubscription(t *testing.T) { userAgent: "test-user-agent", config: &Config{ - endpoint: srv.Addr, - insecure: true, + Endpoint: srv.Addr, + Insecure: true, ProjectID: "my-project", TimeoutSettings: exporterhelper.TimeoutSettings{ Timeout: 12 * time.Second, @@ -95,8 +95,8 @@ func TestReceiver(t *testing.T) { userAgent: "test-user-agent", config: &Config{ - endpoint: srv.Addr, - insecure: true, + Endpoint: srv.Addr, + Insecure: true, ProjectID: "my-project", TimeoutSettings: exporterhelper.TimeoutSettings{ Timeout: 1 * time.Second,