o
    `Û·iB  ã                   @   sœ   U d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 dZ
dZeedœZeeeee gef f ed< d	ai Zeeee f ed
< G dd„ deeƒZd	S )é    )ÚEnum)ÚCallableÚDictÚList)ÚRAY_METRIC_CARDINALITY_LEVEL)Ú
MetricTypeÚWorkerIdÚName©ÚtasksÚactorsÚ"HIGH_CARDINALITY_GAUGE_AGGREGATIONNÚ_HIGH_CARDINALITY_LABELSc                
   @   sˆ   e Zd ZdZdZdZdZeddd„ƒZee	j
fded	e	deee gef fd
d„ƒZedee fdd„ƒZededee fdd„ƒZdS )ÚMetricCardinalitya‚  Cardinality level configuration for all Ray metrics (ray_tasks, ray_actors,
    etc.). This configurtion is used to determine whether to globally drop high
    cardinality labels. This is important for high scale clusters that might consist
    thousands of workers, millions of tasks.

    - LEGACY: Keep all labels. This is the default behavior.
    - RECOMMENDED: Drop high cardinality labels. The set of high cardinality labels
    are determined internally by Ray and not exposed to users. Currently, this includes
    the following labels: WorkerId
    - LOW: Same as RECOMMENDED, but also drop the Name label for tasks and actors.
    ÚlegacyÚrecommendedÚlowÚreturnc                   C   s:   t d urt S z	tt ¡ ƒa W t S  ty   tja Y t S w ©N)Ú_CARDINALITY_LEVELr   r   ÚlowerÚ
ValueErrorÚLEGACY© r   r   ú_/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/_private/telemetry/metric_cardinality.pyÚget_cardinality_level'   s   þþz'MetricCardinality.get_cardinality_levelÚmetric_nameÚmetric_typec                 C   s>   |t jt jfv r
tS |t jkrtdƒ‚| tv rt|  S dd„ S )a°  Get the aggregation function for a metric when labels are dropped. This method does not currently support histogram metrics.

        Args:
            metric_name: The name of the metric.
            metric_type: The type of the metric. If provided, Counter and Sum
                metrics always use sum() aggregation.

        Returns:
            A function that takes a list of values and returns the aggregated value.
        z.No Aggregation function for histogram metrics.c                 S   s   | d S )Nr   r   )Úvaluesr   r   r   Ú<lambda>I   s    z<MetricCardinality.get_aggregation_function.<locals>.<lambda>)r   ÚCOUNTERÚSUMÚsumÚ	HISTOGRAMr   r   )r   r   r   r   r   Úget_aggregation_function2   s   
z*MetricCardinality.get_aggregation_functionc                   C   s   t t ¡ ƒS r   )Úlistr   Úkeysr   r   r   r   Úget_high_cardinality_metricsK   s   z.MetricCardinality.get_high_cardinality_metricsc                 C   sl   | t v rt |  S t ¡ }|tjks| t ¡ vrg t | < g S tgt | < |tjkr2| dv r2t |   t¡ t |  S )z@
        Get the high cardinality labels of the metric.
        r
   )	r   r   r   r   r'   ÚWORKER_ID_TAG_KEYÚLOWÚappendÚTASK_OR_ACTOR_NAME_TAG_KEY)r   Úcardinality_levelr   r   r   Ú#get_high_cardinality_labels_to_dropO   s   

z5MetricCardinality.get_high_cardinality_labels_to_dropN)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚRECOMMENDEDr)   Ústaticmethodr   r   ÚGAUGEÚstrr   r   Úfloatr$   r'   r-   r   r   r   r   r      s(    
ÿÿÿþr   )Úenumr   Útypingr   r   r   Úray._private.ray_constantsr   Ú#ray._private.telemetry.metric_typesr   r(   r+   r"   r   r5   r6   Ú__annotations__r   r   r   r   r   r   r   Ú<module>   s    $þ