From 7bcda47e88ada6336440259fa14483d2140281d1 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 27 Apr 2016 12:48:37 -0700 Subject: [PATCH] Adding appstats sample Change-Id: Ia0a54ea44390a77b2ea786c95e033d9f6f8ff51d --- appengine/appstats/app.yaml | 10 +++++++ appengine/appstats/appengine_config.py | 20 ++++++++++++++ appengine/appstats/main.py | 36 ++++++++++++++++++++++++++ appengine/appstats/main_test.py | 21 +++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 appengine/appstats/app.yaml create mode 100644 appengine/appstats/appengine_config.py create mode 100644 appengine/appstats/main.py create mode 100644 appengine/appstats/main_test.py diff --git a/appengine/appstats/app.yaml b/appengine/appstats/app.yaml new file mode 100644 index 000000000000..eb89129d68e8 --- /dev/null +++ b/appengine/appstats/app.yaml @@ -0,0 +1,10 @@ +runtime: python27 +api_version: 1 +threadsafe: yes + +builtins: +- appstats: on + +handlers: +- url: .* + script: main.app diff --git a/appengine/appstats/appengine_config.py b/appengine/appstats/appengine_config.py new file mode 100644 index 000000000000..4c7a268901c6 --- /dev/null +++ b/appengine/appstats/appengine_config.py @@ -0,0 +1,20 @@ +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# The app engine runtime will call this function during instance startup. +def webapp_add_wsgi_middleware(app): + from google.appengine.ext.appstats import recording + app = recording.appstats_wsgi_middleware(app) + return app diff --git a/appengine/appstats/main.py b/appengine/appstats/main.py new file mode 100644 index 000000000000..8059336a4af5 --- /dev/null +++ b/appengine/appstats/main.py @@ -0,0 +1,36 @@ +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Sample Google App Engine application that demonstrates using appstats. + +For more information about App Engine, see README.md under /appengine. +""" + +# [START all] +from google.appengine.api import memcache +import webapp2 + + +class MainPage(webapp2.RequestHandler): + def get(self): + # Perform some RPCs so that appstats can capture them. + memcache.set('example_key', 50) + value = memcache.get('example_key') + self.response.write('Value is: {}'.format(value)) + +app = webapp2.WSGIApplication([ + ('/', MainPage) +], debug=True) +# [END all] diff --git a/appengine/appstats/main_test.py b/appengine/appstats/main_test.py new file mode 100644 index 000000000000..6909d802cf6a --- /dev/null +++ b/appengine/appstats/main_test.py @@ -0,0 +1,21 @@ +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import main +import webtest + + +def test_app(testbed): + app = webtest.TestApp(main.app) + app.get('/')