Set x-goog-api-client header for Spanner rpcs
I believe this has been done so far for Bigtable and Datastore. We should do the same for spanner as well since we use it for internal metrics.
This is done and has been released in 0.23.1.
The code you pointed to is for the admin APIs. Is this also being done for the data API? Our backend logs do not show any requests where x-goog-api-client contains "python" string (or similar) in it. At the very least we should be seeing some requests from the integration tests?
@vkedia the non-admin APIs have the same configuration in database.py.
@tseaver What would be the exact value of "x-goog-api-client"? I wonder why are we not seeing anything in our logs in that case. Maybe I am looking for the wrong string.
The header is generated by google.gax.api_callable. I'm not sure of the format, but it should start with gl-python and the Python version; it should inclue gccl and the version of google-cloud-spanner, and tokens for the gax and gapic versions.
@lukesneeringer could probably point you to the spec for the header contents.
@tseaver @lukesneeringer There must be some bug somewhere because I am not finding any requests where the x-goog-api-client looks like that. I did find requests where the UserAgent was "grpc-python/1.3.3 grpc-c/3.0.0 (manylinux; chttp2; gentle),gzip(gfe)". I am guessing these requests came from python library? x-goog-api-client was empty on these. Is it possible to dump the headers of outgoing requests on the client side and confirm that the header is being set?
Here is what the kwargs['metadata'] looks like in the run up to the call:
(Pdb) pp kwargs
{u'metadata': [(u'x-goog-api-client',
'gl-python/2.7.12 gccl/0.24.1 gapic/0.15.3 gax/0.15.13 grpc/1.3.3')]}
The code which actually generates the gRPC header from that metadata is buried too deep inside the gRPC stack for me to find.
I would say the bug is not in this library, unless it turns out that every place where we set up the call optoins metadata is borked the same way.
Is there a way to make gRPC dump headers it is sending out?
You can turn on GRPC tracing to look at the actual headers being sent. I did that and I con confirm that x-goog-api-client header is not being set atleast for the data api. Here is a handy command:
GRPC_TRACE=http GRPC_VERBOSITY=DEBUG python quickstart.py 2>&1 | grep SEND_INITIAL_METADATA | egrep '(user-agent|x-goog-api-client)'
I think this has to be an issue in https://github.com/googleapis/gax-python, rather than here: that library is responsible for generating that header.
Possibly though in that case it should manifest in other libraries as well and not just spanner.
@lukesneeringer I think I found the issue. The issue is really in gax that it does not merge the metadata given while creating the callable correctly with extra metadata given while making the call. In that case it will just use the metadata given later. You pass the "google-cloud-resource-prefix" header here: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/391c6fd807f5f4c0ea7066ec086cfa67b47a637e/spanner/google/cloud/spanner/_helpers.py#L271
This ends up overwriting the metadata which contained "x-goog-api-client" header since gax just calls update on the dictionary kwargs which overwrites existing keys: https://github.com/googleapis/gax-python/blob/master/google/gax/init.py#L159
Ping @tseaver can you review latest update from @vkedia?
@danoscarmike AFAICT this is an issue for https://github.com/googleapis/gax-python, where I am not a maintainer.
Thanks Tres. @lukesneeringer can you verify Tres' suspicion? If true let's link to an issue in that repo.
@vam-google @lukesneeringer This is fixed now, correct?
@bjwatson I don't see anything in the gax-python repository which would have fixed the issue, which is why I opened https://github.com/googleapis/gax-python/issues/198
@tseaver This was fixed by @vam-google in https://github.com/googleapis/gax-python/pull/193. He might have independently discovered the same underlying bug.
Great, now we just need a released version which incorporates that fix.