gcp-metadata icon indicating copy to clipboard operation
gcp-metadata copied to clipboard

Permanent redirect to from instance to instance/

Open sk- opened this issue 5 years ago • 5 comments

In a firebase function, which is just a wrapper around a Google Cloud Function, whenever the firestore code is fetching the project details, which triggers an isAvailable call. I see that there's a permanent redirect (301) from either: http://169.254.169.254/computeMetadata/v1/instance -> http://169.254.169.254/computeMetadata/v1/instance/ http://metadata.google.internal./computeMetadata/v1/instance -> http://metadata.google.internal./computeMetadata/v1/instance/

These calls are rather slow and have high variance, taking between 20 and 200ms (I have seen times larger than a couple of seconds too).

I think that the code in the metadataAccessor (https://github.com/googleapis/gcp-metadata/blob/3f1eadacaa36f04aa1f105050031f6c158330576/src/index.ts#L67), should be changed so that when there's no property the url ends with a trailing slash, at least for the instance type.

See the traces below Screen Shot 2020-06-05 at 10 57 29 AM

Environment details

  • OS: Firebase Functions
  • Node.js version: 10.18.1
  • npm version: 6.14.4
  • gcp-metadata version: 3.5.0

Steps to reproduce

  1. Make a firestore request in a Firebase Function
  2. Check the traces of the http request

sk- avatar Jun 05 '20 14:06 sk-

Well, I tried to make this change, and the Cloud Build environment wasn't having it. These seemingly small changes have been very tricky for us in this library. Different environments can respond drastically differently to the same, trivial things. It's quite scary to touch this stuff, so thankfully, our test suite saved us this time.

@JustinBeckwith @bcoe any thoughts?

stephenplusplus avatar Jun 23 '20 21:06 stephenplusplus

He @sk- thanks for the details in the bug :) This is super helpful. I think we should explore 2 separate issues here:

  • Why in the world is the response time on the metadata server in GCF that variable. I'm calling on @grayside for an assist figuring this out.
  • Why doesn't the cloud build metadata server implementation handle the trailing /. Calling on @donmccasland for an assist with this one :)

JustinBeckwith avatar Jun 23 '20 22:06 JustinBeckwith

Could I get clarification on this initial sentence: "In a firebase function which runs in a GCE environment"

Is this running on GCE?

grayside avatar Jun 24 '20 01:06 grayside

@grayside sorry my bad, this is a Firebase Function, which is just a wrapper around Google Cloud functions. I updated the issue to reflect this.

sk- avatar Jun 24 '20 15:06 sk-

Hi, I saw similar behavior on Cloud Run managed environment.

Mistic92 avatar Aug 03 '20 19:08 Mistic92