Пример #1
0
    def test_apply_physical_no_filter(self):
        metrics = DirectMetrics()
        metrics.update_physical(
            object(),
            MetricUpdates(
                counters={
                    MetricKey('step1', self.name1): 5,
                    MetricKey('step1', self.name3): 8
                }))

        metrics.update_physical(
            object(),
            MetricUpdates(
                counters={
                    MetricKey('step2', self.name1): 7,
                    MetricKey('step1', self.name3): 4
                }))
        results = metrics.query()
        hc.assert_that(
            results['counters'],
            hc.contains_inanyorder(*[
                MetricResult(MetricKey('step1', self.name1), 0, 5),
                MetricResult(MetricKey('step1', self.name3), 0, 12),
                MetricResult(MetricKey('step2', self.name1), 0, 7)
            ]))

        metrics.commit_physical(object(), MetricUpdates())
        results = metrics.query()
        hc.assert_that(
            results['counters'],
            hc.contains_inanyorder(*[
                MetricResult(MetricKey('step1', self.name1), 0, 5),
                MetricResult(MetricKey('step1', self.name3), 0, 12),
                MetricResult(MetricKey('step2', self.name1), 0, 7)
            ]))
  def test_apply_physical_no_filter(self):
    metrics = DirectMetrics()
    metrics.update_physical(object(),
                            MetricUpdates(
                                counters={MetricKey('step1', self.name1): 5,
                                          MetricKey('step1', self.name3): 8}))

    metrics.update_physical(object(),
                            MetricUpdates(
                                counters={MetricKey('step2', self.name1): 7,
                                          MetricKey('step1', self.name3): 4}))
    results = metrics.query()
    hc.assert_that(results['counters'],
                   hc.contains_inanyorder(*[
                       MetricResult(MetricKey('step1', self.name1), 0, 5),
                       MetricResult(MetricKey('step1', self.name3), 0, 12),
                       MetricResult(MetricKey('step2', self.name1), 0, 7)]))

    metrics.commit_physical(object(), MetricUpdates())
    results = metrics.query()
    hc.assert_that(results['counters'],
                   hc.contains_inanyorder(*[
                       MetricResult(MetricKey('step1', self.name1), 0, 5),
                       MetricResult(MetricKey('step1', self.name3), 0, 12),
                       MetricResult(MetricKey('step2', self.name1), 0, 7)]))
Пример #3
0
    def test_apply_physical_logical(self):
        metrics = DirectMetrics()
        dist_zero = DistributionData(0, 0, None, None)
        metrics.update_physical(
            object(),
            MetricUpdates(counters={
                MetricKey('step1', self.name1): 7,
                MetricKey('step1', self.name2): 5,
                MetricKey('step2', self.name1): 1
            },
                          distributions={
                              MetricKey('step1', self.name1):
                              DistributionData(3, 1, 3, 3),
                              MetricKey('step2', self.name3):
                              DistributionData(8, 2, 4, 4)
                          }))
        results = metrics.query()
        hc.assert_that(
            results['counters'],
            hc.contains_inanyorder(*[
                MetricResult(MetricKey('step1', self.name1), 0, 7),
                MetricResult(MetricKey('step1', self.name2), 0, 5),
                MetricResult(MetricKey('step2', self.name1), 0, 1)
            ]))
        hc.assert_that(
            results['distributions'],
            hc.contains_inanyorder(*[
                MetricResult(MetricKey('step1', self.name1),
                             DistributionResult(dist_zero),
                             DistributionResult(DistributionData(3, 1, 3, 3))),
                MetricResult(MetricKey('step2', self.name3),
                             DistributionResult(dist_zero),
                             DistributionResult(DistributionData(8, 2, 4, 4)))
            ]))

        metrics.commit_physical(
            object(),
            MetricUpdates(counters={
                MetricKey('step1', self.name1): -3,
                MetricKey('step2', self.name1): -5
            },
                          distributions={
                              MetricKey('step1', self.name1):
                              DistributionData(8, 4, 1, 5),
                              MetricKey('step2', self.name2):
                              DistributionData(8, 8, 1, 1)
                          }))
        results = metrics.query()
        hc.assert_that(
            results['counters'],
            hc.contains_inanyorder(*[
                MetricResult(MetricKey('step1', self.name1), 0, 4),
                MetricResult(MetricKey('step1', self.name2), 0, 5),
                MetricResult(MetricKey('step2', self.name1), 0, -4)
            ]))
        hc.assert_that(
            results['distributions'],
            hc.contains_inanyorder(*[
                MetricResult(MetricKey('step1', self.name1),
                             DistributionResult(dist_zero),
                             DistributionResult(DistributionData(11, 5, 1,
                                                                 5))),
                MetricResult(MetricKey('step2', self.name3),
                             DistributionResult(dist_zero),
                             DistributionResult(DistributionData(8, 2, 4, 4))),
                MetricResult(MetricKey('step2', self.name2),
                             DistributionResult(dist_zero),
                             DistributionResult(DistributionData(8, 8, 1, 1)))
            ]))

        metrics.commit_logical(
            object(),
            MetricUpdates(counters={
                MetricKey('step1', self.name1): 3,
                MetricKey('step1', self.name2): 5,
                MetricKey('step2', self.name1): -3
            },
                          distributions={
                              MetricKey('step1', self.name1):
                              DistributionData(11, 5, 1, 5),
                              MetricKey('step2', self.name2):
                              DistributionData(8, 8, 1, 1),
                              MetricKey('step2', self.name3):
                              DistributionData(4, 1, 4, 4)
                          }))

        results = metrics.query()
        hc.assert_that(
            results['counters'],
            hc.contains_inanyorder(*[
                MetricResult(MetricKey('step1', self.name1), 3, 4),
                MetricResult(MetricKey('step1', self.name2), 5, 5),
                MetricResult(MetricKey('step2', self.name1), -3, -4)
            ]))
        hc.assert_that(
            results['distributions'],
            hc.contains_inanyorder(*[
                MetricResult(MetricKey('step1', self.name1),
                             DistributionResult(DistributionData(11, 5, 1, 5)),
                             DistributionResult(DistributionData(11, 5, 1,
                                                                 5))),
                MetricResult(MetricKey('step2', self.name3),
                             DistributionResult(DistributionData(4, 1, 4, 4)),
                             DistributionResult(DistributionData(8, 2, 4, 4))),
                MetricResult(MetricKey('step2', self.name2),
                             DistributionResult(DistributionData(8, 8, 1, 1)),
                             DistributionResult(DistributionData(8, 8, 1, 1)))
            ]))
  def test_apply_physical_logical(self):
    metrics = DirectMetrics()
    dist_zero = DistributionData(0, 0, None, None)
    metrics.update_physical(
        object(),
        MetricUpdates(
            counters={MetricKey('step1', self.name1): 7,
                      MetricKey('step1', self.name2): 5,
                      MetricKey('step2', self.name1): 1},
            distributions={MetricKey('step1', self.name1):
                           DistributionData(3, 1, 3, 3),
                           MetricKey('step2', self.name3):
                           DistributionData(8, 2, 4, 4)}))
    results = metrics.query()
    hc.assert_that(results['counters'],
                   hc.contains_inanyorder(*[
                       MetricResult(MetricKey('step1', self.name1), 0, 7),
                       MetricResult(MetricKey('step1', self.name2), 0, 5),
                       MetricResult(MetricKey('step2', self.name1), 0, 1)]))
    hc.assert_that(results['distributions'],
                   hc.contains_inanyorder(*[
                       MetricResult(
                           MetricKey('step1', self.name1),
                           DistributionResult(dist_zero),
                           DistributionResult(DistributionData(3, 1, 3, 3))),
                       MetricResult(
                           MetricKey('step2', self.name3),
                           DistributionResult(dist_zero),
                           DistributionResult(DistributionData(8, 2, 4, 4)))]))

    metrics.commit_physical(
        object(),
        MetricUpdates(
            counters={MetricKey('step1', self.name1): -3,
                      MetricKey('step2', self.name1): -5},
            distributions={MetricKey('step1', self.name1):
                           DistributionData(8, 4, 1, 5),
                           MetricKey('step2', self.name2):
                           DistributionData(8, 8, 1, 1)}))
    results = metrics.query()
    hc.assert_that(results['counters'],
                   hc.contains_inanyorder(*[
                       MetricResult(MetricKey('step1', self.name1), 0, 4),
                       MetricResult(MetricKey('step1', self.name2), 0, 5),
                       MetricResult(MetricKey('step2', self.name1), 0, -4)]))
    hc.assert_that(results['distributions'],
                   hc.contains_inanyorder(*[
                       MetricResult(
                           MetricKey('step1', self.name1),
                           DistributionResult(dist_zero),
                           DistributionResult(DistributionData(11, 5, 1, 5))),
                       MetricResult(
                           MetricKey('step2', self.name3),
                           DistributionResult(dist_zero),
                           DistributionResult(DistributionData(8, 2, 4, 4))),
                       MetricResult(
                           MetricKey('step2', self.name2),
                           DistributionResult(dist_zero),
                           DistributionResult(DistributionData(8, 8, 1, 1)))]))

    metrics.commit_logical(
        object(),
        MetricUpdates(
            counters={MetricKey('step1', self.name1): 3,
                      MetricKey('step1', self.name2): 5,
                      MetricKey('step2', self.name1): -3},
            distributions={MetricKey('step1', self.name1):
                           DistributionData(11, 5, 1, 5),
                           MetricKey('step2', self.name2):
                           DistributionData(8, 8, 1, 1),
                           MetricKey('step2', self.name3):
                           DistributionData(4, 1, 4, 4)}))

    results = metrics.query()
    hc.assert_that(results['counters'],
                   hc.contains_inanyorder(*[
                       MetricResult(MetricKey('step1', self.name1), 3, 4),
                       MetricResult(MetricKey('step1', self.name2), 5, 5),
                       MetricResult(MetricKey('step2', self.name1), -3, -4)]))
    hc.assert_that(results['distributions'],
                   hc.contains_inanyorder(*[
                       MetricResult(
                           MetricKey('step1', self.name1),
                           DistributionResult(DistributionData(11, 5, 1, 5)),
                           DistributionResult(DistributionData(11, 5, 1, 5))),
                       MetricResult(
                           MetricKey('step2', self.name3),
                           DistributionResult(DistributionData(4, 1, 4, 4)),
                           DistributionResult(DistributionData(8, 2, 4, 4))),
                       MetricResult(
                           MetricKey('step2', self.name2),
                           DistributionResult(DistributionData(8, 8, 1, 1)),
                           DistributionResult(DistributionData(8, 8, 1, 1)))]))