Using go delve with google app engine standard & dev_appserver.py - google-app-engine

In the google release notes it says:
November 15, 2017
Go runtime notes
Updated Go SDK to 1.9.61
Add --go_debugging flag to dev_appserver.py to enable Delve debugging.
I'm using dev_appserver.py to fire up several services simultaneously, so that they all share the same datastore emulator, and it works great.
However, when I add that --go_debugging flag, I get lots of errors which I don't understand. If anyone has insight, I'd be grateful.
I get these kinds of errors for each service it tries to build:
can't load package: package -N: unknown import path "-N": cannot find module providing package -N
can't load package: package -l: unknown import path "-l": cannot find module providing package -l
Is there maybe a problem with launching several services at once?
Thanks!

Update Nov 2020:
With all the new changes to app engine being able to use standard go libraries at google APIs, now I can just run my go app locally without using dev_appserver, and let it attach to my local datastore emulator etc. Because of that, and thanks to vscode, delve debugging works great (with the go extension). So now I can step through my app engine standard go code.

Related

GAE: No longer able to update my Gaelyk project due to appcfg losing support

Recently tried to update my Gaelyk project (yes, it's old, but it works well and I still use it), but Google App Engine will no longer accept the update. The error message returned is "Deployments using appcfg are no longer supported. See https://cloud.google.com/appengine/docs/deprecations". The thing is, I never used appcfg to deploy my application; I used Gaelyk and Gradle. But obviously Gaelyk must have used appcfg under the covers.
I did download the replacement Google Cloud SDK, but this new tool is not similar at all to how Gaelyk and Gradle worked. Is there anything I can do to get Gaelyk to work anymore? Or is Gaelyk just dead and I need to rewrite my application (like in Node.js or something instead of Groovy).
This will be hard, however I will try to help you as possible. I think you may try to migrate it somehow to app.yaml configuration of GAE.
I am not sure what plugins are used in the project. From Gaelyk temple project I can see that it's using appengine-geb which, according to the documentation, behind the scenes, is using gradle-appengine-plugin (there is wrong link on this doc, but proper is bellow).
On the github of gradle-appengine-plugin I have found following.
There is a note:
NOTE: All App Engine users are encouraged to transition to the new
gradle plugin for their projects.
And in FAQ part there is following information:
How do I deploy with gcloud?
If you're using gcloud to deploy your application, the newest version of app deploy > doesn't support war
directories, you will need to provide it with an app.yaml OR you can
use the appengineStage task to create a directory that is deployable
in /build/staged-app
$ ./gradlew appengineStage
$ gcloud app deploy build/staged-app/app.yaml --project [app id]
--version [some version]
NOTES:
You must explicitly define all config files your want to upload
(cron.yaml, etc)
This does not work with EAR formatted projects.
I think the best option will be to migrate to new appenine plugin or if not possible try to implement is with gcloud app deploy command crating the config files manually (at least app.yaml). And for this migration I can provide you this document.
I hope you will manage somehow...
I can confirm that Serge's answer on the Gaelyk Groups site works; the same procedure that he figured out also worked for me. To summarize:
Run gradlew appengineRun as run previously with Gaelyk.
Copy all jar files inside the build\exploded-app\WEB-INF\lib folder into a \src\main\webapp\web-inf\lib folder (for me the new lib folder did not exist previously).
To deploy, use the new required gcloud tool, and instead of running gradlew appengineUpdate (which fails now), instead run
gcloud app deploy appengine-web.xml where that XML file can be found in your webapp/WEB-INF directory. I navigated to that directory to run the gcloud command, but you can use a relative path there if your working directory is elsewhere. (There are a number of optional flags associated with the gcloud app deploy command, but I didn't need any of them.)
Serge needed to use these instructions to convert datastore-indexes.xml to index.yaml and run gcloud app deploy index.yaml, however, I didn't need to do this because I had no datastores.

Google Cloud Platform: Updating a project after deployment

I am using Google Cloud to deploy my application. I have followed the steps in the documentation for deploying. I deployed early on in my project and it was successful. I then decided to change some files and update some features in my app. For this i followed the documentation for updating a deployment. This update was successful. It had me create the deployment in my Deployment Manager and run the gcloud commands to commence update. When I redeployed with gcloud app deploy, it was successful.
I have since added a couple more lines of code and features in my application. I followed the same documentation for updating a deployment as I had the first time I made an update and it is no longer working for me.
Does anybody have any idea what would be the problem? Again, I was able to successfully deploy, and even update that deployment once by following Google Cloud docs. Now I am having no luck.
Have you been changing the version number? Go to:
https://console.cloud.google.com/appengine/versions?project=< your project name >&serviceId=default
And make sure the version you want is active. Also, you can try:
http://<VERSION>-dot-<SERVICE>-dot-<PROJECT_ID>.<REGION_ID>.r.appspot.com
Example:
https://20200813-dot-myapp.uc.r.appspot.com
if the version number was 20200813 and your appname is myapp and the region is uc

Google App Engine: connection interrupted while running gradle appengineDeploy and now application will not work (including firebase cloud messaging)

While I was deploying my google app engine project (Java) using gradle appengineDeploy my internet connection was interrupted.
I re-deployed the project. Although the console said BUILD SUCCESSFUL, the app engine instance no longer works. No matter how many times I re-deploy or update my application, the logs show nothing but errors:
java.lang.NoClassDefFoundError: com/google/appengine/api/ThreadManager
at
com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter.createClient
(GoogleAppEngineControlFilter.java:61) at
com.google.api.control.ControlFilter.init (ControlFilter.java:141) at
org.eclipse.jetty.servlet.FilterHolder.initialize
(FilterHolder.java:139) at
org.eclipse.jetty.servlet.ServletHandler.initialize
(ServletHandler.java:873) at
org.eclipse.jetty.servlet.ServletContextHandler.startContext
(ServletContextHandler.java:349) at
org.eclipse.jetty.webapp.WebAppContext.startWebapp
(WebAppContext.java:1406) at
com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.startWebapp
(AppEngineWebAppContext.java:175) at
org.eclipse.jetty.webapp.WebAppContext.startContext
(WebAppContext.java:1368) at
org.eclipse.jetty.server.handler.ContextHandler.doStart
(ContextHandler.java:778) at
org.eclipse.jetty.servlet.ServletContextHandler.doStart
(ServletContextHandler.java:262) at
org.eclipse.jetty.webapp.WebAppContext.doStart
(WebAppContext.java:522) at
com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doStart
(AppEngineWebAppContext.java:120) at
org.eclipse.jetty.util.component.AbstractLifeCycle.start
(AbstractLifeCycle.java:68) at
com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.createHandler
(AppVersionHandlerMap.java:240) at
com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.getHandler
(AppVersionHandlerMap.java:178) at
com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest
(JettyServletEngineAdapter.java:120) at
com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest
(JavaRuntime.java:747) at
com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest
(JavaRuntime.java:710) at
com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run
(JavaRuntime.java:680) at
com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run
(JavaRuntime.java:872) at
com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run
(ThreadGroupPool.java:270) at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.ClassNotFoundException:
com.google.appengine.api.ThreadManager at
java.net.URLClassLoader.findClass (URLClassLoader.java:381) at
com.google.apphosting.runtime.ApplicationClassLoader.findClass
(ApplicationClassLoader.java:135) at java.lang.ClassLoader.loadClass
(ClassLoader.java:424) at java.lang.ClassLoader.loadClass
(ClassLoader.java:357)
Is there some way for me to clear out the partial build (or whatever there may be) in google app engine?
I tried deleting all versions and instances (you cannot delete them all, it won't let you delete the serving one).
I tried increasing the version number in appengine-web.xml.
I tried gradle clean.
I tried disabling and enabling the application in the google cloud console.
No luck.
One idea I have is maybe if I can somehow force all the files for the app to be uploaded again? Because with gradle appengineDeploy only the changed files get uploaded.
EDIT:
I managed to fix one part of this by upgrading classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.2.0' in my gradle to the latest version. (Felt kind of hackish to do that and not reliable in the future if this happens again.) Maybe this flushed whatever was in app engine or something by doing that. I still have one problem remaining:
I am using the firebase admin SDK to send firebase cloud messages (authenticated with a .json credentials file) like this:
FirebaseMessaging.getInstance().send(msg);
When I do I am getting this error:
com.google.firebase.messaging.FirebaseMessagingException: Unexpected
HTTP response with status: 401; body: null
Which is strange because other parts of the firebase admin SDK are working (like writing/reading from firestore).
So there is still something weird going on and I think it has to do with the fact that as I was uploading my google app engine project the connection was interrupted.
EDIT 2:
Here is something interesting: When I deploy my application using gcloud app deploy appengine-web.xml the application again will not work. Deploying with gradle appengineDeploy does though. I also noticed that the size of the application is shown as much smaller in the GCP console when deploying with gcloud app deploy appengine-web.xml. So something is messed up here. I tried looking up some sort of gcloud command to clear cache? Or something like that but no luck.
EDIT 3:
Additional Info:
My app was already deployed and working before the failed attempt. I changed one small piece of code in a function and upon uploading the app, the connection was interrupted because the internet went out.
I am on app engine standard environment.
I am deploying my application from the macOS terminal and using android studio to develop.
I have tried the stopPreviousVersion promote and version configs in gradle (actually the first two are true by default and version gets auto-generated if you do not set it).
Running gcloud app deploy appengine-web.xml --verbosity=debug shows a lot of sensitive information but one thing I am seeing is all the files in WEB-INF are being skipped:
DEBUG: Skipping upload of [WEB-INF/....
INFO: Incremental upload skipped 100.0% of data
DEBUG: Uploading 0 files to Google Cloud Storage
DEBUG: Using [16] threads
So perhaps files are not all being uploaded? This SO post raises a similar problem but has no solution: stackoverflow.com/q/42137452/3075340
It's weird but when I do gcloud app deploy, the app won't work at all. There are run-time errors all over the place. Doing gradle appengineDeploy fixes that but I still am having the firebase-admin issue.
To actually answer your question, GAE uses a staging bucket to cache files.
You can delete this bucket, and it will get recreated next time you try to deploy.
The bucket is always named staging.[PROJECT-ID].appspot.com. It should show on the buckets overview page
Just to be clear, I'm not anywhere near sure that this will actually resolve your issue, but this will most definitely clear whatever files GAE cached
Here there was a discussion on a, more or less, similar issue on App Engine from last year.
You can use it as a source of inspiration to fix your current issue, because I think they are really similar as a concept. From there I think it may worth trying to put the appengine-api-1.0-sdk-1.9.63.jar ( or whatever your version is ) file under WEB-INF/lib.
It the same post there were some guys who found out the there was a problem with gcloud v194 and switching to another version fixed the issue.
Here there is a similar issue which was resolved by upgrading the gcloud tool.
Anyhow, this behaviour is not normal and things should not work like this. You can try to find a workaround, but my recommendation is to report the issue and let an App Engine engineer taking a look over it. There are good chances to be something internal.

How to use ujson with Google App Engine

According to the official list of built-in libraries, ujson is available. However, the following app.yaml snippet:
libraries:
- name: ujson
version: '1.35'
...generates this error:
Usage: appcfg.py [options] update <directory> | [file, ...]
appcfg.py: error: Error parsing ./app.yaml: the library "ujson" is not supported
in "./app.yaml", line 89, column 1.
If I try to use other supported C libraries like numpy, it works fine. I am running SDK 159.0.0 (latest) and can even see a "ujson" entry in google-cloud-sdk/lib/googlecloudsdk/third_party/appengine/api/appinfo.py.
Any clue why ujson isn't usable?
ujson v1.35 was added to the app engine runtime in Python SDK version 1.9.55.
This sdk version wasn't included in the gcloud sdk until v161.0.0 (2017-06-28):
Updated App Engine components for Python to version 1.9.55. Please visit the release notes for details
Anecdote:
Some of us still prefer appcfg.py update . instead of gcloud app deploy app.yaml.(We are a rare and dying breed :D).
So in the past I noticed that the appcfg.py tool I was using was an older version from the older app engine tooling. Doesn't come with all the gcloud components update awesomeness. You had to download the binaries each time.
which appcfg.py should reveal the exact one being used which for me was:
$ ~/google_appengine/appcfg.py
I can't say I wasn't warned enough. Besides, I kept seeing this advice/warning each time I ran gcloud components update:
WARNING: There are older versions of Google Cloud Platform tools on your system PATH.
Please remove the following to avoid accidentally invoking these old tools:
/Users/jeff/google_appengine/endpointscfg.py
/usr/local/bin/endpointscfg.py
/Users/jeff/google_appengine/dev_appserver.py
So update to the latest version, update your paths to point to the right appcfg, and enjoy ujson or any of the goodies as and when they drop.
$ ~/google-cloud-sdk/platform/google_appengine/appcfg.py update .

Can not download code from google app engine

I want to download the code from google app engine.
And I installed python, google engine sdk and executed this command
appcfg.py download_app -a ...
and I typed my mail address and password...
but it says
Error 403: ---
You do not have permission to download this app version
What do you think is the problem? Please help me with this.
I am stuck with this like all day but can't find the solution.
I encountered the same problem (Mac OS, running AppEngineLauncher).
Noticed that no apps were running in GAEL.
Running one of the apps in GAEL (earlier version of the same one - could be a coincidence) seemed to make a difference - it started the download, but then halted.
Then I ran appcfg list_versions on that app, followed by download_app.
That seemed to do the job - download continuing as I write this.
On a guess, appcfg got hazy about its security context. YMMV.
Check:
Only the developer who uploaded the code and the application owner(s) can download it. If anyone other than these parties attempts to download the app, they'll see an error message like the following: Error 403
https://developers.google.com/appengine/docs/python/tools/uploadinganapp#Python_Downloading_source_code
or your app have set permanently prohibit code downloads. Check on page: https://appengine.google.com/deployment/codelock?app_id=your_app_id&to_forward=/permissions?app_id=your_app_id
Adding flag --no_cookies worked for me.

Resources