-
Notifications
You must be signed in to change notification settings - Fork 791
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
Refactoring Config into @AutoValue POJO #1254
Refactoring Config into @AutoValue POJO #1254
Conversation
e6abaad
to
f01759c
Compare
f01759c
to
b010c16
Compare
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.
Hey @mateuszrzeszutek!
Reviewing this gave me a further idea.
I was going to suggest not exposing the Config.getProperty
method publicly (since it's not used outside of Config
currently).
But it seems like there's a pretty good use case for custom instrumentation needing to call Config.getProperty
.
And then I realized why shouldn't "bundled" instrumentation do the same?
(talking to myself) And anyways why should instrumentation-api
know about instrumentation-specific configuration properties?
If this makes sense to you and @iNikem, I'll open an issue for it.
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
Outdated
Show resolved
Hide resolved
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
Show resolved
Hide resolved
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
Show resolved
Hide resolved
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ConfigBuilder.java
Show resolved
Hide resolved
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
Outdated
Show resolved
Hide resolved
Assorted thoughts follow. If I create new instrumentation which needs a configuration option, should I go and change common The only downside of the above: we still have to keep the common configuration page or to create "documentation per instrumentation". The latter may be a good idea, albeit work intensive. We should re-use and not duplicate normalization logic from The precedence of configuration, system properties -> env -> file -> SPI -> default, should ideally be in one place. So, if I understand it correctly, some class from It seems I agree with @trask :) |
Do you suggest removing all those fields and just using |
There already are some properties like that: |
I suggest removing both the fields and the getters for instrumentation-specific config properties and also for config properties that are specific to
👍 (and same for |
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.
Thanks a lot, just small comments. Great cleanup
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/TracerInstaller.java
Outdated
Show resolved
Hide resolved
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ConfigBuilder.java
Outdated
Show resolved
Hide resolved
traceExecutors = getListSettingFromEnvironment(TRACE_EXECUTORS, DEFAULT_TRACE_EXECUTORS); | ||
// INSTANCE can never be null - muzzle instantiates instrumenters when it generates | ||
// getInstrumentationMuzzle() and the Instrumenter.Default constructor uses Config | ||
private static volatile Config INSTANCE = DEFAULT; |
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.
Config
becoming volatile
is a surprisingly big change. It's going to make unit tests much easier where we currently use bytecode manipulation to turn Config
from final to non-final so I'm generally happy about it though :)
We should confirm that we only call Config.get
on cold paths, which I think should generally be the case as it's basically only to initialize instrumentation. In Java, the performance of Config.get().isFooEnabled()
is actually significantly different when Java can know a boolean is a constant and C1 compiler can just remove the branches with no de-opt mechanism at all. So when .get
is volatile, we'd expect a private static final boolean IS_FOO_ENABLED = Config.get().isFooEnabled()
to replace such code inline on a hot path where we would like fast enabling/disabling of code paths
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.
That's a good point -- I'll look through usages of Config#get()
kafkaClientPropagationEnabled = | ||
getPropertyBooleanValue( | ||
properties, KAFKA_CLIENT_PROPAGATION_ENABLED, parent.kafkaClientPropagationEnabled); | ||
public static Config get() { |
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.
Might add a recommendation to store config values as constants if they're referenced in performance-sensitive code.
Great -- I'll create a separate GH issue for that. I can implement all those fixes right away, I just want to stop this PR from growing in scope (and get it merged, of course). |
92cd329
to
cc1d6f8
Compare
…config-refactoring
hey @mateuszrzeszutek, heads up, I merged master into your branch, but build not passing due to #1280, once that is merged you can merge master again and should be good to go 👍 |
…config-refactoring
Thanks @mateuszrzeszutek! |
* the agent classloader just before the first instrumentation is loaded (and before {@link | ||
* Config#get()} is used for the first time). | ||
*/ | ||
public static void internalInitializeConfig(Config config) { |
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.
I usually prefer method names like doSomethingInternal
vs internalDoSomething
. What do others think?
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.
I have slight preference for internalDoSomething
- gets the point across that it's internal sooner. Another option could be to make the access package-private
and move the method to an InternalConfigAccess
type of class.
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.
interesting, I've typically done doSomethingInternal
, because it is often a delegate of doSomething
, but I like the reasoning of putting internal in front to "get the point across that it's internal sooner"
Refactored
Config
according to this comment: #1243 (review)