
    ֞ix                       U d Z ddlmZ ddlmZmZ ddlmZmZ 	 ddl	m
Z
mZ ddlmZ dZdd
Zd	Zded<   d	Zded<   er< e       Zej)                  d      dd       Z e
ddd      Zej-                  e       y	y	# e$ r dZd	Z
d	Zd	ZY `w xY w)u2  
api/metrics_endpoint.py

Prometheus metrics HTTP endpoint for the Genesis API.

Exposes GET /metrics in Prometheus text exposition format so that a Prometheus
scraper (or ``infra/monitoring/prometheus.yml``) can collect Genesis platform
metrics.

Can be used in two ways:

1. Standalone FastAPI app (for testing or dedicated metrics server):
   ::
       uvicorn api.metrics_endpoint:app --port 8000

2. Mounted on an existing FastAPI application:
   ::
       from api.metrics_endpoint import metrics_router
       existing_app.include_router(metrics_router)

Falls back gracefully when ``fastapi`` is not installed — the module still
imports cleanly and ``expose_metrics_text()`` remains callable.

VERIFICATION_STAMP
Story: MON-005
Verified By: parallel-builder
Verified At: 2026-02-25
Tests: 7/7
Coverage: 100%
    )annotations)AnyOptional)expose_metricsCONTENT_TYPE_LATEST)FastAPIResponse)	APIRouterTFNc                     t               S )z9Return current Genesis metrics in Prometheus text format.)r        -/mnt/e/genesis-system/api/metrics_endpoint.pyexpose_metrics_textr   <   s    r   zOptional[Any]metrics_routerappz/metricsc                 0    t               } t        | d      S )z
        GET /metrics

        Returns Prometheus text exposition format consumed by Prometheus
        scrapers.  Content-Type matches the Prometheus specification.
        z(text/plain; version=0.0.4; charset=utf-8)content
media_type)r   r	   )r   s    r   get_metrics_endpointr   K   s     &'A
 	
r   zGenesis Metricsz2Prometheus metrics endpoint for the Genesis stack.z1.0.0)titledescriptionversion)returnstr)r   r	   )__doc__
__future__r   typingr   r   core.observability.metricsr   r   fastapir   r	   fastapi.routingr
   _FASTAPI_AVAILABLEImportErrorr   r   __annotations__r   getr   include_routerr   r   r   <module>r&      s   > #  
 K
)) !% $] [N
#
 $
 HC
 ~&/ 1  GHI	s   A< <BB