o
    `šju  ã                   @   s   d dl Z G dd„ dƒZdS )é    Nc                   @   sn   e Zd ZdZdZddd„Zedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
dd„ Zdd„ Zdd„ Zdd„ ZdS )Ú
MetricNamea	  
    This class encapsulates a metric's name, logical group and its
    related attributes (tags).

    group, tags parameters can be used to create unique metric names.
    e.g. domainName:type=group,key1=val1,key2=val2

    Usage looks something like this:

        # set up metrics:
        metric_tags = {'client-id': 'producer-1', 'topic': 'topic'}
        metric_config = MetricConfig(tags=metric_tags)

        # metrics is the global repository of metrics and sensors
        metrics = Metrics(metric_config)

        sensor = metrics.sensor('message-sizes')
        metric_name = metrics.metric_name('message-size-avg',
                                          'producer-metrics',
                                          'average message size')
        sensor.add(metric_name, Avg())

        metric_name = metrics.metric_name('message-size-max',
        sensor.add(metric_name, Max())

        tags = {'client-id': 'my-client', 'topic': 'my-topic'}
        metric_name = metrics.metric_name('message-size-min',
                                          'producer-metrics',
                                          'message minimum size', tags)
        sensor.add(metric_name, Min())

        # as messages are sent we record the sizes
        sensor.record(message_size)
    )Ú_nameÚ_groupÚ_descriptionÚ_tagsÚ_hashNc                 C   sR   |r|st dƒ‚|durt|tƒst dƒ‚|| _|| _|| _t |¡| _d| _dS )ay  
        Arguments:
            name (str): The name of the metric.
            group (str): The logical group name of the metrics to which this
                metric belongs.
            description (str, optional): A human-readable description to
                include in the metric.
            tags (dict, optional): Additional key/val attributes of the metric.
        z!name and group must be non-empty.Nztags must be a dict if present.r   )	Ú
ValueErrorÚ
isinstanceÚdictr   r   r   Úcopyr   r   )ÚselfÚnameÚgroupÚdescriptionÚtags© r   úW/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/kafka/metrics/metric_name.pyÚ__init__)   s   

zMetricName.__init__c                 C   ó   | j S ©N)r   ©r   r   r   r   r   >   ó   zMetricName.namec                 C   r   r   )r   r   r   r   r   r   B   r   zMetricName.groupc                 C   r   r   )r   r   r   r   r   r   F   r   zMetricName.descriptionc                 C   s   t   | j¡S r   )r   r   r   r   r   r   r   J   s   zMetricName.tagsc                 C   sn   | j dkr| j S d}d}|| t| jƒ }|| t| jƒ }| jr*tt| j ¡ ƒƒnd}|| | }|| _ |S )Nr   é   é   )r   Úhashr   r   r   Ú	frozensetÚitems)r   ÚprimeÚresultÚ	tags_hashr   r   r   Ú__hash__N   s   
zMetricName.__hash__c                 C   sJ   | |u rdS |d u rdS t | t|ƒƒo$| j|jko$| j|jko$| j|jkS )NTF)r	   Útyper   r   r   ©r   Úotherr   r   r   Ú__eq__Z   s   
ÿ
þ
ýzMetricName.__eq__c                 C   s   |   |¡ S r   )r$   r"   r   r   r   Ú__ne__d   s   zMetricName.__ne__c                 C   s   d| j | j| j| jf S )Nz6MetricName(name=%s, group=%s, description=%s, tags=%s))r   r   r   r   r   r   r   r   Ú__str__g   s   ÿzMetricName.__str__)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   Úpropertyr   r   r   r   r    r$   r%   r&   r   r   r   r   r      s     "





r   )r   r   r   r   r   r   Ú<module>   s    