Skip to content
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

Flag to point to alternative baseUrl when running locally with Functions Framework #493

Closed
quantuminformation opened this issue Sep 11, 2019 · 15 comments
Assignees
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. type: question Request for information or clarification. Not an issue.

Comments

@quantuminformation
Copy link

Reposted from GoogleCloudPlatform/functions-framework-nodejs#87

I import the following in my cloud functions and am trying to run it all locally with the functions framework

ds: require('@google-cloud/datastore')(),

By default ds.baseUrl_ is "datastore.googleapis.com", but when running gcloud beta emulators datastore the local store is at http://localhost:8766/

my scripts which fire up both emulation:

  "emulate:datastore": "gcloud beta emulators datastore start --project realworldgcp",
    "emulate:functions": " forever -c 'node --inspect' node_modules/@google-cloud/functions-framework --target=api ",

How do I update this baseUrl_ when running with FF?

Screenshot 2019-09-11 at 08 05 26

@callmehiphop callmehiphop added the type: question Request for information or clarification. Not an issue. label Sep 11, 2019
@callmehiphop
Copy link
Contributor

👋 @quantuminformation I'm not too familiar with FF but for emulator usage we usually suggest setting either the DATASTORE_EMULATOR_HOST env var or the apiEndpoint option. Have you tried either of these methods?

@quantuminformation
Copy link
Author

This is my output of the emulator, does it look correct?

➜ gcp-datastore-cloud-functions-realworld-example-app git:(master) ✗ gcloud beta emulators datastore env-init
export DATASTORE_DATASET=realworldgcp
export DATASTORE_EMULATOR_HOST=::1:8766
export DATASTORE_EMULATOR_HOST_PATH=::1:8766/datastore
export DATASTORE_HOST=http://::1:8766
export DATASTORE_PROJECT_ID=realworldgcp

@callmehiphop
Copy link
Contributor

I think so, I'm pretty sure the only env var the client respects is DATASTORE_EMULATOR_HOST however.

@quantuminformation
Copy link
Author

Perfect looks like it worked, will make a youtube video to help others soon

"emulate:functions": " export DATASTORE_EMULATOR_HOST=http://localhost:8081 && forever -c 'node --inspect' node_modules/@google-cloud/functions-framework --target=api ",

@stephenplusplus
Copy link
Contributor

I think we might have an actual issue here when the "DATASTORE_EMULATOR_HOST" variable is in this format: "::1:8766". Our code was expecting something more like "http://localhost:8081". @quantuminformation, did something get removed somehow from the original "DATASTORE_EMULATOR_HOST" value you shared, or is it really "::1:8766"?

@quantuminformation
Copy link
Author

Yeah thats a bug, I saw when updating the cli today

@quantuminformation
Copy link
Author

quantuminformation commented Sep 11, 2019

Your current Cloud SDK version is: 259.0.0
You will be upgraded to version: 262.0.0

┌────────────────────────────────────────────────────┐
│ These components will be updated. │
├────────────────────────────┬────────────┬──────────┤
│ Name │ Version │ Size │
├────────────────────────────┼────────────┼──────────┤
│ BigQuery Command Line Tool │ 2.0.47 │ < 1 MiB │
│ Cloud SDK Core Libraries │ 2019.09.06 │ 11.7 MiB │
└────────────────────────────┴────────────┴──────────┘

before it was:

➜  gcp-datastore-cloud-functions-realworld-example-app git:(master) ✗ npm run emulate:datastore

> @ emulate:datastore /Users/nikos/WebstormProjects/gcp-datastore-cloud-functions-realworld-example-app
> gcloud beta emulators datastore start --project realworldgcp

WARNING: Reusing existing data in [/Users/nikos/.config/gcloud/emulators/datastore].
Executing: /Users/nikos/Downloads/google-cloud-sdk/platform/cloud-datastore-emulator/cloud_datastore_emulator start --host=localhost --port=8081 --store_on_disk=True --consistency=0.9 --allow_remote_shutdown /Users/nikos/.config/gcloud/emulators/datastore
[datastore] Sep 11, 2019 11:10:45 AM com.google.cloud.datastore.emulator.CloudDatastore$FakeDatastoreAction$9 apply
[datastore] INFO: Provided --allow_remote_shutdown to start command which is no longer necessary.
[datastore] Sep 11, 2019 11:10:46 AM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub <init>
[datastore] INFO: Local Datastore initialized:
[datastore] 	Type: High Replication
[datastore] 	Storage: /Users/nikos/.config/gcloud/emulators/datastore/WEB-INF/appengine-generated/local_db.bin
[datastore] Sep 11, 2019 11:10:47 AM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub load
[datastore] INFO: The backing store, /Users/nikos/.config/gcloud/emulators/datastore/WEB-INF/appengine-generated/local_db.bin, does not exist. It will be created.
[datastore] API endpoint: http://localhost:8081
[datastore] If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run:
[datastore]
[datastore]   export DATASTORE_EMULATOR_HOST=localhost:8081

@quantuminformation
Copy link
Author

Not sure if I broke smth locally though, opened another terminal and same issue

@stephenplusplus
Copy link
Contributor

Ah, nice that it was caught! All you should need to do, then, is start the emulator, set the env var, and the Datastore lib will figure it out.

Not sure if I broke smth locally though, opened another terminal and same issue

The issue where the emulator wants you to set "::1:8766", or @google-cloud/datastore can't detect that it should connect to the emulator?

@quantuminformation
Copy link
Author

quantuminformation commented Sep 11, 2019

The issue where the emulator wants you to set "::1:8766",

It confused me for a few mins that one

@stephenplusplus
Copy link
Contributor

That is strange.

@JustinBeckwith -- is there a way we can pass this confusion along to the relevant team, and maybe see if the new output format is deliberate and something we'd need to support?

@JustinBeckwith
Copy link
Contributor

That's super strange. @stephenplusplus can you start an email thread with me and Ben?

@quantuminformation
Copy link
Author

what have I started....

)

@jkwlui
Copy link
Member

jkwlui commented Sep 13, 2019

That looks like an ipv6 loopback address equiv to localhost.

https://stackoverflow.com/questions/40189084/what-is-ipv6-for-localhost-and-0-0-0-0

@stephenplusplus
Copy link
Contributor

#502 can take over for this issue, regarding supporting IPv6 addresses.

@google-cloud-label-sync google-cloud-label-sync bot added the api: datastore Issues related to the googleapis/nodejs-datastore API. label Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

5 participants