def test_collector_collect(self):
        agg = aggregation_module.LastValueAggregation(256)
        view = view_module.View("new_view", "processed video size over time",
                                [FRONTEND_KEY], VIDEO_SIZE_MEASURE, agg)
        registry = mock.Mock()
        view_data = mock.Mock()
        options = prometheus.Options("test2", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options, view_data=view_data)
        collector.register_view(view)
        desc = collector.registered_views[
            'test2_new_view-my.org/keys/frontend']
        collector.to_metric(desc=desc, view=view)

        registry = mock.Mock()
        view_data = mock.Mock()
        options = prometheus.Options("test1", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options, view_data=view_data)
        collector.register_view(VIDEO_SIZE_VIEW)
        desc = collector.registered_views[list(REGISTERED_VIEW)[0]]
        metric = collector.to_metric(desc=desc, view=VIDEO_SIZE_VIEW)

        self.assertEqual(desc['name'], metric.name)
        self.assertEqual(desc['documentation'], metric.documentation)
        self.assertEqual('histogram', metric.type)
        self.assertEqual(5, len(metric.samples))
예제 #2
0
    def test_collector_to_metric_histogram(self):
        registry = mock.Mock()
        options = prometheus.Options("test1", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options)
        collector.register_view(VIDEO_SIZE_VIEW)
        desc = collector.registered_views[list(REGISTERED_VIEW)[0]]
        distribution = copy.deepcopy(VIDEO_SIZE_DISTRIBUTION.aggregation_data)
        distribution.add_sample(280.0 * MiB, None, None)
        metric = collector.to_metric(
            desc=desc,
            tag_values=[tag_value_module.TagValue("ios")],
            agg_data=distribution)

        self.assertEqual(desc['name'], metric.name)
        self.assertEqual(desc['documentation'], metric.documentation)
        self.assertEqual('histogram', metric.type)
        expected_samples = [
            Sample(metric.name + '_bucket',
                   {"myorg_keys_frontend": "ios", "le": str(16.0 * MiB)},
                   0),
            Sample(metric.name + '_bucket',
                   {"myorg_keys_frontend": "ios", "le": str(256.0 * MiB)},
                   0),
            Sample(metric.name + '_bucket',
                   {"myorg_keys_frontend": "ios", "le": "+Inf"},
                   1),
            Sample(metric.name + '_count', {"myorg_keys_frontend": "ios"}, 1),
            Sample(metric.name + '_sum',
                   {"myorg_keys_frontend": "ios"},
                   280.0 * MiB)]
        self.assertEqual(expected_samples, metric.samples)
    def test_collector_register_view(self):
        registry = mock.Mock()
        view_data = mock.Mock()
        options = prometheus.Options("test1", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options, view_data=view_data)
        collector.register_view(VIDEO_SIZE_VIEW)
        collector.collect()

        self.assertEqual(REGISTERED_VIEW, collector.registered_views)
    def test_collector_to_metric_histogram(self):
        registry = mock.Mock()
        view_data = mock.Mock()
        options = prometheus.Options("test1", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options, view_data=view_data)
        collector.register_view(VIDEO_SIZE_VIEW)
        desc = collector.registered_views[list(REGISTERED_VIEW)[0]]
        metric = collector.to_metric(desc=desc, view=VIDEO_SIZE_VIEW)

        self.assertEqual(desc['name'], metric.name)
        self.assertEqual(desc['documentation'], metric.documentation)
        self.assertEqual('histogram', metric.type)
        self.assertEqual(5, len(metric.samples))
    def test_collector_constructor_with_params(self):
        registry = mock.Mock()
        view_data = mock.Mock()
        options = prometheus.Options("test1", 8001, "localhost", registry)
        self.assertEqual(options.namespace, "test1")
        self.assertEqual(options.port, 8001)
        self.assertEqual(options.address, "localhost")
        self.assertEqual(options.registry, registry)

        collector = prometheus.Collector(options=options, view_data=view_data)
        self.assertEqual(options, collector.options)
        self.assertEqual(view_data, collector.view_data)
        self.assertEqual({}, collector.registered_views)
        self.assertEqual(registry, collector.registry)
 def test_collector_add_view_data(self):
     registry = mock.Mock()
     start_time = datetime.utcnow()
     end_time = datetime.utcnow()
     view_data = view_data_module.ViewData(view=VIDEO_SIZE_VIEW,
                                           start_time=start_time,
                                           end_time=end_time)
     options = prometheus.Options("test1", 8001, "localhost", registry)
     collector = prometheus.Collector(options=options, view_data={})
     collector.register_view(VIDEO_SIZE_VIEW)
     collector.add_view_data(view_data)
     v_data = {list(REGISTERED_VIEW)[0]: view_data}
     collector.collect()
     self.assertEqual(v_data, collector.view_data)
예제 #7
0
    def test_collector_to_metric_invalid_dist(self):
        agg = mock.Mock()
        view = view_module.View(VIDEO_SIZE_VIEW_NAME,
                                "processed video size over time",
                                [FRONTEND_KEY], VIDEO_SIZE_MEASURE, agg)
        registry = mock.Mock()
        options = prometheus.Options("test1", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options)
        collector.register_view(view)
        desc = collector.registered_views[list(REGISTERED_VIEW)[0]]

        with self.assertRaisesRegexp(
                ValueError,
                'unsupported aggregation type <class \'mock.mock.Mock\'>'):
            collector.to_metric(desc=desc, tag_values=[], agg_data=agg)
    def test_collector_to_metric_last_value(self):
        agg = aggregation_module.LastValueAggregation(256)
        view = view_module.View(VIDEO_SIZE_VIEW_NAME,
                                "processed video size over time",
                                [FRONTEND_KEY], VIDEO_SIZE_MEASURE, agg)
        registry = mock.Mock()
        view_data = mock.Mock()
        options = prometheus.Options("test1", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options, view_data=view_data)
        collector.register_view(view)
        desc = collector.registered_views[list(REGISTERED_VIEW)[0]]
        metric = collector.to_metric(desc=desc, view=view)

        self.assertEqual(desc['name'], metric.name)
        self.assertEqual(desc['documentation'], metric.documentation)
        self.assertEqual('gauge', metric.type)
        self.assertEqual(1, len(metric.samples))
예제 #9
0
    def test_collector_collect_with_none_label_value(self):
        agg = aggregation_module.LastValueAggregation(256)
        view = view_module.View("new_view", "processed video size over time",
                                [FRONTEND_KEY], VIDEO_SIZE_MEASURE, agg)
        registry = mock.Mock()
        options = prometheus.Options("test3", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options)
        collector.register_view(view)
        desc = collector.registered_views['test3_new_view']
        metric = collector.to_metric(
            desc=desc, tag_values=[None], agg_data=agg.aggregation_data)

        self.assertEqual(1, len(metric.samples))
        sample = metric.samples[0]
        # Sample is a namedtuple
        # ('Sample', ['name', 'labels', 'value', 'timestamp', 'exemplar'])
        label_map = sample[1]
        self.assertEqual({"myorg_keys_frontend": ""}, label_map)
예제 #10
0
    def test_collector_collect(self):
        agg = aggregation_module.LastValueAggregation(256)
        view = view_module.View("new_view", "processed video size over time",
                                [FRONTEND_KEY], VIDEO_SIZE_MEASURE, agg)
        registry = mock.Mock()
        options = prometheus.Options("test2", 8001, "localhost", registry)
        collector = prometheus.Collector(options=options)
        collector.register_view(view)
        desc = collector.registered_views['test2_new_view']
        metric = collector.to_metric(
            desc=desc,
            tag_values=[tag_value_module.TagValue("value")],
            agg_data=agg.aggregation_data)

        self.assertEqual(desc['name'], metric.name)
        self.assertEqual(desc['documentation'], metric.documentation)
        self.assertEqual('gauge', metric.type)
        expected_samples = [
            Sample(metric.name, {"myorg_keys_frontend": "value"}, 256)]
        self.assertEqual(expected_samples, metric.samples)
 def test_collector_constructor(self):
     options = prometheus.Options("test1")
     self.assertEqual(options.namespace, "test1")
     collector = prometheus.Collector(options)
     self.assertEqual(options, collector.options)