How to configure Google App Engine health checking

2019-05-13 19:54发布

Google App Engine requests /_ah/health from the managed vm to do health checking.

I trying to deploy a project that I'm not the code maintainer, it's going to be deployed as managed vm to have autoscaling and health checking.

Currently app.yaml doesn't support rewrite rules, if it supported I could point the /_ah/health to a /ping endpoint. This would be great because health checking could be implemented without changing code.

In app.yaml there is the configuration for handlers, my understanding is that handler are for use with the google runtime, not for managed VMs.

I want to change the location of the /_ah/health request. Is there a way to do this change?

1条回答
劳资没心,怎么记你
2楼-- · 2019-05-13 20:16

So, suppose you have a "health-check serving endpoint" (using webapp2 for definiteness, other frameworks would of course work similarly) in health.py:

class HealthPage(webapp2.RequestHandler):
  def get(self):
    self.response.write('<html><body><p>I\'m fine!</p></body></html>')

and unfortunately you also have routing information hard-coded, say in the same file (rather than more properly reading it from an easily modified and pushed configuration file):

application = webapp2.WSGIApplication([
  ('/howareyou', HealthPage),
])

Now, to serve health checks from that same HealthPage handler, you need to edit your app.yaml to have:

handlers:
- url: /_ah/health
  script: health.application

before any handlers whose url: has wildcards that might "swallow" this one, of course.

Now, since you have a strict, hard-coded routing decision in your application object, you'll have to edit that. This isn't really "editing code" -- it's editing configuration information that you unfortunately decided to embed as strict, hard-coded strings in your code, rather than picking it up from a configuration code.

Either make the in-code routing less strict, maybe all the way down to:

application = webapp2.WSGIApplication([
  ('.*', HealthPage),
])

or if you're committed to using very strict hardcoded routes in your code, you' might choose to add one line...:

application = webapp2.WSGIApplication([
  ('/howareyou', HealthPage),
  ('/_ah/health', HealthPage),
])

Similarly for other routing systems (beyond app.yaml and other configuration-based routing done for you by App Engine itself) of course -- webapp2's routing system is nothing strange, nor anomalous.

Note that none of these edits stop your code from serving the /howareyou URL if it's routed to health.py in other (non-GAE and non-GAE-like) deployments -- they'll serve it just as well as they used to do.

If despite all of this you still demand a "URL rewriting" capability in app.yaml, or similarly powerful features, to deal with health checks while avoiding the need for this kind of tiny workaround, you can of course open a feature request at https://code.google.com/p/googleappengine/issues/list -- I just can't imagine it getting high urgency vs the thousands of open issues there, but, hey!, I've been wrong before:-).

查看更多
登录 后发表回答