| 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 copy | 5 import copy |
| 6 import datetime | 6 import datetime |
| 7 import functools | 7 import functools |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 from infra_libs.ts_mon.common import metric_store | 32 from infra_libs.ts_mon.common import metric_store |
| 33 from infra_libs.ts_mon.common import monitors | 33 from infra_libs.ts_mon.common import monitors |
| 34 from infra_libs.ts_mon.common import standard_metrics | 34 from infra_libs.ts_mon.common import standard_metrics |
| 35 from infra_libs.ts_mon.common import targets | 35 from infra_libs.ts_mon.common import targets |
| 36 | 36 |
| 37 | 37 |
| 38 def _reset_cumulative_metrics(): | 38 def _reset_cumulative_metrics(): |
| 39 """Clear the state when an instance loses its task_num assignment.""" | 39 """Clear the state when an instance loses its task_num assignment.""" |
| 40 logging.warning('Instance %s got purged from Datastore, but is still alive. ' | 40 logging.warning('Instance %s got purged from Datastore, but is still alive. ' |
| 41 'Clearing cumulative metrics.', shared.instance_key_id()) | 41 'Clearing cumulative metrics.', shared.instance_key_id()) |
| 42 for _target, metric, start_time, _fields in interface.state.store.get_all(): | 42 for _, metric, _, _, _ in interface.state.store.get_all(): |
| 43 if metric.is_cumulative(): | 43 if metric.is_cumulative(): |
| 44 metric.reset() | 44 metric.reset() |
| 45 | 45 |
| 46 | 46 |
| 47 _flush_metrics_lock = threading.Lock() | 47 _flush_metrics_lock = threading.Lock() |
| 48 | 48 |
| 49 | 49 |
| 50 def need_to_flush_metrics(time_now): | 50 def need_to_flush_metrics(time_now): |
| 51 """Check if metrics need flushing, and update the timestamp of last flush. | 51 """Check if metrics need flushing, and update the timestamp of last flush. |
| 52 | 52 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 duration_secs * 1000, | 349 duration_secs * 1000, |
| 350 request_size=request_size, | 350 request_size=request_size, |
| 351 response_size=response_size, | 351 response_size=response_size, |
| 352 user_agent=request.META.get('HTTP_USER_AGENT', None)) | 352 user_agent=request.META.get('HTTP_USER_AGENT', None)) |
| 353 return response | 353 return response |
| 354 | 354 |
| 355 | 355 |
| 356 def reset_for_unittest(disable=False): | 356 def reset_for_unittest(disable=False): |
| 357 shared.reset_for_unittest() | 357 shared.reset_for_unittest() |
| 358 interface.reset_for_unittest(disable=disable) | 358 interface.reset_for_unittest(disable=disable) |
| OLD | NEW |