Source code for luna_sender.app.monitoring.points

"""
Points. For monitoring events in the redis context
"""
from typing import Optional

from crutches_on_wheels.cow.monitoring.points import BaseMonitoringPoint


[docs] class BaseSenderMonitoringPoint(BaseMonitoringPoint): """ Base point for Sender messages monitoring """ #: service name service: str
[docs] @classmethod def initialize(cls, serviceName: str): """ Initialize Args: serviceName: service name """ cls.service = serviceName
[docs] class WSRequestPoint(BaseSenderMonitoringPoint): """ Point for monitoring sending message to ws Attributes: accountId (str): account id requestId (str): request id from luna transportTime (float): time between getting message from redis and sending it to a ws (seconds) """ #: series series = "ws_requests" __slots__ = ("requestId", "accountId", "transportTime") def __init__(self, eventTime: float, requestId: str, transportTime: float, accountId: str): super().__init__(eventTime) self.accountId = accountId self.requestId = requestId self.transportTime = transportTime @property def tags(self) -> dict: """ Get point tags Returns: dict with account id and service as keys """ return {"account_id": self.accountId, "service": self.service} @property def fields(self) -> dict: """ Get point fields Returns: dict with request id id and transport time as keys """ return {"transport_time": self.transportTime, "request_id": self.requestId}
[docs] class SubscribeRedisPoint(BaseSenderMonitoringPoint): """ Point for monitoring receiving message from redis Attributes: requestId (str): request id from luna chanel (str): redis chanel ('{chane name}:{account id}') """ #: series series = "redis_message" __slots__ = ("requestId", "chanel") def __init__(self, requestId: str, chanel: str, eventTime: float): super().__init__(eventTime) self.requestId = requestId self.chanel = chanel @property def tags(self) -> dict: """ Get point tags Returns: dict with chanel and service as keys """ return {"service": self.service, "chanel": self.chanel} @property def fields(self) -> dict: """ Get point fields Returns: dict with request id id as keys """ return {"request_id": self.requestId}
[docs] class ErrorPoint(BaseSenderMonitoringPoint): """ Point for monitoring errors of processing messages from redis or connecting to redis Attributes: additionalTags (dict): additional tags for point errorCode (str): error code additionalFields (dict): additional fields for point """ #: series series = "subscription_error" __slots__ = ("errorCode", "additionalTags", "additionalFields") def __init__( self, eventTime: float, errorCode: int, additionalTags: Optional[dict] = None, additionalFields: Optional[dict] = None, ): super().__init__(eventTime) self.additionalTags = additionalTags if additionalTags is not None else {} self.additionalFields = additionalFields if additionalFields is not None else {} self.errorCode = errorCode @property def tags(self) -> dict: """ Get point tags Returns: dict with service as keys + additionalTags """ baseTags = {"service": self.service, "error_code": self.errorCode} baseTags.update(self.additionalTags) return baseTags @property def fields(self) -> dict: """ Get point fields Returns: dict with additional fields """ baseFields = {} baseFields.update(self.additionalFields) return baseFields