@@ -392,25 +392,51 @@ async def test_faststream_prometheus_uses_injected_registry(broker: RedisBroker,
392392 bootstrapper .teardown ()
393393
394394
395- async def test_faststream_prometheus_is_skipped_without_middleware_or_registry (broker : RedisBroker ) -> None :
396- bootstrap_config = dataclasses . replace (
397- build_faststream_config ( broker = broker ),
398- prometheus_middleware_cls = None ,
399- prometheus_collector_registry = None ,
395+ def test_faststream_prometheus_is_skipped_without_metrics_path (broker : RedisBroker ) -> None :
396+ bootstrap_config = FastStreamConfig (
397+ application = faststream . asgi . AsgiFastStream ( broker ),
398+ prometheus_middleware_cls = RedisPrometheusMiddleware ,
399+ logging_buffer_capacity = 0 ,
400400 )
401401 bootstrapper = FastStreamBootstrapper (bootstrap_config = bootstrap_config )
402402 skipped = dict (bootstrapper .skipped_instruments )
403- assert FastStreamPrometheusInstrument in skipped
404- assert "prometheus_collector_registry" in skipped [ FastStreamPrometheusInstrument ]
403+ assert skipped [ FastStreamPrometheusInstrument ] == "prometheus_metrics_path is empty or not valid"
404+
405405
406+ async def test_faststream_prometheus_serves_the_default_registry (broker : RedisBroker ) -> None :
407+ counter_name = f"default_registry_counter_{ uuid .uuid4 ().hex } _total"
408+ counter = prometheus_client .Counter (counter_name , "Default registry counter" )
409+ counter .inc ()
410+ bootstrap_config = dataclasses .replace (
411+ build_faststream_config (broker = broker ), prometheus_middleware_cls = None , prometheus_collector_registry = None
412+ )
413+ bootstrapper = FastStreamBootstrapper (bootstrap_config = bootstrap_config )
406414 application = bootstrapper .bootstrap ()
407415 try :
416+ instruments = [one for one in bootstrapper .instruments if isinstance (one , FastStreamPrometheusInstrument )]
417+ assert [one .collector_registry for one in instruments ] == [prometheus_client .REGISTRY ]
408418 with TestClient (app = application ) as test_client :
409419 async with TestRedisBroker (broker ):
410420 response = test_client .get (bootstrap_config .prometheus_metrics_path )
411- assert response .status_code == status .HTTP_404_NOT_FOUND
421+ assert response .status_code == status .HTTP_200_OK
422+ assert counter_name .encode () in response .content
423+ assert b"python_info" in response .content
412424 finally :
413425 bootstrapper .teardown ()
426+ prometheus_client .REGISTRY .unregister (counter )
427+
428+
429+ def test_faststream_default_registry_takes_two_brokers_and_a_second_bootstrap () -> None :
430+ for _ in range (2 ):
431+ brokers : list [BrokerUsecase [typing .Any , typing .Any , typing .Any ]] = [RedisBroker (), RedisBroker ()]
432+ bootstrapper = _bootstrap_with_brokers (
433+ brokers , opentelemetry_log_traces = False , opentelemetry_middleware_cls = None
434+ )
435+ try :
436+ for one in brokers :
437+ assert _middleware_types (one ) == [RedisPrometheusMiddleware ]
438+ finally :
439+ bootstrapper .teardown ()
414440
415441
416442def test_faststream_logging_teardown_runs_super_when_broker_write_raises (
0 commit comments