How to interact with a locally running datastore service in appengine-magic? - google-app-engine

I'm using appengine-magic to set up a web application, more or less as described at http://www.digitalbricklayers.com/2012/03/geotasklist-in-jquery-mobile-and.html. The example works on my local machine, locations and tasks are added to a local datastore etc.
My question is if it is possible to interact with the datastore from within a REPL, e.g. call (ds/save! ...) etc. during interactive development? I ask because when I try I get:
NullPointerException No API environment is registered for this thread.
com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppId
(DatastoreApiHelper.java:108)
I'm getting this error no matter if I use an eclipse+counterclockwise based setup or an emacs+slime based setup.
Thanks,
Joachim

There's a bunch of ways to do this.
The easiest way is to go to the admin console (http://localhost:/_ah/admin) and click on the "Interactive Console".
I use django-nonrel, which comes with a command to launch an interactive shell (manage.py shell). If you're not using django-nonrel though, getting it set up though, is somewhat involved. I suspect most of what's necessary is found in the setup_env() function in django-nonrel: https://github.com/django-nonrel/djangoappengine/blob/develop/djangoappengine/boot.py
Getting it all to work is a pain, good luck.
The solution I use 99% of the time is to use pdb and force the interpreter to break at a certain point in my app where I need to do some debugging. See this for instructions: http://eatdev.tumblr.com/post/12076034867/using-pdb-on-app-engine

appengine-magic lets you use App Engine services (like the datastore) as long as the application is running; see https://github.com/gcv/appengine-magic#app-engine-services — as long as you ae/start your application, it should work.

Related

Logging Errors in GCloud

Im writing a project using python hosted on a local Django server.
This same project is also deployed to GCloud where it's hosted on Google's Cloud server.
But every time it has any issues post-deployment, the GCloud's logging is always a hassle, mainly because its very uninformative.
When I run my project on my local machine, using the 'runserver' command in the command prompt, anytime an issue pops up, I'm able to view it through the command prompt (eg. django.db.utils.IntegrityError at line abc, method xyz )
Is there anything on GCloud that can give me logging akin to that? Especially if its an issue that has happened awhile back? Preferably something that is within the free trial, if possible?
Cause the best thing I could find was the Log Viewer on the project dashboard and the details it gives me is pretty scarce, something along these lines
error: 500
source: /app/submit/
resource.type="gae_app"
resource.labels.module_id="default"
resource.labels.version_id="20201117t191425"
logName=(...)
jsonPayload.trace="5ec93d7a13aac6b28fe5a8134db1691b"
It does not actually explain what causes the Error 500, as well as the details of the error.
And the documentation itself can sometimes have abit too much self-promoting and alot of linkings to broad topics that may(usually not) give me what I can use.

using golang logging library, where does one see localhost logs?

following the golang library instructions if you write logs with the client library, where can one see those logs when running your server locally during development (eg via go run main.go)?
in my case (not sure if it's relevant) i'm using the library as part of golang logic in appengine, and even the relevant-looking instructions on "viewing logs" for those docs don't mention local development explicitly. Is that because it (running gcloud app logs tail and seeing local server logs) should "just work" or because there's no way to see logs for a local logs sdk interaction?
It's a good question and the Cloud Logging libraries do appear bound to Google's Cloud Logging service but, for local development (your question) and, loose-coupling as a generally good principle, these libraries really ought to be pluggable. Why shouldn't services running on e.g. GCP route logs to e.g. AWS?
With OpenTelemetry (nee OpenCensus), Google (and others) promote the ability to disconnect metric and trace production from consuming services, and logs aren't distinctly different.
A popular logging library in Go, Logrus supports pluggable logging via Hooks and an old (!) Stackdriver Logging implementation exists; this should be straightforward to upgrade to the current API (version).
Meantime, I think your question would benefit from being posted to Google's public issue tracker for Stackdriver (sic.) logging (link) and I'm going to ask someone who's very familiar with Cloud Logging as she may have some insight into this for us.
Update
I emailed with some former colleagues at Google and learned that Open Telemetry will eventually encompass logging. This is mentioned briefly on the project's About page.
tl;dr Tentatively answering myself: that's not supported - instead one has to just conditionally swap out calls to regular logger if env (eg empty GAE_INSTANCE env variable) indicates you're on localhost.
Walking through the code under the NewClient(...) call on the logging package, I end up a spot where the upstream API is really being called (note the rpc context used by the very last turtle - I never saw logic as I walked through that seemed to be switching to something for local development), so I suspect there really is no emulation capturing.
EDIT: See DazWilkin's helpful answer below for more context

Run system tests against deployed app with Nancy.Testing

I've successfully set up some tests that run complete use cases against our code base using nancy.testing.
Now I'd like to use the same tests for what we call release tests: We deploy the complete application to a staging server and run the system tests against it. We already use that approach successfully with a WCF application.
Is there an easy way to make this work? I've noticed that Browser and BrowserResponse do not use any abstractions, so I cannot replace them with a SystemTestBrowser or similar.
I could of course abstract the whole nancy.testing package away, but I thought I ask here first if someone knows a simpler approach.
Nancy.Testing does not use any network communication at all. If you can think of a nice abstract then please let us know and we can talk and see if it's something we'd like to get into the package!

Why can't I use a UI component (Windows form) inside of a Windows service?

I've seen several posts that essentially state that UI components shouldn't run as a service. I understand the rational that no one can respond to UI events etc. But the fact remains that are are many automation tasks that are only possible with Windows forms.
Here is a couple of great examples:
I would like to build a url crawler
service that makes thumbnails of
webpages. Currently the only way I
see to achieve this is to try and
automate the .Net WebBroswer
component.
Automate the printing of MS-Word
docs.
Pre-Vista there was some tricks to get around this, but now there is none. My question is why is this the case, and what alternatives does one really have?
Lookup Shatter Attacks and Session 0 Isolation Feature.
Basically if two processes (of different users) share the same desktop, one process can potentially execute whatever code it wants in the other process by sending windows messages, and this was called a Shatter Attack.
There was a lot of discussion whether this was a design bug or not, and post Vista, Microsoft decided to remove any interactive desktop support for services as that was a potential security hole.
As an alternative, you can consider, running your image generation/printing code as a logged in user, who has access to an interactive desktop.
Like Moron said best thing to do is not run it as a service.
But perhaps you're stuck running it from a service anyway, because there is an existing framework of some sort that you're needing to run your code from.
So the workaround to that would be to write a server program that runs as a logged in user. You will hit that server program from your code the must be in a service. The server will do the work and return the results.
You can communicate between the 2 using WCF over named pipes as the transport, or whatever works. If that doesn't, you can use bare named pipes, or, tcp/ip on the localhost. Judging from your website in your userprofile, you should know all about localhost!
Technically, UI components requires started Windows Message Queue to work. You can run it from windows service (may be with allowed Interaction with Desktop, as far as I know this feature is disabled in Windows Vista and higher).
But things you are talking about is not UI components, it is COM components, and you can use it. At least MS Office, but it is not recommended by Microsoft, because memory leaks are possible. Latest MS Office has server edition, that can be used in application without user interface.

Simple standalone website checking tool

Background:
We run a content management platform that hosts 20+ separate websites - some intranets and some internet sites - so that have different end points routed for internal or external access.
We are currently upgrading our infrastructure - including software versions, hardware, changes of IP/VIP/DNS entries etc which affects all of the sites.
I want to be able to run a repeatable site test against all sites check everything is working fine and I'd like to do it from different end points (locally on each box in the cluster, from the cluster level, from the internet, from the intranet extra.
Anyone know of a simple tool that requires no sofware to install to run a repeatable regression test against a whole bunch of defined URL's?
I was thinking of a HTML page that I can run from different locations that is essentially a link checker.
Can anyone recommend a simple way to provide a level of automatic testing of our sites (in addition to our manual verification.
Thanks
Sounds like you're looking for Selenium: http://seleniumhq.org/
Edit
Wait, I think you mean 'Testing' them as in, check to see if they're online and reachable? Then I might just automate a series of ping or telnet commands, and check appropriate things. Would take a matter of minutes to write a little app in any language to do this.
There is all sorts of web site monitoring software available (check google, or ask for recos here). That's what you're looking for. There is a whole range from free to very expensive that monitor and stress your site from around the world.
Or you can write simple shell scripts that do what you want.
>> 'Testing' them as in, check to see if they're online and reachable?
Yes that's exactly it!! I was thinking the same - I could script something up but I thought I'd check first to see if someone has already done this - I guess not!
Thanks
Doesn't fit the "requires no sofware to install to run" part, and it's not necessarily super-cheap, but we've had great results with Radar Website Monitor for this kind of thing.

Resources