Skip to content

Conversation

@ericgribkoff
Copy link
Contributor

Cronet allows attaching multiple annotation objects to a bidirectional stream (javadoc). This PR deprecates the CRONET_ANNOTATION_KEY, which allowed at most one annotation object, and instead adds a CronetCallOptions#withAnnotation which lets users add annotation objects to a set of annotations attached to the Cronet stream, more closely matching the semantics exposed by Cronet.

This (or some alternative) API change is helpful to accommodate existing users of CRONET_ANNOTATION_KEY alongside a mechanism for exporting gRPC-specific metrics to Cronet's RequestFinishedInfo.Listener implementations using the same annotation mechanism, which seems to require multiple annotations attached to the Cronet stream.

@ericgribkoff ericgribkoff requested a review from ejona86 November 9, 2017 00:15
*/
public static CallOptions withAnnotation(CallOptions callOptions, Object annotation) {
Set<Object> annotations = callOptions.getOption(CRONET_ANNOTATIONS_KEY);
if (annotations != null) {
Copy link
Member

Choose a reason for hiding this comment

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

if (annotations == null) {
  annotations = new HashSet<Object>();
}
annotations.add(annotation);

However, since options are mostly immutable, it may be strange this modifies the set. Notice that the withOption at the end isn't necessary if the key was already present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to Collection backed by ArrayList (also matches how Cronet handles the annotations) and recreate a new ArrayList on each call. I think this better respects the immutability of call options; is this type of change what you had in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's what I was thinking.

if (annotations != null) {
annotations.add(annotation);
} else {
annotations = new HashSet<Object>();
Copy link
Member

Choose a reason for hiding this comment

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

What happens if you don't use a set? (say, a list instead?)

}
return callOptions.withOption(CronetCallOptions.CRONET_ANNOTATIONS_KEY, annotations);
newAnnotations.add(annotation);
return callOptions.withOption(CronetCallOptions.CRONET_ANNOTATIONS_KEY, newAnnotations);
Copy link
Member

Choose a reason for hiding this comment

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

You may consider wrapping with unmodifiableList.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*/
public static CallOptions withAnnotation(CallOptions callOptions, Object annotation) {
Set<Object> annotations = callOptions.getOption(CRONET_ANNOTATIONS_KEY);
if (annotations != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's what I was thinking.

@ericgribkoff ericgribkoff merged commit 1a42a4c into grpc:master Nov 9, 2017
@ericgribkoff ericgribkoff deleted the cronet_annotations branch November 9, 2017 23:15
@carl-mastrangelo carl-mastrangelo added this to the 1.9 milestone Nov 30, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants