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

[exporter/googlepubsub] expose Endpoint and Insecure #29740

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
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 ""
Comment on lines +31 to +34
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this README could be improved by listing the default values of all the configuration options. It does not need to be done in this PR but please consider creating a follow up issue to track this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to do this for both my receiver/exporter at the same time. I have a lot of changes lined up and want to do them in small increments.


```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