Repository navigation
Convert malformed opaque URLs to hierarchical form - #4820
Conversation
| public static final String TELEMETRY_DEPENDENCY_COLLECTION_ENABLED = | ||
| "telemetry.dependency-collection.enabled"; | ||
| public static final String TELEMETRY_CONVERT_OPAQUE_URI_ENABLED = | ||
| "telemetry.convert-opaque-uri.enabled"; |
There was a problem hiding this comment.
I'm not sure this warrants its own feature-flag, given that we know the opaque case leads to an exception.
BTW, have you considered an alternative fix to the DependencyResolver - when it tries to turn the URI into a file it could fall back to using the path for opaque URLs?
There was a problem hiding this comment.
Agreed about the flag if the opaque case is never valid. My concern with going without a flag was that if the path was relative and everything was working fine, prepending an unneeded "/" to make URIs hierarchical might break something for the user. The anticipated usage is just selectively when there is a problem and the behavior should not roll out as a new default for users where everything is working ok right now.
In DependencyResolver I could just catch any IllegalArgumentException containing URI is not hierarchical in its message and then convert+retry the new File op again using the updated URI. If that also does not work then rethrow the original exception. Sound ok using that default behavior without a flag around it?
There was a problem hiding this comment.
Actually I think the flag should stay because if "fixing" it for everybody causes some previously ignored opaque URL to suddenly start working it could override a dep and change the behavior in some unexpected, undesired way.
There was a problem hiding this comment.
I don't think that's a valid case though - not handling opaque file URLs properly and causing an exception is a bug, it's not something that we need a flag for. If an opaque file URL can be mapped to a file by using its path then I see that as improving the resolver logic. That's why I think the fix really should be in the resolver when it tries to convert the URL to a file.
mcculls
left a comment
There was a problem hiding this comment.
Can you remove the flag and also move this fix to DependencyResolver - ie. when it tries to convert the URI to a file, handle opaque URIs by using the path. If that resolves to a file then we know that conversion is ok. (You can either check the URI is opaque upfront or use a try...catch with the path conversion as a fallback for any situation where the whole URI doesn't map to a file.)
|
I like this approach, but may be we can just get path from uri instead of manipulating with the string directly in the resolver? Also, according to rfc8089 the windows local file representation like file:c:/path/to/file is valid. So that looks like a bug in the File, which brings me to idea that we should not touch uri. |
|
if but we could do this which I agree is better than manipulating the string: but doing this without a flag means potentially changing runtime behavior of users' deployed applications. I think it's correcting the behavior but skipping opaque URIs could be relied on as a feature by someone. |
|
@am312 using Re. adding a flag - the dependency resolution feature is to provide users with more information about their deployments - it only reports dependencies that resolve to something, such as a file. If they have an opaque code-location URL that's opaque and doesn't resolve to a file then that will not be reported, so that behaviour has not changed. If they have an opaque code-source location that can be resolved to a file then previously that information was missing, by fixing this we're now providing more complete information - that's why I don't think we need a flag to revert to the previous incomplete behaviour. (Since if they're not interested in dependency information then there's already a flag to turn it off completely.) |
|
The updated version works but it's tricky to add really meaningful tests for Windows files when we don't build on Windows. |
What Does This Do
if telemetry.convert-opaque-uri.enabled is set, opaque URLs will be converted to hierarchal by prepending the missing '/'.Handle opaque URIs in telemetry.
Motivation
This work-around addresses malformed Windows URLs which can cause errors like:
datadog.telemetry.dependency.DependencyResolver - Failed to determine dependency for uri file:C:/lib.jar. java.lang.IllegalArgumentException: URI is not hierarchical