Exemplo n.º 1
0
    def test_on_rebalance_end(self, monitor: PrometheusMonitor,
                              metrics: FaustMetrics, app: AppT) -> None:
        state = {"time_start": 99.2}
        n_rebalances = 12
        metrics.total_rebalances_recovering.set(n_rebalances)

        monitor.on_rebalance_end(app, state)

        self.assert_has_sample_value(
            metrics.total_rebalances_recovering,
            "total_rebalances_recovering",
            {},
            n_rebalances - 1,
        )
        self.assert_has_sample_value(
            metrics.rebalance_done_latency,
            "rebalance_done_latency_sum",
            {},
            monitor.ms_since(state["time_end"]),
        )
Exemplo n.º 2
0
    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))])