OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import json | |
6 import logging | |
7 import os | |
8 import sys | |
9 import webapp2 | |
10 | |
11 from google.appengine.ext import ndb | |
12 from google.appengine.api import users | |
13 | |
14 import common | |
15 import main | |
16 | |
17 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
18 sys.path.insert(0, os.path.join(BASE_DIR, 'components', 'third_party')) | |
19 | |
20 from components import auth | |
21 | |
22 | |
23 TEST_DATA_KEY = 'test_data_key' | |
24 | |
25 class LoadTestData(ndb.Model): | |
26 """Store load test data. | |
27 | |
28 To start a load test, set qps to a positive value. | |
ghost stip (do not use)
2015/04/14 00:36:43
I'm not sure exactly how this tests works. Does it
Sergey Berezin (google)
2015/04/16 04:39:07
The /loadtest endpoint does one simple thing - sto
| |
29 """ | |
30 qps = ndb.IntegerProperty(default=0) | |
31 payload_size = ndb.IntegerProperty(default=1024) | |
32 | |
33 | |
34 class TestHandler(auth.AuthenticatingHandler): | |
35 """A /dev/null endpoint to test the entire pipeline. | |
36 | |
37 This endpoint can be used in place of the MonAcq official endpoint | |
38 for testing the proxy. | |
39 """ | |
40 # Disable XSRF in local dev appserver; otherwise requests will fail. | |
41 if common.is_development_server(): | |
42 xsrf_token_enforce_on = [] # pragma: no cover | |
43 @main.is_group_member('service-account-monitoring-proxy-test') | |
44 def get(self): | |
45 msg = 'Received GET request.' | |
46 self.response.headers['Content-Type'] = 'text/plain' | |
47 self.response.out.write(msg) | |
48 logging.debug('Received GET at /test') | |
49 | |
50 @main.is_group_member('service-account-monitoring-proxy-test') | |
51 def post(self): | |
52 logging.info('Received POST /test: %s', | |
53 common.payload_stats(self.request.body)) | |
54 | |
55 | |
56 class LoadTestHandler(webapp2.RequestHandler): | |
57 """Store and publish load test parameters. | |
58 | |
59 Admins can set QPS, and anyone can retrieve it. This endpoint controls | |
60 distributed machines sending load test traffic to the proxy. | |
61 """ | |
62 def get(self, qps): | |
63 data = LoadTestData.get_or_insert(TEST_DATA_KEY) | |
64 if qps: # Only admins can set a qps value. | |
65 if not users.is_current_user_admin(): | |
66 self.redirect(users.create_login_url(self.request.url)) | |
67 return | |
68 qps = int(qps) | |
69 if qps < 0: | |
70 self.response.write('Error: cannot set QPS to negative value.') | |
71 return | |
72 data.qps = qps | |
73 payload_size = self.request.get('size') | |
74 if payload_size: | |
75 data.payload_size = int(payload_size) | |
76 data.put() | |
77 # Return JSON either way. | |
78 self.response.write(json.dumps(data.to_dict())) | |
79 | |
80 logging.basicConfig(level=logging.DEBUG) | |
81 | |
82 test_handlers = [ | |
83 (r'/test', TestHandler), | |
84 (r'/loadtest/(.*)', LoadTestHandler), | |
85 ] | |
86 | |
87 test = webapp2.WSGIApplication(test_handlers, debug=True) | |
OLD | NEW |