def test_ungrouped_batcher_process_exists(self): meter = metrics.MeterProvider().get_meter(__name__) batcher = UngroupedBatcher(True) aggregator = CounterAggregator() aggregator2 = CounterAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter, ("environment", ), ) label_set = metrics.LabelSet() _batch_map = {} _batch_map[(metric, label_set)] = aggregator aggregator2.update(1.0) batcher._batch_map = _batch_map record = metrics.Record(metric, label_set, aggregator2) batcher.process(record) self.assertEqual(len(batcher._batch_map), 1) self.assertIsNotNone(batcher._batch_map.get((metric, label_set))) self.assertEqual( batcher._batch_map.get((metric, label_set)).current, 0) self.assertEqual( batcher._batch_map.get((metric, label_set)).checkpoint, 1.0)
def test_finished_collection_stateless(self): meter = metrics.MeterProvider().get_meter(__name__) batcher = UngroupedBatcher(False) aggregator = CounterAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter, ("environment", ), ) aggregator.update(1.0) label_set = metrics.LabelSet() _batch_map = {} _batch_map[(metric, label_set)] = aggregator batcher._batch_map = _batch_map batcher.finished_collection() self.assertEqual(len(batcher._batch_map), 0)
def test_checkpoint_set(self): meter = metrics.MeterProvider().get_meter(__name__) batcher = UngroupedBatcher(True) aggregator = CounterAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter, ("environment", ), ) aggregator.update(1.0) label_set = metrics.LabelSet() _batch_map = {} _batch_map[(metric, label_set)] = aggregator batcher._batch_map = _batch_map records = batcher.checkpoint_set() self.assertEqual(len(records), 1) self.assertEqual(records[0].metric, metric) self.assertEqual(records[0].label_set, label_set) self.assertEqual(records[0].aggregator, aggregator)
def test_ungrouped_batcher_process_not_stateful(self): meter = metrics.MeterProvider().get_meter(__name__) batcher = UngroupedBatcher(True) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter, ("environment", ), ) labels = () _batch_map = {} aggregator.update(1.0) batcher._batch_map = _batch_map record = metrics.Record(metric, labels, aggregator) batcher.process(record) self.assertEqual(len(batcher._batch_map), 1) self.assertIsNotNone(batcher._batch_map.get((metric, labels))) self.assertEqual(batcher._batch_map.get((metric, labels)).current, 0) self.assertEqual( batcher._batch_map.get((metric, labels)).checkpoint, 1.0)