-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Stackdriver exporter: Allow overriding client options via config #1010
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,16 +65,29 @@ func (me *metricsExporter) Shutdown(context.Context) error { | |
return nil | ||
} | ||
|
||
func generateClientOptions(cfg *Config, dialOpts ...grpc.DialOption) ([]option.ClientOption, error) { | ||
func generateClientOptions(cfg *Config, userAgent string) ([]option.ClientOption, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consolidated all logic initializing client options in one place. |
||
var copts []option.ClientOption | ||
if cfg.UseInsecure { | ||
conn, err := grpc.Dial(cfg.Endpoint, append(dialOpts, grpc.WithInsecure())...) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot configure grpc conn: %w", err) | ||
if userAgent != "" { | ||
copts = append(copts, option.WithUserAgent(userAgent)) | ||
} | ||
if cfg.Endpoint != "" { | ||
if cfg.UseInsecure { | ||
// WithGRPCConn option takes precedent over all other supplied options so need to provide user agent here as well | ||
var dialOpts []grpc.DialOption | ||
if userAgent != "" { | ||
dialOpts = append(dialOpts, grpc.WithUserAgent(userAgent)) | ||
} | ||
conn, err := grpc.Dial(cfg.Endpoint, append(dialOpts, grpc.WithInsecure())...) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot configure grpc conn: %w", err) | ||
} | ||
copts = append(copts, option.WithGRPCConn(conn)) | ||
} else { | ||
copts = append(copts, option.WithEndpoint(cfg.Endpoint)) | ||
} | ||
copts = append(copts, option.WithGRPCConn(conn)) | ||
} else { | ||
copts = append(copts, option.WithEndpoint(cfg.Endpoint)) | ||
} | ||
nilebox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if cfg.GetClientOptions != nil { | ||
copts = append(copts, cfg.GetClientOptions()...) | ||
} | ||
return copts, nil | ||
} | ||
|
@@ -84,13 +97,11 @@ func newStackdriverTraceExporter(cfg *Config) (component.TraceExporter, error) { | |
cloudtrace.WithProjectID(cfg.ProjectID), | ||
cloudtrace.WithTimeout(cfg.Timeout), | ||
} | ||
if cfg.Endpoint != "" { | ||
copts, err := generateClientOptions(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
topts = append(topts, cloudtrace.WithTraceClientOptions(copts)) | ||
copts, err := generateClientOptions(cfg, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
topts = append(topts, cloudtrace.WithTraceClientOptions(copts)) | ||
if cfg.NumOfWorkers > 0 { | ||
topts = append(topts, cloudtrace.WithMaxNumberOfWorkers(cfg.NumOfWorkers)) | ||
} | ||
|
@@ -126,21 +137,12 @@ func newStackdriverMetricsExporter(cfg *Config, version string) (component.Metri | |
} | ||
|
||
userAgent := strings.ReplaceAll(cfg.UserAgent, "{{version}}", version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bring this line into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, had to change the trace exporter constructor though (which is probably for the better). |
||
if cfg.Endpoint != "" { | ||
// WithGRPCConn option takes precedent over all other supplied options so need to provide user agent here as well | ||
dialOpts := []grpc.DialOption{} | ||
if userAgent != "" { | ||
dialOpts = append(dialOpts, grpc.WithUserAgent(userAgent)) | ||
} | ||
|
||
copts, err := generateClientOptions(cfg, dialOpts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
options.TraceClientOptions = copts | ||
options.MonitoringClientOptions = copts | ||
copts, err := generateClientOptions(cfg, userAgent) | ||
if err != nil { | ||
return nil, err | ||
} | ||
options.MonitoringClientOptions = append(options.MonitoringClientOptions, option.WithUserAgent(options.UserAgent)) | ||
options.TraceClientOptions = copts | ||
options.MonitoringClientOptions = copts | ||
|
||
if cfg.NumOfWorkers > 0 { | ||
options.NumberOfWorkers = cfg.NumOfWorkers | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to callback function to make it clear that this field can only be set programmatically.