Exemple #1
0
    def fetch_points(self,
                     metric,
                     time_start,
                     time_end,
                     stage,
                     aggregated=True):
        """See the real Accessor for a description."""
        super(_MemoryAccessor, self).fetch_points(metric, time_start, time_end,
                                                  stage)
        points = self._metric_to_points[(metric.name, stage)]
        rows = []
        for ts in points.irange(time_start, time_end):
            # A row is time_base_ms, time_offset_ms, value, count
            if stage.aggregated():
                row = self.Row(ts * 1000.0, 0, 0, float(points[ts][0]),
                               points[ts][1])
            else:
                row = self.Row0(ts * 1000.0, 0, float(points[ts][0]))
            rows.append(row)

        query_results = [(True, rows)]
        time_start_ms = int(time_start) * 1000
        time_end_ms = int(time_end) * 1000
        return bg_accessor.PointGrouper(
            metric,
            time_start_ms,
            time_end_ms,
            stage,
            query_results,
            aggregated=aggregated,
        )
 def test_basic(self):
     """Test that we can read simple stages."""
     stage = _METRIC.metadata.retention.stage0
     data = [(True, [(0, 0, 1), (0, 1, 2)]), (True, [(0, 2, 3)])]
     results = bg_accessor.PointGrouper(_METRIC, 0, 3600, stage, data)
     expected_results = [(0.0, 1), (1.0, 2), (2.0, 3)]
     self.assertEquals(list(results), expected_results)
 def test_without_aggregating(self):
     """Test that we can merge instead of aggregate a stage."""
     stage0 = _METRIC.metadata.retention.stage0
     stage1 = _METRIC.metadata.retention.stages[1]
     data = [(True, [(0, 0, 1), (0, 1, 2)]), (True, [(0, 2, 3)])]
     results = bg_accessor.PointGrouper(
         _METRIC, 0, 3600, stage1, data, source_stage=stage0, aggregated=False)
     expected_results = [(0.0, 6.0, 3.0)]
     self.assertEquals(list(results), expected_results)
Exemple #4
0
 def test_downsampling(self):
     """Test that we can downsample a stage."""
     stage0 = _METRIC.metadata.retention.stage0
     stage1 = _METRIC.metadata.retention.stages[1]
     data = [(True, [(0, 0, 1), (0, 1, 2)]), (True, [(0, 2, 3)])]
     results = bg_accessor.PointGrouper(
         _METRIC, 0, 3600, stage1, data, source_stage=stage0)
     expected_results = [(0.0, 2.0)]
     self.assertEquals(list(results), expected_results)
 def test_aggregated(self):
     """Test that we can read aggregated stages."""
     stage1 = _METRIC.metadata.retention.stages[1]
     replica0, replica1 = 0xFFFF, 0x0000
     data = [
         (True, [(0, 0, replica0, 1, 1), (0, 1, replica0, 2, 2)]),
         (True, [(0, 1, replica1, 2, 4)])
     ]
     results = bg_accessor.PointGrouper(_METRIC, 0, 86000, stage1, data)
     expected_results = [(0.0, 1.0), (60.0, 0.5)]
     self.assertEquals(list(results), expected_results)