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

[receiver/googlecloudpubsub] allow endpoint and insecure config #10845

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🧰

Expand Down
4 changes: 4 additions & 0 deletions receiver/googlecloudpubsubreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Copy link
Contributor

Choose a reason for hiding this comment

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

never used the regional endpoints, so I tried the out of curiosity. Verified the branch locally and worked (as well with a regional endpoint)

* `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:
Expand Down
6 changes: 3 additions & 3 deletions receiver/googlecloudpubsubreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 4 additions & 4 deletions receiver/googlecloudpubsubreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions receiver/googlecloudpubsubreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down