def test_summary(self):
   transformer = SpectatorMetricTransformer({}, {})
   rule = TransformationRule(
       transformer,
       {
           'rename': 'NewName',
           'kind': 'Summary',
           'tags': ['status'],
       })
   builder = AggregatedMetricsBuilder(rule)
   for measurement in self._make_timer_measurements():
     builder.add(measurement['values'][0], measurement['tags'])
   self.assertEquals(
       [{
           'values': [{'v': {'count': 123, 'totalTime': 321},
                       't': self.TIMESTAMP}],
           'tags': [{'key': 'status', 'value': '2xx'}]
       }],
       sorted(builder.build())
   )
 def test_summary_summarize(self):
   options = {'summarize_compound_kinds': True}
   transformer = SpectatorMetricTransformer(options, {})
   rule = TransformationRule(
       transformer,
       {
           'rename': 'NewName',
           'kind': 'DistributionSummary',
           'tags': ['status'],
       })
   builder = AggregatedMetricsBuilder(rule)
   for measurement in self._make_timer_measurements():
     builder.add(measurement['values'][0], measurement['tags'])
   self.assertEquals(
       [{
           'values': [{'v': {'count': 123, 'totalTime': 321},
                       't': self.TIMESTAMP}],
           'tags': [{'key': 'status', 'value': '2xx'}]
       }],
       sort_dictionaries(builder.build())
   )
 def test_summary_as_is(self):
   options = {}
   transformer = SpectatorMetricTransformer(options, {})
   rule = TransformationRule(
       transformer,
       {
           'rename': 'NewName',
           'kind': 'DistributionSummary',
           'tags': ['status'],
       })
   builder = AggregatedMetricsBuilder(rule)
   self.do_test_compound_kind_as_is(builder)
    def _make_simple_rule_builder(self, options=None):
        # transformer isnt used for these tests, but is required to construct
        options = options or {}
        transformer = SpectatorMetricTransformer(options, {})

        rule = TransformationRule(transformer, {
            'rename': 'NewName',
            'kind': 'Timer',
            'tags': ['status'],
        })
        # The builder only uses the kind part of the rule.
        # The other parts of the rule are used when it is applied
        # to preprocess the response before adding to the builder.
        return AggregatedMetricsBuilder(rule)