Skip to content

Provide a way to configure the tracer using properties file#862

Merged
labbati merged 11 commits intomasterfrom
labbati/config-file
Jun 17, 2019
Merged

Provide a way to configure the tracer using properties file#862
labbati merged 11 commits intomasterfrom
labbati/config-file

Conversation

@labbati
Copy link
Member

@labbati labbati commented Jun 3, 2019

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:

dd.service.name=my_service
dd.something.else=value

The path to such file is provided to the runtime as a system property -Ddd.trace.config=/path/to/dd-java-tracer.properties.

@labbati labbati force-pushed the labbati/config-file branch 2 times, most recently from 0a40d8b to a3f8c16 Compare June 3, 2019 12:26
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a comment on top of Config default constructor - you may want to update it to reflect the new reality.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of running this synchronized ?

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Member Author

@labbati labbati Jun 3, 2019

Choose a reason for hiding this comment

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

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.

@mar-kolya , @tylerbenson

Copy link
Contributor

Choose a reason for hiding this comment

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

First of all: if you simply remove static from that field nothing changes much :).

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

When I commented about updating comment I meant this one :)

Copy link
Member Author

Choose a reason for hiding this comment

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

opps :)

@labbati labbati marked this pull request as ready for review June 3, 2019 13:42
@labbati labbati requested a review from a team as a code owner June 3, 2019 13:42
@labbati labbati changed the title Labbati/config file Provide a way to configure the tracer using a properties file Jun 4, 2019
@labbati labbati added tag: do not merge Do not merge changes comp: core Tracer core labels Jun 4, 2019
@labbati labbati added this to the 0.30.0 milestone Jun 4, 2019
@labbati labbati self-assigned this Jun 4, 2019
@labbati labbati changed the title Provide a way to configure the tracer using a properties file Provide a way to configure the tracer using properties file Jun 5, 2019
@labbati labbati force-pushed the labbati/config-file branch 2 times, most recently from 2b9ab9b to 2c07912 Compare June 5, 2019 16:54
@labbati labbati changed the base branch from master to labbati/non-static-config June 6, 2019 15:54
@labbati labbati force-pushed the labbati/config-file branch from 2560e5d to dd7a69e Compare June 6, 2019 16:20
@labbati labbati force-pushed the labbati/config-file branch from dd7a69e to 12dc7c4 Compare June 13, 2019 12:35
@labbati labbati changed the base branch from labbati/non-static-config to master June 13, 2019 16:06
@labbati labbati removed the tag: do not merge Do not merge changes label Jun 13, 2019
@labbati
Copy link
Member Author

labbati commented Jun 13, 2019

The blocking PR #863 implementing parts of what we discussed in comments is merged, time for a final review. @tylerbenson @mar-kolya

Copy link
Contributor

@tylerbenson tylerbenson left a comment

Choose a reason for hiding this comment

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

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍
Should getMapSettingFromEnvironment use this method too?


// Normalizing tilde (~) paths for unix systems
configurationFilePath =
configurationFilePath.replaceFirst("^~", System.getProperty("user.home"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised... I would think java would handle this automatically.

@labbati labbati merged commit 72cad28 into master Jun 17, 2019
@tylerbenson tylerbenson deleted the labbati/config-file branch June 17, 2019 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants