Skip to content

Commit

Permalink
feat: ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-frolov committed Dec 20, 2024
1 parent c9de6ca commit 2f6abd9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
20 changes: 13 additions & 7 deletions tests/prometheus/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import random
from typing import Optional, Any
from typing import Any, Optional

import pytest
from prometheus_client import CollectorRegistry

from faststream.prometheus.container import MetricsContainer
from faststream.prometheus.manager import MetricsManager
from faststream.prometheus.types import ProcessingStatus, PublishingStatus
from tests.prometheus.utils import get_received_messages_metric, get_received_messages_size_bytes_metric, \
get_received_messages_in_process_metric, get_received_processed_messages_metric, \
get_received_processed_messages_duration_seconds_metric, get_received_processed_messages_exceptions_metric, \
get_published_messages_metric, get_published_messages_duration_seconds_metric, \
get_published_messages_exceptions_metric
from tests.prometheus.utils import (
get_published_messages_duration_seconds_metric,
get_published_messages_exceptions_metric,
get_published_messages_metric,
get_received_messages_in_process_metric,
get_received_messages_metric,
get_received_messages_size_bytes_metric,
get_received_processed_messages_duration_seconds_metric,
get_received_processed_messages_exceptions_metric,
get_received_processed_messages_metric,
)


class TestCaseMetrics:
Expand Down Expand Up @@ -178,7 +184,7 @@ def test_remove_received_message_in_process(
app_name=app_name,
broker=broker,
queue=queue,
messages_amount=messages_amount-1,
messages_amount=messages_amount - 1,
)

manager.add_received_message_in_process(
Expand Down
37 changes: 19 additions & 18 deletions tests/prometheus/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Sequence, cast
from collections.abc import Sequence
from typing import cast

from dirty_equals import IsPositiveFloat, IsStr
from prometheus_client import Histogram, Metric
Expand All @@ -8,12 +9,12 @@


def get_received_messages_metric(
*,
metrics_prefix: str,
app_name: str,
broker: str,
queue: str,
messages_amount: int,
*,
metrics_prefix: str,
app_name: str,
broker: str,
queue: str,
messages_amount: int,
) -> Metric:
metric = Metric(
name=f"{metrics_prefix}_received_messages",
Expand Down Expand Up @@ -51,11 +52,11 @@ def get_received_messages_size_bytes_metric(
size: int,
) -> Metric:
metric = Metric(
name=f"{metrics_prefix}_received_messages_size_bytes",
documentation="Histogram of received messages size in bytes by broker and handler",
unit="",
typ="histogram",
)
name=f"{metrics_prefix}_received_messages_size_bytes",
documentation="Histogram of received messages size in bytes by broker and handler",
unit="",
typ="histogram",
)
metric.samples = [
*[
Sample(
Expand Down Expand Up @@ -99,12 +100,12 @@ def get_received_messages_size_bytes_metric(


def get_received_messages_in_process_metric(
*,
metrics_prefix: str,
app_name: str,
broker: str,
queue: str,
messages_amount: int,
*,
metrics_prefix: str,
app_name: str,
broker: str,
queue: str,
messages_amount: int,
) -> Metric:
metric = Metric(
name=f"{metrics_prefix}_received_messages_in_process",
Expand Down

0 comments on commit 2f6abd9

Please sign in to comment.