
    &`iA                     L    d dl Z d dlmZ d dlmZmZmZmZ  G d d          ZdS )    N)RLock)AnyCallableDictListc                   x    e Zd ZdZd Zdededeeegef         ddfdZd	ed
ede	fdZ
dee         fdZddZdS )EventSummarizerz@Utility that aggregates related log messages to reduce log spam.c                 V    i | _         g | _        i | _        t                      | _        d S )N)events_by_keymessages_to_sendthrottled_messagesr   lock)selfs    |/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/autoscaler/_private/event_summarizer.py__init__zEventSummarizer.__init__	   s-    -/+- 57 GG			    templatequantity	aggregatereturnNc                    | j         5  |                    d          s|dz  }|| j        v r  || j        |         |          | j        |<   n
|| j        |<   ddd           dS # 1 swxY w Y   dS )ay  Add a log message, which will be combined by template.

        Args:
            template: Format string with one placeholder for quantity.
            quantity: Quantity to aggregate.
            aggregate: Aggregation function used to combine the
                quantities. The result is inserted into the template to
                produce the final log message.
        .N)r   endswithr   )r   r   r   r   s       r   addzEventSummarizer.add   s     Y 		8 		8$$S))  C4---/8y&x0(0 0"8,, 08"8,		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8s   AA##A'*A'messagekey
interval_sc                     | j         5  || j        vr8t          j                    |z   | j        |<   | j                            |           ddd           dS # 1 swxY w Y   dS )zAdd a log message, which is throttled once per interval by a key.

        Args:
            message: The message to log.
            key: The key to use to deduplicate the message.
            interval_s: Throttling interval in seconds.
        N)r   r   timer   append)r   r   r   r   s       r   add_once_per_intervalz%EventSummarizer.add_once_per_interval,   s     Y 	6 	6$111/3y{{Z/G',%,,W555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   AAAAc                 
   | j         5  g }| j                                        D ]-\  }}|                    |                    |                     .|                    | j                   ddd           n# 1 swxY w Y   |S )z8Generate the aggregated log summary of all added events.N)r   r   itemsr    formatextendr   )r   outr   r   s       r   summaryzEventSummarizer.summary9   s    Y 	. 	.C&*&8&>&>&@&@ 6 6"(

8??8445555JJt,---		. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.
 
s   A$A88A<?A<c                 B   | j         5  | j                                         | j                                         t	          | j                                                  D ]$\  }}t          j                    |k    r| j        |= %	 ddd           dS # 1 swxY w Y   dS )zClear the events added.N)r   r   clearr   listr   r#   r   )r   kts      r   r)   zEventSummarizer.clearB   s    Y 	3 	3$$&&&!''))) T4::<<== 3 319;;??/23	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s   A>BBB)r   N)__name__
__module____qualname____doc__r   strr   r   r   intr!   r   r'   r)    r   r   r	   r	      s        JJ
 
 
88*-8:BC:s?:S8	8 8 8 8.6S 6s 6 6 6 6 6c    	3 	3 	3 	3 	3 	3r   r	   )	r   	threadingr   typingr   r   r   r   r	   r3   r   r   <module>r6      s           , , , , , , , , , , , ,E3 E3 E3 E3 E3 E3 E3 E3 E3 E3r   