Exemple #1
0
 def test_reset(self):
     m = metrics.StringMetric('test')
     self.assertIsNone(m.get())
     m.set('foo')
     self.assertEqual('foo', m.get())
     m.reset()
     self.assertIsNone(m.get())
Exemple #2
0
 def test_serialize(self):
     t = targets.DeviceTarget('reg', 'role', 'net', 'host')
     m = metrics.StringMetric('test')
     m.set('val')
     p = metrics_pb2.MetricsCollection()
     m.serialize_to(p, 1234, (('bar', 1), ('baz', False)), m.get(), t)
     return str(p).splitlines()
Exemple #3
0
 def test_serialize_too_many_fields(self):
     m = metrics.StringMetric('test',
                              fields={
                                  'a': 1,
                                  'b': 2,
                                  'c': 3,
                                  'd': 4
                              })
     m.set('val', fields={'e': 5, 'f': 6, 'g': 7})
     with self.assertRaises(errors.MonitoringTooManyFieldsError):
         m.set('val', fields={'e': 5, 'f': 6, 'g': 7, 'h': 8})
Exemple #4
0
 def test_set(self):
     m = metrics.StringMetric('test')
     m.set('hello world')
     self.assertEquals(m.get(), 'hello world')
Exemple #5
0
 def test_non_string_raises(self):
     m = metrics.StringMetric('test')
     with self.assertRaises(errors.MonitoringInvalidValueTypeError):
         m.set(object())
Exemple #6
0
 def test_set_list_fields(self):
     m = metrics.StringMetric('foo', 'foo', [metrics.IntegerField('asdf')])
     with self.assertRaises(ValueError):
         m.set('bar', [1])
Exemple #7
0
 def test_populate_value(self):
     pb = metrics_pb2.MetricsData()
     m = metrics.StringMetric('test')
     m._populate_value(pb, 'foo', 1234)
     self.assertEquals(pb.string_value, 'foo')
Exemple #8
0
 def test_set_wrong_number_of_fields(self):
     m = metrics.StringMetric('foo', 'foo', [metrics.IntegerField('asdf')])
     with self.assertRaises(errors.WrongFieldsError):
         m.set('bar', {'asdf': 1, 'foo': 2})
Exemple #9
0
 def test_is_cumulative(self):
     m = metrics.StringMetric('test', 'test', None)
     self.assertFalse(m.is_cumulative())
Exemple #10
0
 def test_generate_proto(self):
     proto = self._test_proto(metrics.StringMetric('t', 't', None),
                              lambda m: m.set('aaa'), metrics_pb2.STRING,
                              metrics_pb2.GAUGE)
     self.assertEqual('aaa', proto.string_value)
Exemple #11
0
from google.appengine.api import namespace_manager
from google.appengine.ext import ndb

from infra_libs.ts_mon.common import metrics

REGION = 'appengine'
PUBSUB_PROJECT = 'chrome-infra-mon-pubsub'
PUBSUB_TOPIC = 'monacq'
INSTANCE_NAMESPACE = 'ts_mon_instance_namespace'
# Duration of inactivity to consider an instance dead.
INSTANCE_EXPIRE_SEC = 30 * 60
INSTANCE_EXPECTED_TO_HAVE_TASK_NUM_SEC = 5 * 60
INTERNAL_CALLBACK_NAME = '__gae_ts_mon_callback'

appengine_default_version = metrics.StringMetric(
    'appengine/default_version',
    description='Name of the version currently marked as default.')
started_counter = metrics.CounterMetric(
    'appengine/instances/started',
    description='Count the number of GAE instance initializations.')
shutdown_counter = metrics.CounterMetric(
    'appengine/instances/shutdown',
    description='Count the number of GAE instance shutdowns.')
expired_counter = metrics.CounterMetric(
    'appengine/instances/expired',
    description=('Count the number of GAE instance expirations '
                 'due to inactivity.'))

global_metrics = {}
global_metrics_callbacks = {}
Exemple #12
0
from infra_libs.ts_mon.common import metrics

REGION = 'appengine'
PRODXMON_ENDPOINT = 'https://prodxmon-pa.googleapis.com/v1:insert'
PRODXMON_SERVICE_ACCOUNT_EMAIL = (
    'app-engine-metric-publishers@'
    'prodx-mon-chrome-infra.google.com.iam.gserviceaccount.com')
INSTANCE_NAMESPACE = 'ts_mon_instance_namespace'
# Duration of inactivity to consider an instance dead.
INSTANCE_EXPIRE_SEC = 30 * 60
INSTANCE_EXPECTED_TO_HAVE_TASK_NUM_SEC = 5 * 60
INTERNAL_CALLBACK_NAME = '__gae_ts_mon_callback'


appengine_default_version = metrics.StringMetric(
    'appengine/default_version',
    'Name of the version currently marked as default.',
    None)
started_counter = metrics.CounterMetric(
    'appengine/instances/started',
    'Count the number of GAE instance initializations.',
    None)
shutdown_counter = metrics.CounterMetric(
    'appengine/instances/shutdown',
    'Count the number of GAE instance shutdowns.',
    None)
expired_counter = metrics.CounterMetric(
    'appengine/instances/expired',
    'Count the number of GAE instance expirations due to inactivity.',
    None)