OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import alerts_history | 5 import alerts_history |
6 import json | 6 import json |
7 import logging | 7 import logging |
8 import utils | 8 import utils |
9 import webapp2 | 9 import webapp2 |
10 import zlib | 10 import zlib |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 | 34 |
35 class TimeSeriesAlertsHandler(webapp2.RequestHandler): | 35 class TimeSeriesAlertsHandler(webapp2.RequestHandler): |
36 ALERT_TYPE = 'ts-alerts' | 36 ALERT_TYPE = 'ts-alerts' |
37 MEMCACHE_COMPRESSION_LEVEL = 9 | 37 MEMCACHE_COMPRESSION_LEVEL = 9 |
38 # Alerts which have continued to fire are re-sent every 5 minutes, so stale | 38 # Alerts which have continued to fire are re-sent every 5 minutes, so stale |
39 # alerts older than 300 seconds are replaced by incoming alerts. | 39 # alerts older than 300 seconds are replaced by incoming alerts. |
40 STALE_ALERT_TIMEOUT = 300 | 40 STALE_ALERT_TIMEOUT = 300 |
41 | 41 |
42 def get(self, key=None): | 42 def get(self, key=None): |
43 utils.increment_monarch('ts-alerts') | |
44 self.remove_expired_alerts() | 43 self.remove_expired_alerts() |
45 if not users.get_current_user(): | 44 if not users.get_current_user(): |
46 results = {'date': dt.utcnow(), | 45 results = {'date': dt.utcnow(), |
47 'redirect-url': users.create_login_url(self.request.uri)} | 46 'redirect-url': users.create_login_url(self.request.uri)} |
48 self.write_json(results) | 47 self.write_json(results) |
49 return | 48 return |
50 | 49 |
51 if key: | 50 if key: |
52 logging.info('getting the key: ' + key) | 51 logging.info('getting the key: ' + key) |
53 try: | 52 try: |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 def set_memcache(self, key, data): | 168 def set_memcache(self, key, data): |
170 json_data = utils.generate_json_dump(data, False) | 169 json_data = utils.generate_json_dump(data, False) |
171 compression_level = self.MEMCACHE_COMPRESSION_LEVEL | 170 compression_level = self.MEMCACHE_COMPRESSION_LEVEL |
172 compressed = zlib.compress(json_data, compression_level) | 171 compressed = zlib.compress(json_data, compression_level) |
173 memcache.set(key, compressed) | 172 memcache.set(key, compressed) |
174 | 173 |
175 | 174 |
176 class TimeSeriesAlertsHistory(alerts_history.AlertsHistory): | 175 class TimeSeriesAlertsHistory(alerts_history.AlertsHistory): |
177 | 176 |
178 def get(self, timestamp=None): | 177 def get(self, timestamp=None): |
179 utils.increment_monarch('ts-alerts-history') | |
180 result_json = {} | 178 result_json = {} |
181 if not users.get_current_user(): | 179 if not users.get_current_user(): |
182 result_json['login-url'] = users.create_login_url(self.request.uri) | 180 result_json['login-url'] = users.create_login_url(self.request.uri) |
183 return result_json | 181 return result_json |
184 | 182 |
185 alerts = TSAlertsJSON.query_active().fetch() | 183 alerts = TSAlertsJSON.query_active().fetch() |
186 if timestamp: | 184 if timestamp: |
187 try: | 185 try: |
188 time = dt.fromtimestamp(int(timestamp)) | 186 time = dt.fromtimestamp(int(timestamp)) |
189 except ValueError: | 187 except ValueError: |
(...skipping 27 matching lines...) Expand all Loading... |
217 self.response.headers['Content-Type'] = 'application/json' | 215 self.response.headers['Content-Type'] = 'application/json' |
218 data = utils.generate_json_dump(data) | 216 data = utils.generate_json_dump(data) |
219 self.response.write(data) | 217 self.response.write(data) |
220 | 218 |
221 | 219 |
222 app = webapp2.WSGIApplication([ | 220 app = webapp2.WSGIApplication([ |
223 ('/ts-alerts', TimeSeriesAlertsHandler), | 221 ('/ts-alerts', TimeSeriesAlertsHandler), |
224 ('/ts-alerts/(.*)', TimeSeriesAlertsHandler), | 222 ('/ts-alerts/(.*)', TimeSeriesAlertsHandler), |
225 ('/ts-alerts-history', TimeSeriesAlertsHistory), | 223 ('/ts-alerts-history', TimeSeriesAlertsHistory), |
226 ('/ts-alerts-history/(.*)', TimeSeriesAlertsHistory)]) | 224 ('/ts-alerts-history/(.*)', TimeSeriesAlertsHistory)]) |
OLD | NEW |