Skip to content

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

Merged
merged 7 commits into from
Oct 11, 2018

Conversation

zhangkun83
Copy link
Contributor

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.

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.
Copy link
Member

@ejona86 ejona86 left a 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 {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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."

Copy link
Contributor Author

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.

@zhangkun83 zhangkun83 changed the title core: add CallCredentials2 and deprecate CallCredentials. core: add CallCredentials2 and deprecate CallCredentials' old interface Oct 3, 2018
@igorbernstein2
Copy link
Contributor

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?

@carl-mastrangelo
Copy link
Contributor

@igorbernstein2 The io.grpc.Context is available at the time, so you can get it from there.

@igorbernstein2
Copy link
Contributor

@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

@carl-mastrangelo
Copy link
Contributor

@igorbernstein2 You can access it inside of your CallCredentials:

class MyCallCredentials extends CallCredentials {
  void applyRequestMetadata(/*...*/) {
    deadline = Context.current().getDeadline();
    // use deadline
  }
}

@igorbernstein2
Copy link
Contributor

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.

@igorbernstein2
Copy link
Contributor

Actually never mind, I’m getting confused with gax. Sorry for the noise

@carl-mastrangelo
Copy link
Contributor

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.

@igorbernstein2
Copy link
Contributor

I took a closer look and it seems like Context.current().getDeadline() might not be enough. A deadline might be set via CallOptions.withDeadline which will not be stamped on the current Context and not be accessible by the CallCredentials

@zhangkun83
Copy link
Contributor Author

I can easily add CallOptions to the RequestInfo

@igorbernstein2
Copy link
Contributor

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

@zhangkun83
Copy link
Contributor Author

@igorbernstein2, can you file an issue for accessing deadline from CallCredentials?
It's not as trivial as I thought initially. Let's discuss it on its own issue.

@igorbernstein2
Copy link
Contributor

done: #4929

@carl-mastrangelo
Copy link
Contributor

carl-mastrangelo commented Oct 9, 2018

@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?

@zhangkun83
Copy link
Contributor Author

@carl-mastrangelo, let's discuss this in #4929

Copy link
Member

@ejona86 ejona86 left a 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 {
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

static?

Copy link
Contributor Author

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).

@zhangkun83 zhangkun83 merged commit 861f914 into grpc:master Oct 11, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants