| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 contextlib | 5 import contextlib |
| 6 | 6 |
| 7 from google.appengine.api import modules | 7 from google.appengine.api import modules |
| 8 from google.appengine.api import namespace_manager | 8 from google.appengine.api import namespace_manager |
| 9 from google.appengine.ext import ndb | 9 from google.appengine.ext import ndb |
| 10 | 10 |
| 11 from infra_libs.ts_mon.common import metrics | 11 from infra_libs.ts_mon.common import metrics |
| 12 | 12 |
| 13 REGION = 'appengine' | 13 REGION = 'appengine' |
| 14 PUBSUB_PROJECT = 'chrome-infra-mon-pubsub' | 14 PUBSUB_PROJECT = 'chrome-infra-mon-pubsub' |
| 15 PUBSUB_TOPIC = 'monacq' | 15 PUBSUB_TOPIC = 'monacq' |
| 16 INSTANCE_NAMESPACE = 'ts_mon_instance_namespace' | 16 INSTANCE_NAMESPACE = 'ts_mon_instance_namespace' |
| 17 # Duration of inactivity to consider an instance dead. | 17 # Duration of inactivity to consider an instance dead. |
| 18 INSTANCE_EXPIRE_SEC = 30 * 60 | 18 INSTANCE_EXPIRE_SEC = 30 * 60 |
| 19 INSTANCE_EXPECTED_TO_HAVE_TASK_NUM_SEC = 5 * 60 | 19 INSTANCE_EXPECTED_TO_HAVE_TASK_NUM_SEC = 5 * 60 |
| 20 INTERNAL_CALLBACK_NAME = '__gae_ts_mon_callback' | 20 INTERNAL_CALLBACK_NAME = '__gae_ts_mon_callback' |
| 21 | 21 |
| 22 | 22 |
| 23 appengine_default_version = metrics.StringMetric( | 23 appengine_default_version = metrics.StringMetric( |
| 24 'appengine/default_version', | 24 'appengine/default_version', |
| 25 description='Name of the version currently marked as default.') | 25 'Name of the version currently marked as default.', |
| 26 None) |
| 26 started_counter = metrics.CounterMetric( | 27 started_counter = metrics.CounterMetric( |
| 27 'appengine/instances/started', | 28 'appengine/instances/started', |
| 28 description='Count the number of GAE instance initializations.') | 29 'Count the number of GAE instance initializations.', |
| 30 None) |
| 29 shutdown_counter = metrics.CounterMetric( | 31 shutdown_counter = metrics.CounterMetric( |
| 30 'appengine/instances/shutdown', | 32 'appengine/instances/shutdown', |
| 31 description='Count the number of GAE instance shutdowns.') | 33 'Count the number of GAE instance shutdowns.', |
| 34 None) |
| 32 expired_counter = metrics.CounterMetric( | 35 expired_counter = metrics.CounterMetric( |
| 33 'appengine/instances/expired', | 36 'appengine/instances/expired', |
| 34 description=('Count the number of GAE instance expirations ' | 37 'Count the number of GAE instance expirations due to inactivity.', |
| 35 'due to inactivity.')) | 38 None) |
| 36 | 39 |
| 37 | 40 |
| 38 global_metrics = {} | 41 global_metrics = {} |
| 39 global_metrics_callbacks = {} | 42 global_metrics_callbacks = {} |
| 40 | 43 |
| 41 | 44 |
| 42 def reset_for_unittest(): | 45 def reset_for_unittest(): |
| 43 global global_metrics | 46 global global_metrics |
| 44 global global_metrics_callbacks | 47 global global_metrics_callbacks |
| 45 global_metrics = {} | 48 global_metrics = {} |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 try: | 115 try: |
| 113 namespace_manager.set_namespace(INSTANCE_NAMESPACE) | 116 namespace_manager.set_namespace(INSTANCE_NAMESPACE) |
| 114 yield | 117 yield |
| 115 finally: | 118 finally: |
| 116 namespace_manager.set_namespace(previous_namespace) | 119 namespace_manager.set_namespace(previous_namespace) |
| 117 | 120 |
| 118 | 121 |
| 119 def get_instance_entity(): | 122 def get_instance_entity(): |
| 120 with instance_namespace_context(): | 123 with instance_namespace_context(): |
| 121 return Instance.get_or_insert(instance_key_id()) | 124 return Instance.get_or_insert(instance_key_id()) |
| OLD | NEW |