diff --git a/.chloggen/googlecloudpubsubexporter-expose-insecure.yaml b/.chloggen/googlecloudpubsubexporter-expose-insecure.yaml new file mode 100644 index 000000000000..3a6fd8fc45ea --- /dev/null +++ b/.chloggen/googlecloudpubsubexporter-expose-insecure.yaml @@ -0,0 +1,11 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: googlecloudpubsubexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Expose `Endpoint` and `Insecure` in configuration. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [29304] diff --git a/exporter/googlecloudpubsubexporter/README.md b/exporter/googlecloudpubsubexporter/README.md index 9b061451029b..83eeefa48380 100644 --- a/exporter/googlecloudpubsubexporter/README.md +++ b/exporter/googlecloudpubsubexporter/README.md @@ -28,6 +28,11 @@ The following configuration options are supported: the smallest timestamp of all the messages. * `allow_drift` (Optional): The maximum difference the `ce-time` attribute can be set from the system clock. When the drift is set to 0, the maximum drift from the clock is allowed (only applicable to `earliest`). +* `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 exporters: googlecloudpubsub: diff --git a/exporter/googlecloudpubsubexporter/config.go b/exporter/googlecloudpubsubexporter/config.go index a87ee88872cd..5bd1da1dbcfb 100644 --- a/exporter/googlecloudpubsubexporter/config.go +++ b/exporter/googlecloudpubsubexporter/config.go @@ -22,10 +22,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"` // The fully qualified resource name of the Pubsub topic Topic string `mapstructure:"topic"` diff --git a/exporter/googlecloudpubsubexporter/exporter.go b/exporter/googlecloudpubsubexporter/exporter.go index 357b915111bc..7a93980d22dc 100644 --- a/exporter/googlecloudpubsubexporter/exporter.go +++ b/exporter/googlecloudpubsubexporter/exporter.go @@ -94,16 +94,16 @@ func (ex *pubsubExporter) generateClientOptions() (copts []option.ClientOption) if ex.userAgent != "" { copts = append(copts, option.WithUserAgent(ex.userAgent)) } - if ex.config.endpoint != "" { - if ex.config.insecure { + if ex.config.Endpoint != "" { + if ex.config.Insecure { var dialOpts []grpc.DialOption if ex.userAgent != "" { dialOpts = append(dialOpts, grpc.WithUserAgent(ex.userAgent)) } - conn, _ := grpc.Dial(ex.config.endpoint, append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))...) + conn, _ := grpc.Dial(ex.config.Endpoint, append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))...) copts = append(copts, option.WithGRPCConn(conn)) } else { - copts = append(copts, option.WithEndpoint(ex.config.endpoint)) + copts = append(copts, option.WithEndpoint(ex.config.Endpoint)) } } return copts diff --git a/exporter/googlecloudpubsubexporter/exporter_test.go b/exporter/googlecloudpubsubexporter/exporter_test.go index a698f8aeb057..099af678bcfd 100644 --- a/exporter/googlecloudpubsubexporter/exporter_test.go +++ b/exporter/googlecloudpubsubexporter/exporter_test.go @@ -31,9 +31,9 @@ func TestGenerateClientOptions(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() exporterConfig := cfg.(*Config) - exporterConfig.endpoint = srv.Addr + exporterConfig.Endpoint = srv.Addr exporterConfig.UserAgent = "test-user-agent" - exporterConfig.insecure = true + exporterConfig.Insecure = true exporterConfig.ProjectID = "my-project" exporterConfig.Topic = "projects/my-project/topics/otlp" exporterConfig.TimeoutSettings = exporterhelper.TimeoutSettings{ @@ -44,7 +44,7 @@ func TestGenerateClientOptions(t *testing.T) { options := exporter.generateClientOptions() assert.Equal(t, option.WithUserAgent("test-user-agent"), options[0]) - exporter.config.insecure = false + exporter.config.Insecure = false options = exporter.generateClientOptions() assert.Equal(t, option.WithUserAgent("test-user-agent"), options[0]) assert.Equal(t, option.WithEndpoint(srv.Addr), options[1]) @@ -63,8 +63,8 @@ func TestExporterDefaultSettings(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() exporterConfig := cfg.(*Config) - exporterConfig.endpoint = srv.Addr - exporterConfig.insecure = true + exporterConfig.Endpoint = srv.Addr + exporterConfig.Insecure = true exporterConfig.ProjectID = "my-project" exporterConfig.Topic = "projects/my-project/topics/otlp" exporterConfig.TimeoutSettings = exporterhelper.TimeoutSettings{ @@ -91,9 +91,9 @@ func TestExporterCompression(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() exporterConfig := cfg.(*Config) - exporterConfig.endpoint = srv.Addr + exporterConfig.Endpoint = srv.Addr exporterConfig.UserAgent = "test-user-agent" - exporterConfig.insecure = true + exporterConfig.Insecure = true exporterConfig.ProjectID = "my-project" exporterConfig.Topic = "projects/my-project/topics/otlp" exporterConfig.TimeoutSettings = exporterhelper.TimeoutSettings{ diff --git a/exporter/googlecloudpubsubexporter/factory_test.go b/exporter/googlecloudpubsubexporter/factory_test.go index a5c4cdeda2ab..fffea47b722d 100644 --- a/exporter/googlecloudpubsubexporter/factory_test.go +++ b/exporter/googlecloudpubsubexporter/factory_test.go @@ -31,7 +31,7 @@ func TestCreateTracesExporter(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() eCfg := cfg.(*Config) - eCfg.endpoint = "http://testing.invalid" + eCfg.Endpoint = "http://testing.invalid" te, err := factory.CreateTracesExporter( context.Background(), @@ -46,7 +46,7 @@ func TestCreateMetricsExporter(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() eCfg := cfg.(*Config) - eCfg.endpoint = "http://testing.invalid" + eCfg.Endpoint = "http://testing.invalid" me, err := factory.CreateMetricsExporter( context.Background(), @@ -61,7 +61,7 @@ func TestLogsCreateExporter(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() eCfg := cfg.(*Config) - eCfg.endpoint = "http://testing.invalid" + eCfg.Endpoint = "http://testing.invalid" me, err := factory.CreateLogsExporter( context.Background(), @@ -76,7 +76,7 @@ func TestEnsureExporter(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() eCfg := cfg.(*Config) - eCfg.endpoint = "http://testing.invalid" + eCfg.Endpoint = "http://testing.invalid" exporter1 := ensureExporter(exportertest.NewNopCreateSettings(), eCfg) exporter2 := ensureExporter(exportertest.NewNopCreateSettings(), eCfg)