Skip to content

Commit

Permalink
[exporter/googlepubsub] expose Endpoint and Insecure (#29740)
Browse files Browse the repository at this point in the history
**Description:**
expose `Endpoint` and `Insecure` in configuration

**Link to tracking Issue:**
#29304

**Testing:**
Adapted tests to use the new attributes

**Documentation:**
Added new attributes to documentation
  • Loading branch information
alexvanboxel committed Dec 14, 2023
1 parent de55fe8 commit de8ba78
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
11 changes: 11 additions & 0 deletions .chloggen/googlecloudpubsubexporter-expose-insecure.yaml
Original file line number Diff line number Diff line change
@@ -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]
5 changes: 5 additions & 0 deletions exporter/googlecloudpubsubexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions exporter/googlecloudpubsubexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 4 additions & 4 deletions exporter/googlecloudpubsubexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions exporter/googlecloudpubsubexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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])
Expand All @@ -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{
Expand All @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions exporter/googlecloudpubsubexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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)
Expand Down

0 comments on commit de8ba78

Please sign in to comment.