예제 #1
0
class TestAuroraCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('AuroraCollector', {})

        self.collector = AuroraCollector(config, None)

    def test_import(self):
        self.assertTrue(AuroraCollector)

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        def se(url):
            if url == 'http://*****:*****@patch.object(Collector, 'publish')
    def test_should_fail_gracefully(self, publish_mock):
        patch_urlopen = patch(
            'urllib2.urlopen',
            Mock(return_value=self.getFixture('metrics_blank')))

        patch_urlopen.start()
        self.collector.collect()
        patch_urlopen.stop()

        self.assertPublishedMany(publish_mock, {})

    def get_metrics(self):
        return {
            'async.tasks.completed': 11117.0,
            'attribute.store.fetch.all.events': 24.0,
            'attribute.store.fetch.all.events.per.sec': 0.0,
            'attribute.store.fetch.all.nanos.per.event': 0.0,
            'attribute.store.fetch.all.nanos.total': 90208119.0,
            'attribute.store.fetch.all.nanos.total.per.sec': 0.0,
            'attribute.store.fetch.one.events': 33024.0,
            'tasks.FAILED.computers.prod.computer-traffic-analysis': 517.0,
            'tasks.FAILED.reporting.prod.report-processing': 2.0
        }
예제 #2
0
class TestAuroraCollector(CollectorTestCase):

    def setUp(self):
        config = get_collector_config('AuroraCollector', {})

        self.collector = AuroraCollector(config, None)

    def test_import(self):
        self.assertTrue(AuroraCollector)

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        def se(url):
            if url == 'http://*****:*****@patch.object(Collector, 'publish')
    def test_should_fail_gracefully(self, publish_mock):
        patch_urlopen = patch('urllib2.urlopen', Mock(
                              return_value=self.getFixture('metrics_blank')))

        patch_urlopen.start()
        self.collector.collect()
        patch_urlopen.stop()

        self.assertPublishedMany(publish_mock, {})

    def get_metrics(self):
        return {
            'async.tasks.completed': 11117.0,
            'attribute.store.fetch.all.events': 24.0,
            'attribute.store.fetch.all.events.per.sec': 0.0,
            'attribute.store.fetch.all.nanos.per.event': 0.0,
            'attribute.store.fetch.all.nanos.total': 90208119.0,
            'attribute.store.fetch.all.nanos.total.per.sec': 0.0,
            'attribute.store.fetch.one.events': 33024.0,
            'tasks.FAILED.computers.prod.computer-traffic-analysis': 517.0,
            'tasks.FAILED.reporting.prod.report-processing': 2.0
        }
예제 #3
0
    def setUp(self):
        config = get_collector_config('AuroraCollector', {})

        self.collector = AuroraCollector(config, None)
예제 #4
0
    def setUp(self):
        config = get_collector_config('AuroraCollector', {})

        self.collector = AuroraCollector(config, None)
예제 #5
0
    def setUp(self):
        config = get_collector_config('AuroraCollector', {
            'hosts': 'localhost:8081',
        })

        self.collector = AuroraCollector(config, None)
예제 #6
0
class TestAuroraCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('AuroraCollector', {
            'hosts': 'localhost:8081',
        })

        self.collector = AuroraCollector(config, None)

    def test_import(self):
        self.assertTrue(TestAuroraCollector)

    @patch.object(Collector, 'publish')
    def test_cluster_vars(self, publish_mock):
        fixtures = [
            self.getFixture('role_summary'),
            self.getFixture('cluster_vars'),
            self.getFixture('job_summary')
        ]
        patch_urlopen = patch('urllib2.OpenerDirector.open',
                              Mock(side_effect=lambda *args: fixtures.pop(0)))

        patch_urlopen.start()
        self.collector.collect()
        patch_urlopen.stop()

        published_metrics = {
            'schedule_queue_size': 0,
            'scheduler_thrift_createJob_nanos_total': 40390494,
            'task_throttle_events': 258
        }

        self.assertPublishedMany(publish_mock, published_metrics)

        unpublished_metrics = {
            'jvm_prop_java_class_path': 0,
            'system_env_TERM': 0
        }

        self.assertUnpublishedMany(publish_mock, unpublished_metrics)

    @patch.object(Collector, 'publish')
    def test_no_publish_if_inactive(self, publish_mock):
        metrics = {
            'schedule_queue_size': 0,
            'scheduler_thrift_createJob_nanos_total': 40390494,
            'task_throttle_events': 258
        }
        fixtures = [
            self.getFixture('role_summary'),
            StringIO(json.dumps(metrics)),
            self.getFixture('job_summary')
        ]
        patch_urlopen = patch('urllib2.OpenerDirector.open',
                              Mock(side_effect=lambda *args: fixtures.pop(0)))

        patch_urlopen.start()
        self.collector.collect()
        patch_urlopen.stop()

        self.assertUnpublishedMany(publish_mock, metrics)

    @patch.object(Collector, 'publish')
    def test_extract_metric_and_source(self, publish_mock):
        metrics = {
            'tasks_FAILED_test_role/prod/my_job': 103,
            'tasks_LOST_test_role/prod/my_job': 111,
            'sla_test_role/prod/my_job_job_uptime_90.00_sec': 1143469,
            'scheduler_lifecycle_ACTIVE': 1
        }
        fixtures = [
            self.getFixture('role_summary'),
            StringIO(json.dumps(metrics)),
            self.getFixture('job_summary'),
            self.getFixture('role_summary'),
            StringIO(json.dumps(metrics)),
            self.getFixture('job_summary')
        ]
        patch_urlopen = patch('urllib2.OpenerDirector.open',
                              Mock(side_effect=lambda *args: fixtures.pop(0)))

        config = get_collector_config('AuroraCollector', {
            'hosts': 'test@localhost:8081',
        })

        cluster_override_collector = AuroraCollector(config, None)
        collectors = [
            ('test', cluster_override_collector),
            ('general', self.collector)
        ]

        for cluster, collector in collectors:
            patch_urlopen.start()
            collector.collect()
            patch_urlopen.stop()

            published_metrics = {
                'sla_job_job_uptime_90_00_sec':
                    call('sla_job_job_uptime_90_00_sec', 1143469.0,
                         metric_type='GAUGE',
                         source='%s.test_role.prod.my_job' % cluster),
                'job_stats_active_tasks':
                    call('job_stats_active_tasks', 1,
                         metric_type='GAUGE',
                         source='%s.test_role.prod.my_job' % cluster),
                'job_stats_failed_tasks':
                    call('job_stats_failed_tasks', 103,
                         metric_type='COUNTER',
                         source='%s.test_role.prod.my_job' % cluster),
                'job_stats_lost_tasks':
                    call('job_stats_lost_tasks', 111,
                         metric_type='COUNTER',
                         source='%s.test_role.prod.my_job' % cluster),
                'job_resources_total_allocated_cpu':
                    call('job_resources_total_allocated_cpu', 17,
                         metric_type='GAUGE',
                         source='%s.test_role.prod.my_job' % cluster),
                'job_resources_total_allocated_cpu_adjusted':
                    call('job_resources_total_allocated_cpu_adjusted', 17.5,
                         metric_type='GAUGE',
                         source='%s.test_role.prod.my_job' % cluster),
            }

            for k, v in published_metrics.iteritems():
                calls = filter(lambda x: x[0][0] == k,
                               publish_mock.call_args_list)
                self.assertEqual(calls[0] if calls else '', v)
                self.assertEqual(calls[0], v)

            publish_mock.reset_mock()