google-cloud-cpp
google-cloud-cpp copied to clipboard
add pubsub support for per-operation options
Add an Options options = {}
argument to the constructor of the client class(es). Merge these options with the default options for the service, and store them as a member of the client class.
Add an Options options = {}
argument to each operation within each client. These options should then be merged with the client options from above, and installed as the prevailing options for the duration of the operation by instantiating an internal::OptionsSpan
.
You could then use internal::CurrentOptions()
to obtain (a const&
to) the prevailing options from anywhere you might need them. Any cleanup for call paths where Options
have been passed explicitly is discretionary.
Similar support for the generated client classes was added in #7683, so you might be able to use that as an example.
I need this to fix the x-goog-user-project anyway.
What is supposed to happen to the options used to initialize a Connection
?
What is supposed to happen to the options used to initialize a Connection?
At least they should be returned by the Options()
accessor. After that, I'd say it is up to the service.
In the generated ConnectionImpl
s they are only used to get policies when CurrentOptions()
doesn't have them (but that is only an allowance for testing here: https://github.com/googleapis/google-cloud-cpp/blob/2a40c30e50b30d0f61f41882681ccb60161c7d58/generator/internal/connection_impl_generator.cc#L112-L116).
In the Spanner ConnectionImpl
though, they are used to check if rpc-streams
tracing is enabled, and to create the SessionPool
.
I have not been following the ins and outs of this feature as I should. This bug is asking me to:
Save all the options, with their defaults, at the Client
level, and then set these options (and maybe the per-call options) using an internal::OptionsSpan
. That means the options set at the connection level never have an effect. I recall that we changed our minds about how options-per-call are implemented, did you update this bug to reflect the latest approach?
In Pub/Sub some of the options are only used while constructing the *Connection
+ *Stub
stack, it is impossible to override them for each RPC. For example, consider this:
https://github.com/googleapis/google-cloud-cpp/blob/207a602a02c5d5bd44546650f84912c1c6a396da/google/cloud/pubsub/publisher_connection.cc#L141-L148
or this:
https://github.com/googleapis/google-cloud-cpp/blob/207a602a02c5d5bd44546650f84912c1c6a396da/google/cloud/pubsub/publisher_connection.cc#L89-L100
I suppose we would need to document which options can have an effect on a per-call basis?
I have not been following the ins and outs of this feature as I should. This bug is asking me to:
Save all the options, with their defaults, at the
Client
level, and then set these options (and maybe the per-call options) using aninternal::OptionsSpan
. That means the options set at the connection level never have an effect. I recall that we changed our minds about how options-per-call are implemented, did you update this bug to reflect the latest approach?
Yes, we did modify the procedure, and no, I did not update this bug [ENOMEM].
At the Client
level we should now merge the defaulted Connection
options into the argument options. That is, something along the lines of:
ServiceClient::ServiceClient(std::shared_ptr<ServiceConnection> connection, Options opts = {})
: connection_(std::move(connection)),
options_(internal::MergeOptions(std::move(opts),
service_internal::DefaultOptions(connection_->options()))) {
...
}
In Pub/Sub some of the options are only used while constructing the
*Connection
+*Stub
stack, it is impossible to override them for each RPC.
Yes. That's the same for all services I reckon. In the Spanner example from above, the SessionPool
options would fall into that category.
I suppose we would need to document which options can have an effect on a per-call basis?
Yes, I suppose so. I hope that it would be clear where particular options are applied, and hence when overriding values has an effect, but that may be assuming too much implementation knowledge from a user.
Addendum: Please also ensure that the OptionsSpan
instantiated during ServiceClient::Operation()
is saved and then restored over any work done on behalf of the operation but after Operation()
returns. Typically this means for async, paginated, or streaming RPCs. (These cases may already be handled via changes in the common library.)
I am still unsure what to do about pubsub::Publisher
and specially about pubsub::Subscriber
. I do not think I will be making progress for the next few weeks.
After thinking some more about, and looking at the code, I don't think it makes sense to implement this feature for pubsub::Publisher
. The issue is that most interesting options affect the stack of decorators in the pubsub::PublisherConnnection
, they cannot be changed "per call". And the batching properties / ordering properties affect previous messages.
I am closing this.