예제 #1
0
    def test_aggregate_lifecycle_and_timing(self):
        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)

        lifecycles = Lifecycle.objects.select_related()\
                                      .filter(instance=INSTANCE_ID_1)
        self.assertEqual(len(lifecycles), 1)
        lifecycle = lifecycles[0]
        self.assertOnLifecycle(lifecycle, INSTANCE_ID_1, self.start_raw)

        views.aggregate_lifecycle(self.end_raw)

        lifecycles = Lifecycle.objects.select_related()\
                                      .filter(instance=INSTANCE_ID_1)
        self.assertEqual(len(lifecycles), 1)
        lifecycle = lifecycles[0]
        self.assertOnLifecycle(lifecycle, INSTANCE_ID_1, self.end_raw)

        timings = Timing.objects.select_related()\
                                .filter(lifecycle=lifecycle)
        self.assertEqual(len(lifecycles), 1)
        timing = timings[0]
        expected_diff = self.end_raw.when - self.start_raw.when
        self.assertOnTiming(timing, lifecycle, self.start_raw, self.end_raw,
                            expected_diff)
예제 #2
0
    def test_aggregate_lifecycle_and_timing(self):
        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)

        lifecycles = Lifecycle.objects.select_related()\
                                      .filter(instance=INSTANCE_ID_1)
        self.assertEqual(len(lifecycles), 1)
        lifecycle = lifecycles[0]
        self.assertOnLifecycle(lifecycle, INSTANCE_ID_1, self.start_raw)

        views.aggregate_lifecycle(self.end_raw)

        lifecycles = Lifecycle.objects.select_related()\
                                      .filter(instance=INSTANCE_ID_1)
        self.assertEqual(len(lifecycles), 1)
        lifecycle = lifecycles[0]
        self.assertOnLifecycle(lifecycle, INSTANCE_ID_1, self.end_raw)

        timings = Timing.objects.select_related()\
                                .filter(lifecycle=lifecycle)
        self.assertEqual(len(lifecycles), 1)
        timing = timings[0]
        expected_diff = self.end_raw.when - self.start_raw.when
        self.assertOnTiming(timing, lifecycle, self.start_raw, self.end_raw,
                            expected_diff)
예제 #3
0
    def test_aggregate_lifecycle_and_kpi(self):
        views.aggregate_lifecycle(self.update_raw)

        lifecycles = Lifecycle.objects.select_related()\
                                      .filter(instance=INSTANCE_ID_1)
        self.assertEqual(len(lifecycles), 1)
        lifecycle = lifecycles[0]
        self.assertOnLifecycle(lifecycle, INSTANCE_ID_1, self.update_raw)

        trackers = RequestTracker.objects.filter(request_id=REQUEST_ID_1)
        self.assertEqual(len(trackers), 1)
        tracker = trackers[0]
        self.assertOnTracker(tracker, REQUEST_ID_1, lifecycle,
                             self.update_raw.when)

        views.aggregate_lifecycle(self.start_raw)
        views.aggregate_lifecycle(self.end_raw)

        trackers = RequestTracker.objects.filter(request_id=REQUEST_ID_1)
        self.assertEqual(len(trackers), 1)
        tracker = trackers[0]
        expected_diff = self.end_raw.when-self.update_raw.when
        self.assertOnTracker(tracker, REQUEST_ID_1, lifecycle,
                             self.update_raw.when, expected_diff)
예제 #4
0
    def test_aggregate_lifecycle_and_kpi(self):
        views.aggregate_lifecycle(self.update_raw)

        lifecycles = Lifecycle.objects.select_related()\
                                      .filter(instance=INSTANCE_ID_1)
        self.assertEqual(len(lifecycles), 1)
        lifecycle = lifecycles[0]
        self.assertOnLifecycle(lifecycle, INSTANCE_ID_1, self.update_raw)

        trackers = RequestTracker.objects.filter(request_id=REQUEST_ID_1)
        self.assertEqual(len(trackers), 1)
        tracker = trackers[0]
        self.assertOnTracker(tracker, REQUEST_ID_1, lifecycle,
                             self.update_raw.when)

        views.aggregate_lifecycle(self.start_raw)
        views.aggregate_lifecycle(self.end_raw)

        trackers = RequestTracker.objects.filter(request_id=REQUEST_ID_1)
        self.assertEqual(len(trackers), 1)
        tracker = trackers[0]
        expected_diff = self.end_raw.when - self.update_raw.when
        self.assertOnTracker(tracker, REQUEST_ID_1, lifecycle,
                             self.update_raw.when, expected_diff)
예제 #5
0
    def test_single_instance_multiple_kpi_out_of_order(self):
        when1 = utils.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = utils.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment, when1,
                                      'compute.instance.update',
                                      request_id=REQUEST_ID_2,
                                      host='api', service='api')
        start_raw2 = create_raw(self.deployment, when2,
                                     'compute.instance.resize.start',
                                     request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment, when3,
                                   'compute.instance.resize.end',
                                   old_task='resize',
                                   request_id=REQUEST_ID_2)

        # First action started
        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        # Second action started, first end is late
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)
        # Finally get first end
        views.aggregate_lifecycle(self.end_raw)
        # Second end
        views.aggregate_lifecycle(end_raw2)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 1)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, end_raw2)

        trackers = RequestTracker.objects.all().order_by('id')
        self.assertEqual(len(trackers), 2)
        tracker1 = trackers[0]
        expected_diff1 = self.end_raw.when-self.update_raw.when
        self.assertOnTracker(tracker1, REQUEST_ID_1, lifecycle1,
                             self.update_raw.when, expected_diff1)
        tracker2 = trackers[1]
        expected_diff2 = end_raw2.when-update_raw2.when
        self.assertOnTracker(tracker2, REQUEST_ID_2, lifecycle1,
                             update_raw2.when, expected_diff2)
예제 #6
0
    def test_same_instance_multiple_timings(self):
        when1 = utils.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = utils.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment, when1,
                                      'compute.instance.update',
                                      request_id=REQUEST_ID_2,
                                      host='api', service='api')
        start_raw2 = create_raw(self.deployment, when2,
                                     'compute.instance.resize.start',
                                     request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment, when3,
                                   'compute.instance.resize.end',
                                   old_task='resize',
                                   request_id=REQUEST_ID_2)

        # First action started
        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        # Second action started, first end is late
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)
        # Finally get first end
        views.aggregate_lifecycle(self.end_raw)
        # Second end
        views.aggregate_lifecycle(end_raw2)

        lifecycles = Lifecycle.objects.select_related()\
                                      .filter(instance=INSTANCE_ID_1)
        self.assertEqual(len(lifecycles), 1)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, end_raw2)

        timings = Timing.objects.all().order_by('id')
        self.assertEqual(len(timings), 2)
        timing1 = timings[0]
        expected_diff1 = self.end_raw.when - self.start_raw.when
        self.assertOnTiming(timing1, lifecycle1, self.start_raw, self.end_raw,
                            expected_diff1)
        expected_diff2 = end_raw2.when - start_raw2.when
        timing2 = timings[1]
        self.assertOnTiming(timing2, lifecycle1, start_raw2, end_raw2,
                            expected_diff2)
예제 #7
0
    def test_single_instance_multiple_kpi_out_of_order(self):
        when1 = utils.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = utils.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment,
                                 when1,
                                 'compute.instance.update',
                                 request_id=REQUEST_ID_2,
                                 host='api',
                                 service='api')
        start_raw2 = create_raw(self.deployment,
                                when2,
                                'compute.instance.resize.start',
                                request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment,
                              when3,
                              'compute.instance.resize.end',
                              old_task='resize',
                              request_id=REQUEST_ID_2)

        # First action started
        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        # Second action started, first end is late
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)
        # Finally get first end
        views.aggregate_lifecycle(self.end_raw)
        # Second end
        views.aggregate_lifecycle(end_raw2)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 1)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, end_raw2)

        trackers = RequestTracker.objects.all().order_by('id')
        self.assertEqual(len(trackers), 2)
        tracker1 = trackers[0]
        expected_diff1 = self.end_raw.when - self.update_raw.when
        self.assertOnTracker(tracker1, REQUEST_ID_1, lifecycle1,
                             self.update_raw.when, expected_diff1)
        tracker2 = trackers[1]
        expected_diff2 = end_raw2.when - update_raw2.when
        self.assertOnTracker(tracker2, REQUEST_ID_2, lifecycle1,
                             update_raw2.when, expected_diff2)
예제 #8
0
    def test_same_instance_multiple_timings(self):
        when1 = utils.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = utils.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = utils.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment,
                                 when1,
                                 'compute.instance.update',
                                 request_id=REQUEST_ID_2,
                                 host='api',
                                 service='api')
        start_raw2 = create_raw(self.deployment,
                                when2,
                                'compute.instance.resize.start',
                                request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment,
                              when3,
                              'compute.instance.resize.end',
                              old_task='resize',
                              request_id=REQUEST_ID_2)

        # First action started
        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        # Second action started, first end is late
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)
        # Finally get first end
        views.aggregate_lifecycle(self.end_raw)
        # Second end
        views.aggregate_lifecycle(end_raw2)

        lifecycles = Lifecycle.objects.select_related()\
                                      .filter(instance=INSTANCE_ID_1)
        self.assertEqual(len(lifecycles), 1)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, end_raw2)

        timings = Timing.objects.all().order_by('id')
        self.assertEqual(len(timings), 2)
        timing1 = timings[0]
        expected_diff1 = self.end_raw.when - self.start_raw.when
        self.assertOnTiming(timing1, lifecycle1, self.start_raw, self.end_raw,
                            expected_diff1)
        expected_diff2 = end_raw2.when - start_raw2.when
        timing2 = timings[1]
        self.assertOnTiming(timing2, lifecycle1, start_raw2, end_raw2,
                            expected_diff2)
예제 #9
0
파일: tests.py 프로젝트: hungld/stacktach
    def test_multiple_instance_kpi(self):
        when1 = views.str_time_to_unix('2012-12-21 13:32:50.123')
        when2 = views.str_time_to_unix('2012-12-21 13:34:50.123')
        when3 = views.str_time_to_unix('2012-12-21 13:37:50.124')
        update_raw2 = create_raw(self.deployment, when1,
                                      'compute.instance.update',
                                      instance=INSTANCE_ID_2,
                                      request_id=REQUEST_ID_2,
                                      host='api', service='api')
        start_raw2 = create_raw(self.deployment, when2,
                                     'compute.instance.resize.start',
                                     instance=INSTANCE_ID_2,
                                     request_id=REQUEST_ID_2)
        end_raw2 = create_raw(self.deployment, when3,
                                   'compute.instance.resize.end',
                                   instance=INSTANCE_ID_2,
                                   old_task='resize',
                                   request_id=REQUEST_ID_2)

        views.aggregate_lifecycle(self.update_raw)
        views.aggregate_lifecycle(self.start_raw)
        views.aggregate_lifecycle(self.end_raw)
        views.aggregate_lifecycle(update_raw2)
        views.aggregate_lifecycle(start_raw2)
        views.aggregate_lifecycle(end_raw2)

        lifecycles = Lifecycle.objects.all().order_by('id')
        self.assertEqual(len(lifecycles), 2)
        lifecycle1 = lifecycles[0]
        self.assertOnLifecycle(lifecycle1, INSTANCE_ID_1, self.end_raw)
        lifecycle2 = lifecycles[1]
        self.assertOnLifecycle(lifecycle2, INSTANCE_ID_2, end_raw2)

        trackers = RequestTracker.objects.all().order_by('id')
        self.assertEqual(len(trackers), 2)
        tracker1 = trackers[0]
        expected_diff = self.end_raw.when-self.update_raw.when
        self.assertOnTracker(tracker1, REQUEST_ID_1, lifecycle1,
                             self.update_raw.when, expected_diff)
        tracker2 = trackers[1]
        expected_diff2 = end_raw2.when-update_raw2.when
        self.assertOnTracker(tracker2, REQUEST_ID_2, lifecycle2,
                             update_raw2.when, expected_diff2)