def test_add_metrics(self):
        test_context = TestContext()
        registry = Registry()
        reporter = test_context.get_workload_manager()
        reporter.set_registry(registry, {})

        workload = get_test_workload(uuid.uuid4(), 2, STATIC)
        reporter.add_workload(workload)
        reporter.report_metrics({})

        self.assertTrue(gauge_value_equals(registry, RUNNING, 1))
        self.assertTrue(counter_value_equals(registry, ADDED_KEY, 1))
        self.assertTrue(counter_value_equals(registry, REMOVED_KEY, 0))
        self.assertTrue(counter_value_equals(registry, SUCCEEDED_KEY, 1))
        self.assertTrue(counter_value_equals(registry, FAILED_KEY, 0))
        self.assertTrue(gauge_value_equals(registry, WORKLOAD_COUNT_KEY, 1))
        self.assertTrue(gauge_value_equals(registry, PACKAGE_VIOLATIONS_KEY,
                                           0))
        self.assertTrue(gauge_value_equals(registry, CORE_VIOLATIONS_KEY, 0))
        self.assertTrue(
            gauge_value_equals(registry, IP_ALLOCATOR_TIMEBOUND_COUNT, 0))
        self.assertTrue(
            gauge_value_equals(registry, ALLOCATED_SIZE_KEY,
                               workload.get_thread_count()))

        expected_unallocated_size = len(test_context.get_cpu().get_threads()
                                        ) - workload.get_thread_count()
        self.assertTrue(
            gauge_value_equals(registry, UNALLOCATED_SIZE_KEY,
                               expected_unallocated_size))
Esempio n. 2
0
    def test_absent_workload_type_label(self):
        registry = Registry()
        test_context = TestContext()
        name = str(uuid.uuid4())
        unknown_event = get_event(CONTAINER, START, name, {NAME: name})
        event_handlers = test_context.get_event_handlers()
        event_iterable = MockEventProvider([unknown_event])
        manager = EventManager(event_iterable, event_handlers,
                               DEFAULT_TEST_EVENT_TIMEOUT_SECS)
        manager.set_registry(registry, {})
        manager.start_processing_events()

        wait_until(lambda: test_context.get_create_event_handler().
                   get_ignored_event_count() == 1)
        self.assertEqual(0, manager.get_queue_depth())

        manager.stop_processing_events()

        manager.report_metrics({})
        self.assertTrue(gauge_value_equals(registry, QUEUE_DEPTH_KEY, 0))
        self.assertTrue(
            counter_value_equals(registry, EVENT_SUCCEEDED_KEY,
                                 len(test_context.get_event_handlers())))
        self.assertTrue(counter_value_equals(registry, EVENT_FAILED_KEY, 0))
        self.assertTrue(counter_value_equals(registry, EVENT_PROCESSED_KEY, 1))
Esempio n. 3
0
    def test_free_cpu_on_container_die(self):
        registry = Registry()
        test_pod = get_simple_test_pod()
        get_pod_manager().set_pod(test_pod)
        workload_name = test_pod.metadata.name

        events = [
            get_container_create_event(DEFAULT_CPU_COUNT, STATIC,
                                       workload_name, workload_name),
            get_container_die_event(workload_name)
        ]
        event_count = len(events)
        event_iterable = MockEventProvider(
            events, 1)  # Force in order event processing for the test

        test_context = TestContext()
        manager = EventManager(event_iterable,
                               test_context.get_event_handlers(),
                               DEFAULT_TEST_EVENT_TIMEOUT_SECS)
        manager.set_registry(registry, {})
        manager.start_processing_events()

        wait_until(lambda: event_count == manager.get_processed_count())
        self.assertEqual(0, manager.get_queue_depth())
        self.assertEqual(DEFAULT_TOTAL_THREAD_COUNT,
                         len(test_context.get_cpu().get_empty_threads()))
        self.assertEqual(
            1,
            test_context.get_create_event_handler().get_handled_event_count())
        self.assertEqual(
            1,
            test_context.get_free_event_handler().get_handled_event_count())

        manager.stop_processing_events()

        manager.report_metrics({})
        self.assertTrue(gauge_value_equals(registry, QUEUE_DEPTH_KEY, 0))
        self.assertTrue(
            counter_value_equals(
                registry, EVENT_SUCCEEDED_KEY,
                event_count * len(test_context.get_event_handlers())))
        self.assertTrue(counter_value_equals(registry, EVENT_FAILED_KEY, 0))
        self.assertTrue(
            counter_value_equals(registry, EVENT_PROCESSED_KEY, event_count))
Esempio n. 4
0
    def test_rebalance(self):
        registry = Registry()

        events = [REBALANCE_EVENT]
        event_count = len(events)
        event_iterable = MockEventProvider(events)

        test_context = TestContext()
        manager = EventManager(event_iterable,
                               test_context.get_event_handlers(),
                               DEFAULT_TEST_EVENT_TIMEOUT_SECS)
        manager.set_registry(registry, {})
        manager.start_processing_events()

        wait_until(lambda: event_count == manager.get_processed_count())
        self.assertEqual(0, manager.get_queue_depth())
        self.assertEqual(DEFAULT_TOTAL_THREAD_COUNT,
                         len(test_context.get_cpu().get_empty_threads()))
        self.assertEqual(
            0,
            test_context.get_create_event_handler().get_handled_event_count())
        self.assertEqual(
            0,
            test_context.get_free_event_handler().get_handled_event_count())
        self.assertEqual(
            1,
            test_context.get_rebalance_event_handler().get_handled_event_count(
            ))

        manager.stop_processing_events()

        manager.report_metrics({})
        self.assertTrue(gauge_value_equals(registry, QUEUE_DEPTH_KEY, 0))
        self.assertTrue(
            counter_value_equals(
                registry, EVENT_SUCCEEDED_KEY,
                event_count * len(test_context.get_event_handlers())))
        self.assertTrue(counter_value_equals(registry, EVENT_FAILED_KEY, 0))
        self.assertTrue(
            counter_value_equals(registry, EVENT_PROCESSED_KEY, event_count))
    def test_empty_metrics(self):
        test_context = TestContext()
        registry = Registry()
        reporter = test_context.get_workload_manager()
        reporter.set_registry(registry, {})
        reporter.report_metrics({})

        self.assertTrue(gauge_value_equals(registry, RUNNING, 1))
        self.assertTrue(counter_value_equals(registry, ADDED_KEY, 0))
        self.assertTrue(counter_value_equals(registry, REMOVED_KEY, 0))
        self.assertTrue(counter_value_equals(registry, SUCCEEDED_KEY, 0))
        self.assertTrue(counter_value_equals(registry, FAILED_KEY, 0))
        self.assertTrue(gauge_value_equals(registry, WORKLOAD_COUNT_KEY, 0))
        self.assertTrue(gauge_value_equals(registry, PACKAGE_VIOLATIONS_KEY,
                                           0))
        self.assertTrue(gauge_value_equals(registry, CORE_VIOLATIONS_KEY, 0))
        self.assertTrue(
            gauge_value_equals(registry, IP_ALLOCATOR_TIMEBOUND_COUNT, 0))
        self.assertTrue(gauge_value_equals(registry, ALLOCATED_SIZE_KEY, 0))
        self.assertTrue(
            gauge_value_equals(registry, UNALLOCATED_SIZE_KEY,
                               len(test_context.get_cpu().get_threads())))