Skip to content

Commit d57a393

Browse files
authored
telegram event noise reduction (#77)
* apply the same notification rules on zd events to tg events * update sample config and version bump * linting
1 parent ab41a4d commit d57a393

File tree

4 files changed

+62
-31
lines changed

4 files changed

+62
-31
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ Event types are configured via environment variables:
3333

3434
- `TelegramEvent`
3535
- `TELEGRAM_BOT_TOKEN` - API token for the Telegram bot
36+
- `OPEN_ALERTS_FILE` - Path to local file used for persisting open alerts
3637

3738
- `ZendutyEvent`
3839
- `ZENDUTY_INTEGRATION_KEY` - Integration key for Zenduty service API integration
3940
- `OPEN_ALERTS_FILE` - Path to local file used for persisting open alerts
4041

41-
### Zenduty Alert Thresholds
42-
- Zenduty alert will fire if a check fails 5 or more times within 5 minutes.
43-
- The alert will be resolved if the check failed < 4 times within 5 minutes.
42+
### Alert Thresholds
43+
- Alert thresholds apply to ZendutyEvent and TelegramEvent (resolution only applies to zenduty)
4444
- Checks run approximately once per minute.
4545
- These thresholds can be overridden per check type in config.yaml
46-
- `zenduty_alert_threshold`: number of failures in 5 minutes >= to this value trigger an alert (default: 5)
47-
- `zenduty_resolution_threshold`: number of failures in 5 minutes <= this value resolve the alert (default: 3)
46+
- `alert_threshold`: number of failures in 5 minutes >= to this value trigger an alert (default: 5)
47+
- `resolution_threshold`: number of failures in 5 minutes <= this value resolve the alert (default: 3)
4848

4949
## Finding the Telegram Group Chat ID
5050

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ignore_missing_imports = true
44

55
[tool.poetry]
66
name = "pyth-observer"
7-
version = "0.2.12"
7+
version = "0.2.13"
88
description = "Alerts and stuff"
99
authors = []
1010
readme = "README.md"

pyth_observer/dispatch.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, config, publishers):
4747
self.open_alerts = self.load_alerts()
4848
# below is used to store events to later send if mutilple failures occur
4949
# events cannot be stored in open_alerts as they are not JSON serializable.
50-
self.zenduty_events = {}
50+
self.delayed_events = {}
5151

5252
def load_alerts(self):
5353
try:
@@ -79,7 +79,7 @@ async def run(self, states: List[State]):
7979
for event_type in self.config["events"]:
8080
event: Event = globals()[event_type](check, context)
8181

82-
if event_type == "ZendutyEvent":
82+
if event_type in ["ZendutyEvent", "TelegramEvent"]:
8383
alert_identifier = self.generate_alert_identifier(check)
8484
alert = self.open_alerts.get(alert_identifier)
8585
if alert is None:
@@ -89,11 +89,12 @@ async def run(self, states: List[State]):
8989
"failures": 1,
9090
"last_window_failures": None,
9191
"sent": False,
92+
"event_type": event_type,
9293
}
9394
else:
9495
alert["failures"] += 1
95-
self.zenduty_events[alert_identifier] = event
96-
continue # Skip sending immediately for ZendutyEvent
96+
self.delayed_events[alert_identifier] = event
97+
continue # Skip sending immediately for ZendutyEvent or TelegramEvent
9798

9899
sent_events.append(event.send())
99100

@@ -177,8 +178,8 @@ async def process_zenduty_events(self, current_time):
177178
for identifier, info in self.open_alerts.items():
178179
self.check_zd_alert_status(identifier, current_time)
179180
check_config = self.config["checks"]["global"][info["type"]]
180-
alert_threshold = check_config.get("zenduty_alert_threshold", 5)
181-
resolution_threshold = check_config.get("zenduty_resolution_threshold", 3)
181+
alert_threshold = check_config.get("alert_threshold", 5)
182+
resolution_threshold = check_config.get("resolution_threshold", 3)
182183
# Resolve the alert if raised and failed < $threshold times in the last 5m window
183184
resolved = False
184185
if (
@@ -187,7 +188,10 @@ async def process_zenduty_events(self, current_time):
187188
):
188189
logger.debug(f"Resolving Zenduty alert {identifier}")
189190
resolved = True
190-
if info["sent"]:
191+
if (
192+
info["sent"]
193+
and info.get("event_type", "ZendutyEvent") == "ZendutyEvent"
194+
):
191195
response = await send_zenduty_alert(
192196
identifier, identifier, resolved=True
193197
)
@@ -208,16 +212,16 @@ async def process_zenduty_events(self, current_time):
208212
logger.debug(f"Raising Zenduty alert {identifier}")
209213
self.open_alerts[identifier]["sent"] = True
210214
self.open_alerts[identifier]["last_alert"] = current_time.isoformat()
211-
event = self.zenduty_events.get(identifier)
215+
event = self.delayed_events.get(identifier)
212216
if event:
213217
to_alert.append(event.send())
214218

215219
await asyncio.gather(*to_alert)
216220
for identifier in to_remove:
217221
if self.open_alerts.get(identifier):
218222
del self.open_alerts[identifier]
219-
if self.zenduty_events.get(identifier):
220-
del self.zenduty_events[identifier]
223+
if self.delayed_events.get(identifier):
224+
del self.delayed_events[identifier]
221225

222226
with open(self.open_alerts_file, "w") as file:
223227
json.dump(self.open_alerts, file)

sample.config.yaml

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
network:
22
name: "pythnet"
3-
http_endpoint: "https://pythnet.rpcpool.com"
4-
ws_endpoint: "wss://pythnet.rpcpool.com"
3+
http_endpoint: "https://api2.pythnet.pyth.network"
4+
ws_endpoint: "wss://api2.pythnet.pyth.network"
55
first_mapping: "AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"
66
crosschain_endpoint: "https://hermes.pyth.network"
77
request_rate_limit: 10
88
request_rate_period: 1
99
events:
10-
# NOTE: Uncomment to enable Datadog metrics, see README.md for datadog credential docs.
11-
# - DatadogEvent
1210
- LogEvent
11+
# - DatadogEvent
1312
# - TelegramEvent
1413
- ZendutyEvent
14+
# Alert thresholds apply to Zenduty and Telegram events
15+
# - Checks run approximately once per minute
16+
# - `alert_threshold`: number of failures within 5 minutes >= to this value trigger an alert (default: 5)
17+
# - `resolution_threshold`: number of failures within 5 minutes <= this value resolve the alert (default: 3)
1518
checks:
1619
global:
1720
# Price feed checks
1821
PriceFeedOfflineCheck:
1922
enable: true
20-
max_slot_distance: 25
23+
max_slot_distance: 120
2124
abandoned_slot_distance: 100000
22-
zenduty_alert_threshold: 3
23-
zenduty_resolution_threshold: 0
25+
alert_threshold: 3
26+
resolution_threshold: 0
2427
PriceFeedCoinGeckoCheck:
2528
enable: true
2629
max_deviation: 5
@@ -46,24 +49,48 @@ checks:
4649
PublisherPriceCheck:
4750
enable: true
4851
max_slot_distance: 25
49-
max_aggregate_distance: 6
50-
zenduty_alert_threshold: 5
51-
zenduty_resolution_threshold: 2
52+
max_aggregate_distance: 5
53+
alert_threshold: 2
54+
resolution_threshold: 1
5255
PublisherStalledCheck:
5356
enable: false
5457
stall_time_limit: 30
55-
abandoned_time_limit: 600
58+
abandoned_time_limit: 300
5659
max_slot_distance: 25
57-
zenduty_alert_threshold: 1
58-
zenduty_resolution_threshold: 0
60+
alert_threshold: 1
61+
resolution_threshold: 0
5962
# Per-symbol config
63+
Crypto.ANC/USD:
64+
PublisherPriceCheck:
65+
enable: true
66+
max_slot_distance: 25
67+
max_aggregate_distance: 50
68+
Crypto.MIR/USD:
69+
PublisherPriceCheck:
70+
enable: true
71+
max_slot_distance: 25
72+
max_aggregate_distance: 25
6073
Crypto.MNGO/USD:
6174
PriceFeedOfflineCheck:
62-
max_slot_distance: 10000
75+
max_slot_distance: 100000
76+
Crypto.SLND/USD:
77+
PriceFeedOfflineCheck:
78+
max_slot_distance: 100000
79+
Crypto.SNY/USD:
80+
PriceFeedOfflineCheck:
81+
max_slot_distance: 100000
82+
Crypto.PORT/USD:
83+
PriceFeedOfflineCheck:
84+
max_slot_distance: 100000
6385
FX.USD/HKD:
6486
PriceFeedOfflineCheck:
6587
max_slot_distance: 10000
88+
Crypto.ZBC/USD:
89+
PublisherPriceCheck:
90+
max_aggregate_distance: 30
6691
Crypto.BTC/USD:
6792
PublisherStalledCheck:
6893
enable: true
69-
stall_time_limit: 60
94+
stall_time_limit: 300 # This will override the global stall_time_limit for Crypto.BTC/USD
95+
abandoned_time_limit: 600 # This will override the global abandoned_time_limit for Crypto.BTC/USD
96+
max_slot_distance: 25

0 commit comments

Comments
 (0)