google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

Set x-goog-api-client header for Spanner rpcs

Open vkedia opened this issue 9 years ago • 23 comments

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.

vkedia avatar Mar 09 '17 05:03 vkedia

This is done and has been released in 0.23.1.

dhermes avatar Mar 09 '17 05:03 dhermes

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 avatar May 18 '17 18:05 vkedia

@vkedia the non-admin APIs have the same configuration in database.py.

tseaver avatar May 18 '17 18:05 tseaver

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

vkedia avatar May 18 '17 18:05 vkedia

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 avatar May 18 '17 18:05 tseaver

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

vkedia avatar May 18 '17 19:05 vkedia

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')]}

tseaver avatar May 18 '17 19:05 tseaver

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.

tseaver avatar May 18 '17 19:05 tseaver

Is there a way to make gRPC dump headers it is sending out?

vkedia avatar May 18 '17 19:05 vkedia

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

vkedia avatar May 23 '17 22:05 vkedia

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.

tseaver avatar May 23 '17 23:05 tseaver

Possibly though in that case it should manifest in other libraries as well and not just spanner.

vkedia avatar May 23 '17 23:05 vkedia

@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

vkedia avatar May 24 '17 02:05 vkedia

Ping @tseaver can you review latest update from @vkedia?

danoscarmike avatar Jun 27 '17 19:06 danoscarmike

@danoscarmike AFAICT this is an issue for https://github.com/googleapis/gax-python, where I am not a maintainer.

tseaver avatar Jun 27 '17 19:06 tseaver

Thanks Tres. @lukesneeringer can you verify Tres' suspicion? If true let's link to an issue in that repo.

danoscarmike avatar Jun 28 '17 04:06 danoscarmike

@vam-google @lukesneeringer This is fixed now, correct?

bjwatson avatar Jul 25 '17 22:07 bjwatson

@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 avatar Jul 25 '17 23:07 tseaver

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

bjwatson avatar Jul 25 '17 23:07 bjwatson

Great, now we just need a released version which incorporates that fix.

tseaver avatar Jul 26 '17 00:07 tseaver