def test_on_rebalance( self, monitor: PrometheusMonitor, metrics: FaustMetrics, app: AppT ) -> None: monitor.on_rebalance_start(app) self.assert_has_sample_value( metrics.total_rebalances, "test_total_rebalances", {}, 1 )
def test_old_labels_are_removed_from_registry_after_rebalance( self, monitor: PrometheusMonitor, metrics: FaustMetrics, registry: CollectorRegistry, stream: StreamT, event: EventT, app: AppT, ) -> None: self._handle_event( monitor=monitor, topic_partition=TP1, stream=stream, event=event, offset=10, ) monitor.on_rebalance_start(app) monitor.on_rebalance_end(app, state={"time_start": monitor.time()}) self._handle_event( monitor=monitor, topic_partition=TP2, stream=stream, event=event, offset=11, ) collected_topics = frozenset( sample.labels["topic"] for metric in registry.collect() if metric.name == "test_messages_received_per_topic" for sample in metric.samples ) assert collected_topics == frozenset([TP2.topic]) collected_partitions = frozenset( (sample.labels["topic"], sample.labels["partition"]) for metric in registry.collect() if metric.name == "test_messages_received_per_topics_partition" for sample in metric.samples ) assert collected_partitions == frozenset([(TP2.topic, str(TP2.partition))])