-
Notifications
You must be signed in to change notification settings - Fork 33
Conjure User-Agents supports arbitrary comment data #1286
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
Conversation
This allows us to track more specific context through the platform
Generate changelog in
|
service-config/src/main/java/com/palantir/conjure/java/api/config/service/UserAgent.java
Outdated
Show resolved
Hide resolved
Some context:
A few comments:
if we go forward with key-value pairs then I'd propose we model it as a list of key-value pairs, and not as a map. I.e. don't require the keys to be unique. It's quite common for us to have the same "key" with different values in our internal requests. I don't have a strong opinion if we should make this key-value pairs or just strings though - we don't currently parse them, and is easy enough to parse
Note that for my use-case, I don't really care about the browser user-agents. In fact, they're noise. I care about which resource is being accessed, not by which client or browser (which kind of indicates we're extending the usability of
In fact, we're currently using internally
I agree. |
I tend to avoid using maps in apis, for uniqueness constraints as well -- I like the flexibility of a simple list of strings instead of dealing with key/value pair delimiters which may not be sufficient for all types of key/value pair. Let's stick with
I'm not suggesting that the additional metadata is useful for your use case, but rather than by implementing a feature that is helpful for you, we may be able to more closely align with how user-agents are constructed and used more broadly. This gives me confidence that the feature will be supportable without causing issues regardless of whether/how it's used for this particular use-case.
This is a fair caveat -- the use-case that we discussed for this metadata a few weeks ago did have better alignment, describing state/intent of a caller rather than what specifically they were attempting to access.
That's not how I interpreted the rfc, they seem entirely valid (and common) within both the agent and comment components. See examples at https://useragents.io/ |
private static final Splitter SEMICOLON_SPLITTER = | ||
Splitter.on(CharMatcher.is(';').precomputed()).trimResults().omitEmptyStrings(); |
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.
In the most recent commit, I've updated this to no longer split on commas. I haven't found examples where the comma is used as a delimiter like semicolon, but it is used within the common string KHTML, like Gecko
.
Everywhere that we encoded nodeId was a single component, and that wouldn't be impacted (though I don't think we actually use the nodeId component anywhere these days): (nodeId:value)
* for additional diagnostic information. Note that this library provides a much stricter set of allowed | ||
* characters within comments than the linked RFCs to reduce complexity. | ||
*/ | ||
List<@Safe String> comments(); |
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.
do we need to validate comments in the check()
method as well?
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 don't think so, there are two factory methods, only one takes comments, and it validates them before passing args. This way we avoid unnecessary work in the common case.
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.
sure, but the same could be said about name
and version
, no? should we just remove the check()
method? i think this is more of a question of if anyone does/will use ImmutableAgent.builder()
directly.
This way we avoid unnecessary work in the common case.
what's the "common case" here? using the factory that does not accept comments?
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 think this is more of a question of if anyone does/will use ImmutableAgent.builder() directly.
Right, ImmutableAgent
is package private, so it can't be used from outside of this module (assuming no package-clobbering hackery)
what's the "common case" here? using the factory that does not accept comments?
Correct, the existing factory method that folks already use today, which does not accept comments.
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.
avoid unnecessary work
isn't this just a conditional on comments().size()
?
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.
ImmutableAgent is package private
ah okay, i missed that
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.
Yep!
In general I'm a bit biased against immutables @Check
methods as well, since they add a public method to the interfaces API which isn't meant to be called by consumers of the interface.
Released 2.59.0 |
This allows us to track more specific context through the platform
==COMMIT_MSG==
Conjure User-Agents supports arbitrary comment data
==COMMIT_MSG==
I need to put some more thought into this. A few areas where I think we may want to do things differently:
nodeId
withcomments
, which can take multiple arbitrary values.nodeId
was set on the top-level UserAgent, not on a per-agent basis, so the new comments are set on the top-level type and encoded just after the primary agent as well. I think we should move the comments toAgent
instead, allowing each component to provide context.In general, I like that we retain more of the original info from browser user-agents, which might not be possible if we force key/value pairs. We could bias the API toward key/value pairs in a way that doesn't exclude other strings (e.g. empty value to represent a single string) but that would make parsing more complex and risk mutations when we parse->re-encode (e.g. delimiter characters in the comment key getting split, and moving into the value)