-
Notifications
You must be signed in to change notification settings - Fork 3.9k
core: add CallCredentials2 and deprecate CallCredentials' old interface #4902
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 is the first step of smoothly changing the CallCredentials API. Security level and authority are parameters required to be passed to applyRequestMetadata(). This change wraps them, along with MethodDescriptor and the transport attributes to RequestInfo, which is more clear to the implementers. ATTR_SECURITY_LEVEL is moved to the internal GrpcAttributes and annotated as TransportAttr, because transports are required to set it, but no user is actually reading them from {Client,Server}Call.getAttributes(). ATTR_AUTHORITY is removed, because no transport is overriding it. All involved interfaces are changed to abstract classes, as this will make further API changes smoother. The CallCredentials name is stabilized, thus we first introduce CallCredentials2, ask CallCredentials implementations to migrate to it, while GRPC accepting both at the same time, then replace CallCredentials with CallCredentials2.
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 can't look at this in full at the moment, but the CallCredentials{,2} looks about right.
* <p>THIS CLASS IS MEANT TO BE REFERENCED BY IMPLEMENTIONS ONLY. All users should reference {@link | ||
* CallCredentials}. | ||
*/ | ||
public abstract class CallCredentials2 implements CallCredentials { |
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.
This entire class should be marked experimental. It should deserve a note that it is part of a migration and is necessary to be used in the short-term but will be removed.
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 wanted to use the deprecation warnings on the old interface to push implementations to switch to the new interface. If we deprecate it now, implementations would have to suppress the deprecation warnings and may accidentally mask off implementations that have not been migrated, and would also cause confusion when we want implementations to switch from CallCredentials2
back to CallCredentials
. I think it's better to deprecate it after we replace CallCredentials
with the new interface.
I have added the note, and an @Internal
annotation to dissuade usage.
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 wasn't suggesting marking it deprecated, just experimental. I guess internal works as well, although it seems experimental is more appropriate since we do expect some "normal" users to use it. I'd normally prefer to keep internal a "if you are using this, you are probably doing it wrong."
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.
Sorry, read too fast :). Switched to experimental.
I'm not sure if this is the right place to ask. But since you are creating a new interface for CallCredentials, would it be possible to make provisions to allow Credentials to take & respect the call deadlines? |
@igorbernstein2 The io.grpc.Context is available at the time, so you can get it from there. |
@carl-mastrangelo I apologize for being dense, but can you clarify what you mean by “the grpc Context is available”? If I’m not mistaken, the deadline needs to be available inside applyRequestMetadata so that it can be passed to the credentials. Thanks |
@igorbernstein2 You can access it inside of your CallCredentials: class MyCallCredentials extends CallCredentials {
void applyRequestMetadata(/*...*/) {
deadline = Context.current().getDeadline();
// use deadline
}
} |
Ah, I see, via a threadlocal. Would it not be cleaner to make it part of the api? All of the grpc seems to pass it around as parameter, it feels odd that CallCredentials have to rely on a threadlocal. |
Actually never mind, I’m getting confused with gax. Sorry for the noise |
Technically Context does not have to be backed by a thread local. I have met users who use different backing storage. It is implemented by default as a thread local because that was the paradigm internally at Google. Legacy code has a strong influence, unfortunately. |
I took a closer look and it seems like |
I can easily add |
Should CallCredentials subclasses be responsible for figuring out the effective deadline between grpc.Context and CallOptions? I don't have a good answer, I was just requesting for this be a consideration in the api change |
@igorbernstein2, can you file an issue for accessing deadline from CallCredentials? |
done: #4929 |
@zhangkun83 I don't feel comfortable expecting CallCredentials implementations having to recalculate the deadline as done in ClientCallImpl. Can the effective deadline be passed in instead? Also, that's kind of weird. The CallOptions contains the credentials, but now the credentials will be passed the call options? |
@carl-mastrangelo, let's discuss this in #4929 |
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.
One comment, but otherwise LGTM
* The request-related information passed to {@link #applyRequestMetadata}. | ||
*/ | ||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1914") | ||
public abstract static class RequestInfo { |
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.
Should this be in CallCredentials? I'm thinking that moving the class to CallCredentials later may not be ABI-safe.
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.
Makes sense. Moved to CallCredentials.
@@ -92,16 +100,16 @@ void applyRequestMetadata( | |||
* <p>Exactly one of its methods must be called to make the RPC proceed. | |||
*/ | |||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1914") | |||
public interface MetadataApplier { | |||
public abstract class MetadataApplier { |
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.
static?
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.
An class under an interface is implicitly static. But it's no harm to add it (and it will be needed once CallCredentials becomes an abstract class).
This is the first step of introducing the 2nd edition of CallCredentials API (#4901)
Security level and authority are parameters required to be passed to
applyRequestMetadata(). This change wraps them, along with
MethodDescriptor and the transport attributes to RequestInfo, which is
more clear to the implementers.
ATTR_SECURITY_LEVEL is moved to the internal GrpcAttributes and
annotated as TransportAttr, because transports are required to set it,
but no user is actually reading them from
{Client,Server}Call.getAttributes().
ATTR_AUTHORITY is removed, because no transport is overriding it.
All involved interfaces are changed to abstract classes, as this will
make further API changes smoother.