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

Stackdriver exporter: Allow overriding client options via config #1010

Merged
merged 4 commits into from
Sep 15, 2020
Merged

Stackdriver exporter: Allow overriding client options via config #1010

merged 4 commits into from
Sep 15, 2020

Conversation

nilebox
Copy link
Member

@nilebox nilebox commented Sep 11, 2020

Description: Currently we have to use a forked Stackdriver exporter for custom authorization (#688).
Adding ability to override client options will only require to make a "wrapper" factory without having a complete fork of the code.

Link to tracking Issue: #688

Testing: Added a basic unit test overriding client options

Documentation: Given that a new config parameter is meant to be overridden programmatically by developers, there is no need for user documentation.

@nilebox nilebox requested a review from a team September 11, 2020 05:32
@nilebox
Copy link
Member Author

nilebox commented Sep 11, 2020

/cc @serathius @james-bebbington

exporter/stackdriverexporter/stackdriver.go Show resolved Hide resolved
// to the underlying Cloud Monitoring API client.
// Must be set programmatically (no support via declarative config).
// Optional.
ClientOptions []option.ClientOption
Copy link
Member

Choose a reason for hiding this comment

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

Optional: I wonder if it would be cleaner to put this into a separate struct that is passed into the NewFactory() function explicitly instead of polluting the Config struct?

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with making it part of NewFactory is that it will be "static", i.e. will apply to all instances of exporter.
One could imagine configuring exporters with different client options.

exporter/stackdriverexporter/stackdriver.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 11, 2020

Codecov Report

Merging #1010 into master will increase coverage by 13.89%.
The diff coverage is 67.85%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1010       +/-   ##
===========================================
+ Coverage   74.88%   88.77%   +13.89%     
===========================================
  Files          21      247      +226     
  Lines        1071    13274    +12203     
===========================================
+ Hits          802    11784    +10982     
- Misses        213     1135      +922     
- Partials       56      355      +299     
Flag Coverage Δ
#integration 74.88% <ø> (ø)
#unit 87.99% <67.85%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
exporter/stackdriverexporter/factory.go 75.00% <0.00%> (ø)
exporter/stackdriverexporter/stackdriver.go 71.92% <70.37%> (ø)
receiver/kubeletstatsreceiver/kubelet/resource.go 100.00% <0.00%> (ø)
exporter/newrelicexporter/config.go 100.00% <0.00%> (ø)
exporter/awsxrayexporter/xray_client.go 68.00% <0.00%> (ø)
exporter/azuremonitorexporter/factory.go 88.57% <0.00%> (ø)
receiver/receivercreator/observerhandler.go 66.12% <0.00%> (ø)
exporter/jaegerthrifthttpexporter/factory.go 100.00% <0.00%> (ø)
exporter/splunkhecexporter/metricdata_to_splunk.go 61.38% <0.00%> (ø)
exporter/sapmexporter/config.go 100.00% <0.00%> (ø)
... and 230 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b925a1...fb298f7. Read the comment docs.

// to the underlying Google Cloud API client.
// Must be set programmatically (no support via declarative config).
// Optional.
GetClientOptions func() []option.ClientOption
Copy link
Member Author

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.

@@ -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) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Consolidated all logic initializing client options in one place.

@@ -126,21 +137,12 @@ func newStackdriverMetricsExporter(cfg *Config, version string) (component.Metri
}

userAgent := strings.ReplaceAll(cfg.UserAgent, "{{version}}", version)
Copy link
Member

Choose a reason for hiding this comment

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

Bring this line into generateClientOptions as well?

Copy link
Member Author

Choose a reason for hiding this comment

The 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).

@bogdandrutu bogdandrutu merged commit 47370fa into open-telemetry:master Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants