Skip to content

Commit

Permalink
better format DD alert text (#64)
Browse files Browse the repository at this point in the history
* better format DD alert text

* poetry version patch

* lint fix
  • Loading branch information
ayazabbas authored May 13, 2024
1 parent 74b4a9f commit 0f88050
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions pyth_observer/check/price_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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"),
}
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pyth_observer/check/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}",
Expand Down
11 changes: 7 additions & 4 deletions pyth_observer/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import os
from typing import Dict, Protocol, TypedDict, cast

Expand Down Expand Up @@ -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}"
Expand All @@ -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']}",
Expand Down

0 comments on commit 0f88050

Please sign in to comment.