From 0f88050859c55ef3ebd8057ccf9c44d43d087095 Mon Sep 17 00:00:00 2001 From: ayazabbas <30928485+ayazabbas@users.noreply.github.com> Date: Mon, 13 May 2024 12:15:44 +0100 Subject: [PATCH] better format DD alert text (#64) * better format DD alert text * poetry version patch * lint fix --- pyproject.toml | 2 +- pyth_observer/check/price_feed.py | 10 +++++----- pyth_observer/check/publisher.py | 8 ++++---- pyth_observer/event.py | 11 +++++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ec2fe86..b9eb2dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ ignore_missing_imports = true [tool.poetry] name = "pyth-observer" -version = "0.2.1" +version = "0.2.2" description = "Alerts and stuff" authors = [] readme = "README.md" diff --git a/pyth_observer/check/price_feed.py b/pyth_observer/check/price_feed.py index 9a421f1..cd8bbb0 100644 --- a/pyth_observer/check/price_feed.py +++ b/pyth_observer/check/price_feed.py @@ -83,7 +83,7 @@ def error_message(self) -> dict: distance = self.__state.latest_block_slot - self.__state.latest_trading_slot return { "msg": f"{self.__state.symbol} is offline (either non-trading/stale). Last update {distance} slots ago.", - "type": "PriceFeedCheck", + "type": "PriceFeedOfflineCheck", "symbol": self.__state.symbol, "latest_trading_slot": self.__state.latest_trading_slot, "block_slot": self.__state.latest_block_slot, @@ -127,7 +127,7 @@ def run(self) -> bool: def error_message(self) -> dict: return { "msg": f"{self.__state.symbol} is too far from Coingecko's price.", - "type": "PriceFeedCheck", + "type": "PriceFeedCoinGeckoCheck", "symbol": self.__state.symbol, "pyth_price": self.__state.price_aggregate, "coingecko_price": self.__state.coingecko_price, @@ -157,7 +157,7 @@ def run(self) -> bool: def error_message(self) -> dict: return { "msg": f"{self.__state.symbol} confidence interval is too low.", - "type": "PriceFeedCheck", + "type": "PriceFeedConfidenceIntervalCheck", "symbol": self.__state.symbol, "confidence_interval": self.__state.confidence_interval_aggregate, } @@ -213,7 +213,7 @@ def error_message(self) -> dict: return { "msg": f"{self.__state.symbol} isn't online at the price service.", - "type": "PriceFeedCheck", + "type": "PriceFeedCrossChainOnlineCheck", "symbol": self.__state.symbol, "last_publish_time": publish_time.format("YYYY-MM-DD HH:mm:ss ZZ"), } @@ -273,7 +273,7 @@ def error_message(self) -> dict: ) return { "msg": f"{self.__state.symbol} is too far at the price service.", - "type": "PriceFeedCheck", + "type": "PriceFeedCrossChainDeviationCheck", "symbol": self.__state.symbol, "price": self.__state.price_aggregate, "price_at_price_service": price, diff --git a/pyth_observer/check/publisher.py b/pyth_observer/check/publisher.py index c85b1c6..41201e8 100644 --- a/pyth_observer/check/publisher.py +++ b/pyth_observer/check/publisher.py @@ -82,7 +82,7 @@ def error_message(self) -> dict: intervals_away = abs(diff / self.__state.confidence_interval_aggregate) return { "msg": f"{self.__state.publisher_name} price is {intervals_away} times away from confidence.", - "type": "PublisherCheck", + "type": "PublisherWithinAggregateConfidenceCheck", "publisher": self.__state.publisher_name, "symbol": self.__state.symbol, "publisher_price": f"{self.__state.price} ± {self.__state.confidence_interval}", @@ -118,7 +118,7 @@ def run(self) -> bool: def error_message(self) -> dict: return { "msg": f"{self.__state.publisher_name} confidence interval is too tight.", - "type": "PublisherCheck", + "type": "PublisherConfidenceIntervalCheck", "publisher": self.__state.publisher_name, "symbol": self.__state.symbol, "price": self.__state.price, @@ -153,7 +153,7 @@ def error_message(self) -> dict: distance = self.__state.latest_block_slot - self.__state.slot return { "msg": f"{self.__state.publisher_name} hasn't published recently for {distance} slots.", - "type": "PublisherCheck", + "type": "PublisherOfflineCheck", "publisher": self.__state.publisher_name, "symbol": self.__state.symbol, "publisher_slot": self.__state.slot, @@ -201,7 +201,7 @@ def error_message(self) -> dict: deviation = (self.ci_adjusted_price_diff() / self.__state.price_aggregate) * 100 return { "msg": f"{self.__state.publisher_name} price is too far from aggregate price.", - "type": "PublisherCheck", + "type": "PublisherPriceCheck", "publisher": self.__state.publisher_name, "symbol": self.__state.symbol, "publisher_price": f"{self.__state.price} ± {self.__state.confidence_interval}", diff --git a/pyth_observer/event.py b/pyth_observer/event.py index beeabee..2987683 100644 --- a/pyth_observer/event.py +++ b/pyth_observer/event.py @@ -1,4 +1,3 @@ -import json import os from typing import Dict, Protocol, TypedDict, cast @@ -39,7 +38,11 @@ def __init__(self, check: Check, context: Context): async def send(self): # Publisher checks expect the key -> name mapping of publishers when # generating the error title/message. - event = self.check.error_message() + event_content = self.check.error_message() + event_title = event_content["msg"] + event_text = "" + for key, value in event_content: + event_text += f"{key}: {value}\n" # An example is: PriceFeedOfflineCheck-Crypto.AAVE/USD aggregation_key = f"{self.check.__class__.__name__}-{self.check.state().symbol}" @@ -51,8 +54,8 @@ async def send(self): event = EventCreateRequest( aggregation_key=aggregation_key, - title=event["msg"], - text=json.dumps(event), + title=event_title, + text=event_text, tags=[ "service:observer", f"network:{self.context['network']}",