예제 #1
0
 def test_should_add_matching_hashes_for_matching_labels(self):
     a_dict = {'test': 'dict'}
     mv1 = metric_value.create(labels=a_dict)
     mv2 = metric_value.create(labels=a_dict)
     want = self.make_hash(mv1)
     got = self.make_hash(mv2)
     expect(got).to(equal(want))
 def test_should_add_matching_hashes_for_matching_labels(self):
     a_dict = {'test': 'dict'}
     mv1 = metric_value.create(labels=a_dict)
     mv2 = metric_value.create(labels=a_dict)
     want = self.make_hash(mv1)
     got = self.make_hash(mv2)
     expect(got).to(equal(want))
 def test_should_update_hash_for_when_currency_is_added(self):
     a_dict = {'test': 'dict'}
     mv1 = metric_value.create(labels=a_dict)
     mv2 = metric_value.create(labels=a_dict)
     mv2.moneyValue = messages.Money(currencyCode='JPY')
     want = self.make_hash(mv1)
     got = self.make_hash(mv2)
     expect(got).to_not(equal(want))
예제 #4
0
 def test_should_update_hash_for_when_currency_is_added(self):
     a_dict = {'test': 'dict'}
     mv1 = metric_value.create(labels=a_dict)
     mv2 = metric_value.create(labels=a_dict)
     mv2.moneyValue = messages.Money(currencyCode='JPY')
     want = self.make_hash(mv1)
     got = self.make_hash(mv2)
     expect(got).to_not(equal(want))
예제 #5
0
 def test_should_fail_for_delta_metrics_with_unmergable_types(self):
     no_init = metric_value.create()
     unmergeables = [
         metric_value.create(stringValue='a test string'),
         metric_value.create(boolValue=False),
     ]
     for mv in unmergeables:
         testf = lambda: metric_value.merge(MetricKind.DELTA, mv, mv)
         expect(testf).to(raise_error(ValueError))
 def test_should_fail_for_delta_metrics_with_unmergable_types(self):
     no_init = metric_value.create()
     unmergeables = [
         metric_value.create(stringValue='a test string'),
         metric_value.create(boolValue=False),
     ]
     for mv in unmergeables:
         testf = lambda: metric_value.merge(MetricKind.DELTA, mv, mv)
         expect(testf).to(raise_error(ValueError))
예제 #7
0
 def setUp(self):
     self.test_value = metric_value.create(labels=self.TEST_LABELS,
                                           doubleValue=self.A_FLOAT_VALUE)
     self.early_ending = metric_value.create(labels=self.TEST_LABELS,
                                             doubleValue=self.A_FLOAT_VALUE,
                                             endTime=self.EARLY)
     self.late_ending = metric_value.create(labels=self.TEST_LABELS,
                                            doubleValue=self.A_FLOAT_VALUE,
                                            endTime=self.LATER)
     self.test_value_with_money = metric_value.create(
         labels=self.TEST_LABELS,
         moneyValue=messages.Money(currencyCode='JPY', units=100, nanos=0))
예제 #8
0
 def test_should_use_the_earliest_start_time_in_delta_merges(self):
     early_starting = metric_value.create(labels=self.TEST_LABELS,
                                          doubleValue=self.A_FLOAT_VALUE,
                                          startTime=self.EARLY)
     late_starting = metric_value.create(labels=self.TEST_LABELS,
                                         doubleValue=self.A_FLOAT_VALUE,
                                         startTime=self.LATER)
     got = metric_value.merge(MetricKind.DELTA, early_starting,
                              late_starting)
     expect(got.startTime).to(equal(early_starting.startTime))
     got = metric_value.merge(MetricKind.DELTA, late_starting,
                              early_starting)
     expect(got.startTime).to(equal(early_starting.startTime))
 def test_should_use_the_earliest_start_time_in_delta_merges(self):
     early_starting = metric_value.create(
         labels=self.TEST_LABELS,
         doubleValue=self.A_FLOAT_VALUE,
         startTime=self.EARLY)
     late_starting = metric_value.create(
         labels=self.TEST_LABELS,
         doubleValue=self.A_FLOAT_VALUE,
         startTime=self.LATER)
     got = metric_value.merge(MetricKind.DELTA, early_starting,
                              late_starting)
     expect(got.startTime).to(equal(early_starting.startTime))
     got = metric_value.merge(MetricKind.DELTA, late_starting,
                              early_starting)
     expect(got.startTime).to(equal(early_starting.startTime))
예제 #10
0
 def setUp(self):
     self.test_value = metric_value.create(
         labels=self.TEST_LABELS,
         doubleValue=self.A_FLOAT_VALUE)
     self.early_ending = metric_value.create(
         labels=self.TEST_LABELS,
         doubleValue=self.A_FLOAT_VALUE,
         endTime=self.EARLY)
     self.late_ending = metric_value.create(
         labels=self.TEST_LABELS,
         doubleValue=self.A_FLOAT_VALUE,
         endTime=self.LATER)
     self.test_value_with_money = metric_value.create(
         labels=self.TEST_LABELS,
         moneyValue=messages.Money(currencyCode='JPY', units=100, nanos=0))
class TestProducerByConsumerErrorCountWithError(KnownMetricsBase,
                                                unittest2.TestCase):
    SUBJECT = _KNOWN.PRODUCER_BY_CONSUMER_ERROR_COUNT
    GIVEN_INFO = report_request.Info(response_code=401)
    WANTED_ADDED_METRICS = messages.MetricValueSet(
        metricName=SUBJECT.metric_name,
        metricValues=[metric_value.create(int64Value=1)])
예제 #12
0
 def test_should_succeed_for_delta_metrics_with_the_distribution_type(self):
     test_distribution = distribution.create_explicit([0.1, 0.3, 0.5])
     distribution.add_sample(0.4, test_distribution)
     v = metric_value.create(labels=self.TEST_LABELS,
                             distributionValue=test_distribution)
     want = 2 * test_distribution.count
     got = metric_value.merge(MetricKind.DELTA, v, v)
     expect(got.distributionValue.count).to(equal(want))
예제 #13
0
 def test_should_succeed_for_delta_metrics_with_the_distribution_type(self):
     test_distribution = distribution.create_explicit([0.1, 0.3, 0.5])
     distribution.add_sample(0.4, test_distribution)
     v = metric_value.create(labels=self.TEST_LABELS,
                             distributionValue=test_distribution)
     want = 2 * test_distribution.count
     got = metric_value.merge(MetricKind.DELTA, v, v)
     expect(got.distributionValue.count).to(equal(want))
class TestProducerBackendLatencies(KnownMetricsBase, unittest2.TestCase):
    SUBJECT = _KNOWN.PRODUCER_BACKEND_LATENCIES
    WANTED_DISTRIBUTION = _wanted_distribution_with_sample(
        KnownMetricsBase.GIVEN_INFO.backend_time.seconds,
        *metric_descriptor._TIME_DISTRIBUTION_ARGS)
    WANTED_ADDED_METRICS = messages.MetricValueSet(
        metricName=SUBJECT.metric_name,
        metricValues=[
            metric_value.create(distributionValue=WANTED_DISTRIBUTION)
        ])
class TestConsumerTotalLatencies(KnownMetricsBase, unittest2.TestCase):
    SUBJECT = _KNOWN.CONSUMER_TOTAL_LATENCIES
    WANTED_DISTRIBUTION = _wanted_distribution_with_sample(
        KnownMetricsBase.GIVEN_INFO.request_time.seconds,
        *metric_descriptor._TIME_DISTRIBUTION_ARGS)
    WANTED_ADDED_METRICS = messages.MetricValueSet(
        metricName=SUBJECT.metric_name,
        metricValues=[
            metric_value.create(distributionValue=WANTED_DISTRIBUTION)
        ])
class TestProducerErrorCountWithErrors(KnownMetricsBase, unittest2.TestCase):
    SUBJECT = _KNOWN.PRODUCER_ERROR_COUNT
    GIVEN_INFO = report_request.Info(
        response_code=401,
        api_key=KnownMetricsBase.TEST_API_KEY,
        api_key_valid=True,
    )
    WANTED_ADDED_METRICS = messages.MetricValueSet(
        metricName=SUBJECT.metric_name,
        metricValues=[metric_value.create(int64Value=1)])
class TestProducerResponseSizes(KnownMetricsBase, unittest2.TestCase):
    SUBJECT = _KNOWN.PRODUCER_RESPONSE_SIZES
    WANTED_DISTRIBUTION = _wanted_distribution_with_sample(
        KnownMetricsBase.WANTED_SIZE,
        *metric_descriptor._SIZE_DISTRIBUTION_ARGS)
    WANTED_ADDED_METRICS = messages.MetricValueSet(
        metricName=SUBJECT.metric_name,
        metricValues=[
            metric_value.create(distributionValue=WANTED_DISTRIBUTION)
        ])
class TestProducerByConsumerRequestOverheadLatencies(KnownMetricsBase,
                                                     unittest2.TestCase):
    SUBJECT = _KNOWN.PRODUCER_BY_CONSUMER_REQUEST_OVERHEAD_LATENCIES
    WANTED_DISTRIBUTION = _wanted_distribution_with_sample(
        KnownMetricsBase.GIVEN_INFO.overhead_time.seconds,
        *metric_descriptor._TIME_DISTRIBUTION_ARGS)
    WANTED_ADDED_METRICS = messages.MetricValueSet(
        metricName=SUBJECT.metric_name,
        metricValues=[
            metric_value.create(distributionValue=WANTED_DISTRIBUTION)
        ])
예제 #19
0
 def test_should_change_signature_when_metric_values_are_added(self):
     without_mvs = check_request.sign(self.test_check_request)
     self.test_op.metricValueSets = [
         messages.MetricValueSet(metricName='a_float',
                                 metricValues=[
                                     metric_value.create(
                                         labels={
                                             'key1': 'value1',
                                             'key2': 'value2'
                                         },
                                         doubleValue=1.1,
                                     ),
                                 ])
     ]
     with_mvs = check_request.sign(self.test_check_request)
     expect(with_mvs).not_to(equal(without_mvs))
 def test_should_change_signature_when_metric_values_are_added(self):
     without_mvs = check_request.sign(self.test_check_request)
     self.test_op.metricValueSets = [
         messages.MetricValueSet(
             metricName='a_float',
             metricValues=[
                 metric_value.create(
                     labels={
                         'key1': 'value1',
                         'key2': 'value2'
                     },
                     doubleValue=1.1,
                 ),
             ]
         )
     ]
     with_mvs = check_request.sign(self.test_check_request)
     expect(with_mvs).not_to(equal(without_mvs))
     backend_time=_TEST_LATENCY,
     overhead_time=_TEST_LATENCY,
     request_time=_TEST_LATENCY,
     request_size=_TEST_SIZE,
     response_size=_TEST_SIZE,
     service_name=_TEST_SERVICE_NAME,
     api_key=_TEST_API_KEY,
     api_key_valid=True),
  messages.Operation(
      importance=messages.Operation.ImportanceValueValuesEnum.LOW,
      logEntries=[],
      metricValueSets = [
          messages.MetricValueSet(
              metricName=_EXPECTED_OK_METRIC.metric_name,
              metricValues=[
                  metric_value.create(int64Value=1),
              ]
          ),
      ],
      consumerId='api_key:' + _TEST_API_KEY,
      operationId='an_op_id',
      operationName='an_op_name',
      startTime=_START_OF_EPOCH_TIMESTAMP,
      endTime=_START_OF_EPOCH_TIMESTAMP)
 ),
 (report_request.Info(
     response_code=404,
     operation_id='an_op_id',
     operation_name='an_op_name',
     method='GET',
     referer='a_referer',
  messages.Operation(
      importance=messages.Operation.ImportanceValueValuesEnum.LOW,
      logEntries=[],
      labels=encoding.PyValueToMessage(
          messages.Operation.LabelsValue, {
              'servicecontrol.googleapis.com/service_agent':
              _WANTED_SERVICE_AGENT,
              'servicecontrol.googleapis.com/user_agent':
              _WANTED_USER_AGENT,
              'servicecontrol.googleapis.com/platform': _WANTED_PLATFORM,
          }),
      metricValueSets=[
          messages.MetricValueSet(
              metricName=_EXPECTED_OK_METRIC.metric_name,
              metricValues=[
                  metric_value.create(int64Value=1),
              ]),
      ],
      consumerId='api_key:' + _TEST_API_KEY,
      operationId='an_op_id',
      operationName='an_op_name',
      startTime=_START_OF_EPOCH_TIMESTAMP,
      endTime=_START_OF_EPOCH_TIMESTAMP)),
 (report_request.Info(response_code=404,
                      operation_id='an_op_id',
                      operation_name='an_op_name',
                      method='GET',
                      referer='a_referer',
                      backend_time=_TEST_LATENCY,
                      overhead_time=_TEST_LATENCY,
                      request_time=_TEST_LATENCY,
예제 #23
0
 def test_should_fail_for_uninitialized_metric_values(self):
     no_init = metric_value.create()
     for kind in (MetricKind.GAUGE, MetricKind.CUMULATIVE, MetricKind.DELTA):
         testf = lambda: metric_value.merge(kind, no_init, no_init)
         expect(testf).to(raise_error(ValueError))
예제 #24
0
                           messages.LogEntry(textPayload='agg2')
                       ])
}, {
    'description':
    'combines the metric value using the default kind',
    'kinds':
    None,
    'initial':
    messages.Operation(
        startTime=_EARLY,
        endTime=_LATER,
        metricValueSets=[
            messages.MetricValueSet(metricName='some_floats',
                                    metricValues=[
                                        metric_value.create(
                                            labels=_TEST_LABELS,
                                            doubleValue=_A_FLOAT_VALUE,
                                            endTime=_EARLY),
                                    ]),
            messages.MetricValueSet(metricName='other_floats',
                                    metricValues=[
                                        metric_value.create(
                                            labels=_TEST_LABELS,
                                            doubleValue=_A_FLOAT_VALUE,
                                            endTime=_EARLY),
                                    ])
        ]),
    'ops': [
        messages.Operation(startTime=_EARLY,
                           endTime=_LATER,
                           metricValueSets=[
                               messages.MetricValueSet(
예제 #25
0
 def test_should_succeed_for_delta_metrics_with_the_int64_type(self):
     test_int = 4
     v = metric_value.create(labels=self.TEST_LABELS, int64Value=test_int)
     want = 2 * test_int
     got = metric_value.merge(MetricKind.DELTA, v, v)
     expect(got.int64Value).to(equal(want))
예제 #26
0
 def test_should_fail_for_metric_values_with_different_types(self):
     changed = metric_value.create(labels=self.TEST_LABELS, int64Value=1)
     for kind in (MetricKind.GAUGE, MetricKind.CUMULATIVE, MetricKind.DELTA):
         testf = lambda: metric_value.merge(kind, self.test_value, changed)
         expect(testf).to(raise_error(ValueError))
예제 #27
0
 def test_should_fail_for_metric_values_with_different_types(self):
     changed = metric_value.create(labels=self.TEST_LABELS, int64Value=1)
     for kind in (MetricKind.GAUGE, MetricKind.CUMULATIVE,
                  MetricKind.DELTA):
         testf = lambda: metric_value.merge(kind, self.test_value, changed)
         expect(testf).to(raise_error(ValueError))
예제 #28
0
 def test_should_fail_for_uninitialized_metric_values(self):
     no_init = metric_value.create()
     for kind in (MetricKind.GAUGE, MetricKind.CUMULATIVE,
                  MetricKind.DELTA):
         testf = lambda: metric_value.merge(kind, no_init, no_init)
         expect(testf).to(raise_error(ValueError))
예제 #29
0
         ]
     )
 },
 {
     'description': 'combines the metric value using the default kind',
     'kinds': None,
     'initial': messages.Operation(
         startTime=_EARLY,
         endTime=_LATER,
         metricValueSets = [
             messages.MetricValueSet(
                 metricName='some_floats',
                 metricValues=[
                     metric_value.create(
                         labels=_TEST_LABELS,
                         doubleValue=_A_FLOAT_VALUE,
                         endTime=_EARLY
                     ),
                 ]
             ),
             messages.MetricValueSet(
                 metricName='other_floats',
                 metricValues=[
                     metric_value.create(
                         labels=_TEST_LABELS,
                         doubleValue=_A_FLOAT_VALUE,
                         endTime=_EARLY
                     ),
                 ]
             )
         ]
class TestProducerByConsumerRequestCount(KnownMetricsBase, unittest2.TestCase):
    SUBJECT = _KNOWN.PRODUCER_BY_CONSUMER_REQUEST_COUNT
    WANTED_ADDED_METRICS = messages.MetricValueSet(
        metricName=SUBJECT.metric_name,
        metricValues=[metric_value.create(int64Value=1)])
예제 #31
0
 def test_should_succeed_for_delta_metrics_with_the_int64_type(self):
     test_int = 4
     v = metric_value.create(labels=self.TEST_LABELS, int64Value=test_int)
     want = 2 * test_int
     got = metric_value.merge(MetricKind.DELTA, v, v)
     expect(got.int64Value).to(equal(want))