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

[PoC] Refactor config API #33

Closed
wants to merge 3 commits into from
Closed

[PoC] Refactor config API #33

wants to merge 3 commits into from

Conversation

pellared
Copy link
Contributor

@pellared pellared commented Apr 9, 2021

Why

#30 (comment)

What

See: 2c907eb and d8365c1
It is an attempt to make the OTel functional options API more extensible-friendly.

@pellared pellared changed the title [WIP] PoC - Refactor config API PoC - Refactor config API Apr 9, 2021
@pellared
Copy link
Contributor Author

pellared commented Apr 9, 2021

@MrAlias @owais

I tried 3 approaches to make OTel functional options API more extensible-friendly.

  1. Add WithNop functional option to make it easier to do a composition. It was done here: 2c907eb
  2. Export Config in otelhttp and at the same time unexport all its fields.
  3. Change Apply in Option from otelhttp to accept interface{} instead of *config (current PR state)

Approach 1

I do not like adding the WithNop function to the public API surface. IMO the worst approach.

Approach 2

It does not have the drawback of approach 1, however, it will result in a similar code boat to opinion 2, It requires type-assertions (but not in OTel code - just in "distro" code). When I started writing this code I ended with approach no 3.

Approach 3

I feel that this one is the cleanest. We lose some kind of type-safety as we really on type assertions, but I cannot figure out any better way that will work nicely with the functional options approach. The implementation of options in OTEL and distro is similar (orthogonal).

I was also thinking of builder pattern or simply using config structs... But after a few hours of experiments, I just feel that I am not able to come up with anything better than presented in this PR.

@@ -2,6 +2,8 @@ module github.com/signalfx/splunk-otel-go/instrumentation/net/http/splunkhttp

go 1.14

replace go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => ../otelhttp
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 have "vendored" go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp module to easily experiment and visualize the changes in OTel repo

Comment on lines +48 to +61
// Option Interface used for setting *optional* config properties
type Option interface {
Apply(interface{})
}

// OptionFunc provides a convenience wrapper for simple Options
// that can be represented as functions.
type OptionFunc func(*config)

func (o OptionFunc) Apply(obj interface{}) {
if c, ok := obj.(*config); ok {
o(c)
}
}
Copy link
Contributor Author

@pellared pellared Apr 9, 2021

Choose a reason for hiding this comment

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

@pellared pellared changed the title PoC - Refactor config API [PoC] Refactor config API Apr 9, 2021
@pellared pellared requested review from MrAlias and owais April 9, 2021 08:57
@pellared
Copy link
Contributor Author

@MrAlias @owais Can you please take a look and comment?

@MrAlias
Copy link
Contributor

MrAlias commented Apr 14, 2021

Awesome work! 😄

I like option 2 the most due to the type safety, but I'm still thinking it through. I definitely want to present this to the Go SIG on Thursday to get more feedback.

@pellared
Copy link
Contributor Author

Awesome work! 😄

I like option 2 the most due to the type safety, but I'm still thinking it through. I definitely want to present this to the Go SIG on Thursday to get more feedback.

I will try to make a draft PR for each approach + GitHub issue in opentelemetry-go-contrib to facilitate the discussion.

@pellared
Copy link
Contributor Author

pellared commented Apr 14, 2021

@pellared pellared closed this Apr 15, 2021
@pellared pellared deleted the poc-refacor-config branch April 15, 2021 15:38
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.

2 participants