Skip to content

Feature:Support MultiProcess Collector for PrometheusMiddleWare #2220

Open
@C3EQUALZz

Description

@C3EQUALZz

I encountered a problem that if MultiProcessCollector from prometheus_client is used, then the metrics are simply not collected. Only #TYPE and #HELP appear. I learned from one of the contributers - Roman Frolov - of FastStream that this functionality is missing, he asked me to create a Issue to add this functionality.

It would be cool if you add a flag for Middleware multiprocess=True or something like that.

from typing import Final
from faststream import FastStream
from faststream.kafka import KafkaBroker
from app.settings import Settings, get_settings()

settings: Final[Settings] = get_settings()
registry: Final[CollectorRegistry] = CollectorRegistry()
multiprocess.MultiProcessCollector(registry, path=settings.project_dir / settings.server.multiprocess_dir)

broker: KafkaBroker = KafkaBroker(
            settings.broker.url,
            middlewares=[
                KafkaPrometheusMiddleware(
                    registry=registry,
                    app_name="faststream-some-service",
                    multiprocess=True
                ),
            ]
        )

Environment
Running FastStream 0.5.40 with CPython 3.12 on Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions