Provide a way to configure the tracer using properties file#862
Provide a way to configure the tracer using properties file#862
Conversation
0a40d8b to
a3f8c16
Compare
There was a problem hiding this comment.
There is a comment on top of Config default constructor - you may want to update it to reflect the new reality.
There was a problem hiding this comment.
What is the point of running this synchronized ?
There was a problem hiding this comment.
My mistake, originally this method was also setting the static variable, while now it only return the result. So no point in doing it synchronized
There was a problem hiding this comment.
A comment here. I set a static variable in a constructor which is clearly a smell. The motivation behind this was testability and this is not my favorite approach.
What I would prefer to do is to change the class quite a few moving from imperative static loading of properties to a more instance centric approach, where I define inner providers [systemPropertyProvider, environmentVariableProvider, configurationFileProvider, defaultValuesProvider] instantiated in constructor which are tested in sequence until I find a non null.
But the approach above (that I would be more than happy to implement) requires quite a few changes and I will do only if we all agree.
There was a problem hiding this comment.
First of all: if you simply remove static from that field nothing changes much :).
There was a problem hiding this comment.
I think one possible approach here is to implement a separate way of loading fully fledged config file from all possible sources separately and then also implement merging config objects. There is sort of a very primitive implementation of this already in a form of second constructor for Config - but it is not flexible enough at the moment.
There was a problem hiding this comment.
I think I don't follow. Are you suggesting to make the various getSettingFromEnvironment and the likes non-static and to pass along the loaded properties? In this case I would not clearly understand why we are treating properties from properties file differently from system properties and environment variables
There was a problem hiding this comment.
Oh, right, getSettingFromEnvironment that is static... And not only that - it is also used outside of Config... in this particular case I think that initializing that in constructor is outright dangerous and confusing and I would suggest funding way of not doing that.
I think first step there might be refactoring all places that use getSettingFromEnvironment directly to use actual config instance. And then this can be made non static and proper config inheriting/overwriting scheme could be implemented.
There was a problem hiding this comment.
When I commented about updating comment I meant this one :)
2b9ab9b to
2c07912
Compare
2560e5d to
dd7a69e
Compare
dd7a69e to
12dc7c4
Compare
|
The blocking PR #863 implementing parts of what we discussed in comments is merged, time for a final review. @tylerbenson @mar-kolya |
tylerbenson
left a comment
There was a problem hiding this comment.
Just optional comments...
|
|
||
| def "verify fallback to properties file that does not exist does not crash app"() { | ||
| setup: | ||
| System.setProperty(PREFIX + CONFIGURATION_FILE, "src/test/resources/do-not-exist.properties") |
There was a problem hiding this comment.
You may want to clear this property in cleanup.
| * @return The public facing system property name | ||
| */ | ||
| private static String propertyNameToSystemPropertyName(String setting) { | ||
| return PREFIX + setting; |
There was a problem hiding this comment.
👍
Should getMapSettingFromEnvironment use this method too?
|
|
||
| // Normalizing tilde (~) paths for unix systems | ||
| configurationFilePath = | ||
| configurationFilePath.replaceFirst("^~", System.getProperty("user.home")); |
There was a problem hiding this comment.
I'm surprised... I would think java would handle this automatically.
So far we only allowed configuration of the Java tracer from system properties and environment variables. This can be a pain for users, especially because a file is easier to track and some values can be very large an not easy to handle in envs or system properties.
This PR introduces a third source of configuration, through a properties file in the format:
The path to such file is provided to the runtime as a system property
-Ddd.trace.config=/path/to/dd-java-tracer.properties.