Migrate Config system to environment component#9191
Conversation
78ad76f to
9d287cb
Compare
b6c331b to
2512a49
Compare
9d287cb to
d374062
Compare
2512a49 to
fe762c4
Compare
3cca925 to
8647cfd
Compare
fe762c4 to
41de4a2
Compare
8647cfd to
e085472
Compare
41de4a2 to
42d109e
Compare
There was a problem hiding this comment.
Just a minor question: why getOrDefault ? is it possible not to have user.home?
There was a problem hiding this comment.
If the security manager prevents access to this property, SystemProperties.get() will return null.
So using getOrDefault(key, '') should avoid NPE or "null" in path.
There was a problem hiding this comment.
Got it. But just curious, how previous code worked?
And would it make sense to build a path that will be not correct?
I have a feeling that we need method in SystemProperties class that will throw IllegalStateException in case when we must have a value.
Here instead of NPE we will introduce logic error.
There was a problem hiding this comment.
Got it. But just curious, how previous code worked?
I think the whole OTel config source init fails, then config init fails.
And would it make sense to build a path that will be not correct?
That would be a question for @mcculls 😉
I have a feeling that we need method in SystemProperties class that will throw IllegalStateException in case when we must have a value.
We can still check if a value is missing using null check and no default value. The question stays: how should we deal with this case then if we don't want to have a logic error?
There was a problem hiding this comment.
I finally went with a safer approach: only do the ~ substitution if env.home property is set and retrieved.
I applied the same logic to the ConfigProvider (around line 475)
There was a problem hiding this comment.
The OTel code doesn't handle this condition: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ConfigurationFile.java#L57 - so we can choose.
TBH I doubt that anyone except maybe developers uses the ~ prefix for OTel configuration files, instead preferring the more stable absolute path. This scenario is specific to someone who wants to use an external config file, declares the path to that file using ~, and has a security manager installed that disallows system property access.
This is so unlikely I think using "" is ok as a fallback - but TBH I would also be fine with letting it throw an exception, because this falls into the category of an exceptional situation where it might be safer to not try to second guess...
There was a problem hiding this comment.
Got it. But just curious, how previous code worked?
I doubt the tracer would have got this far - if such a strict security manager was installed and the tracer hadn't been granted this permission, then it would have bailed out earlier.
There was a problem hiding this comment.
Should I revert to an IllegalStateException then?
There was a problem hiding this comment.
I'm fine with your current approach of just not doing the substitution
There was a problem hiding this comment.
Got it. But just curious, how previous code worked?
And would it make sense to build a path that will be not correct?
I have a feeling that we need method in SystemProperties class that will throw IllegalStateException in case when we must have a value.
Here instead of NPE we will introduce logic error.
42d109e to
68fc6ca
Compare
e7cb973 to
a3d54e9
Compare
a3d54e9 to
9ae7f6a
Compare
9ae7f6a to
d61ab39
Compare
d61ab39 to
d83f869
Compare
mhlidd
left a comment
There was a problem hiding this comment.
LGTM 🚀 ! I'm wondering if it's worthwhile to have a followup PR add a ForbiddenAPIs rule to prevent the usages of System.setProperty() and System.clearProperty() to encourage the usage of the Environment component. This is something I'm already doing for System.getenv() for Config Inversion :).
|
Yes, this is something we should be doing. |
mcculls
left a comment
There was a problem hiding this comment.
+1 ... just a query about the behaviour change in addByteBuddyRawSetting
d83f869 to
476cb5f
Compare

What Does This Do
This PR migrates the config system to the environment component.
It additionally improves the environment component with:
SystemProperties.clear()nullhandling onSystemPropertiesfor thesetandclearmethods.Motivation
Safely interact with the env var and system properties by handling security manager exception and possible NPE.
Additional Notes
Environment component related stacked PRs:
Contributor Checklist
type:and (comp:orinst:) labels in addition to any usefull labelsclose,fixor any linking keywords when referencing an issue.Use
solvesinstead, and assign the PR milestone to the issueJira ticket: LANGPLAT-458