Skip to content

Commit 4ba3310

Browse files
authored
feat(reliability) Add flag to disable telegram notifications (#92)
1 parent c5ecb0f commit 4ba3310

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

pyth_observer/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ def __init__(
5555
config: Dict[str, Any],
5656
publishers: Dict[str, Publisher],
5757
coingecko_mapping: Dict[str, Symbol],
58+
disable_telegram: bool = False,
5859
):
5960
self.config = config
60-
self.dispatch = Dispatch(config, publishers)
61+
self.dispatch = Dispatch(config, publishers, disable_telegram)
6162
self.publishers = publishers
6263
self.pyth_client = PythClient(
6364
solana_endpoint=config["network"]["http_endpoint"],
@@ -75,6 +76,7 @@ def __init__(
7576
metrics.set_observer_info(
7677
network=config["network"]["name"],
7778
config=config,
79+
telegram_enabled=not disable_telegram,
7880
)
7981

8082
async def run(self):

pyth_observer/cli.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@
3737
envvar="PROMETHEUS_PORT",
3838
default="9001",
3939
)
40-
def run(config, publishers, coingecko_mapping, prometheus_port):
40+
@click.option(
41+
"--disable-telegram",
42+
help="Disable sending Telegram notifications",
43+
envvar="DISABLE_TELEGRAM",
44+
is_flag=True,
45+
default=False,
46+
)
47+
def run(config, publishers, coingecko_mapping, prometheus_port, disable_telegram):
4148
config_ = yaml.safe_load(open(config, "r"))
4249
# Load publishers YAML file and convert to dictionary of Publisher instances
4350
publishers_raw = yaml.safe_load(open(publishers, "r"))
@@ -54,11 +61,7 @@ def run(config, publishers, coingecko_mapping, prometheus_port):
5461
for publisher in publishers_raw
5562
}
5663
coingecko_mapping_ = yaml.safe_load(open(coingecko_mapping, "r"))
57-
observer = Observer(
58-
config_,
59-
publishers_,
60-
coingecko_mapping_,
61-
)
64+
observer = Observer(config_, publishers_, coingecko_mapping_, disable_telegram)
6265

6366
start_http_server(int(prometheus_port))
6467

pyth_observer/dispatch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ class Dispatch:
2929
notifiers for the checks that failed.
3030
"""
3131

32-
def __init__(self, config, publishers):
32+
def __init__(self, config, publishers, disable_telegram=False):
3333
self.config = config
3434
self.publishers = publishers
35+
self.disable_telegram = disable_telegram
3536
if "ZendutyEvent" in self.config["events"]:
3637
self.open_alerts_file = os.environ["OPEN_ALERTS_FILE"]
3738
self.open_alerts = self.load_alerts()
@@ -67,6 +68,8 @@ async def run(self, states: List[State]):
6768
current_time = datetime.now()
6869
for check in failed_checks:
6970
for event_type in self.config["events"]:
71+
if event_type == "TelegramEvent" and self.disable_telegram:
72+
continue
7073
event: Event = globals()[event_type](check, context)
7174

7275
if event_type in ["ZendutyEvent", "TelegramEvent"]:

pyth_observer/metrics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ def __init__(self, registry: CollectorRegistry = REGISTRY):
148148
registry=registry,
149149
)
150150

151-
def set_observer_info(self, network: str, config: Dict[str, Any]):
151+
def set_observer_info(
152+
self, network: str, config: Dict[str, Any], telegram_enabled: bool = False
153+
):
152154
"""Set static information about the observer instance."""
153155
self.observer_info.info(
154156
{
@@ -163,6 +165,7 @@ def set_observer_info(self, network: str, config: Dict[str, Any]):
163165
)
164166
),
165167
"event_handlers": ",".join(config.get("events", [])),
168+
"telegram_enabled": str(int(telegram_enabled)),
166169
}
167170
)
168171

0 commit comments

Comments
 (0)