Skip to content

Commit 30096fb

Browse files
committed
cleanup, add symbol label to update attempts
1 parent 0e0e72c commit 30096fb

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

apps/hip-3-pusher/src/pusher/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _init_metrics(self):
2626
name="hip_3_relayer_last_published_time",
2727
description="Time of last successful oracle update",
2828
)
29-
# labels: dex, status, error_reason
29+
# labels: dex, symbol, status, error_reason
3030
self.update_attempts_total = self.meter.create_counter(
3131
name="hip_3_relayer_update_attempts_total",
3232
description="Number of update attempts",

apps/hip-3-pusher/src/pusher/publisher.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from enum import StrEnum
23
import time
34

45
from loguru import logger
@@ -16,6 +17,13 @@
1617
from pusher.price_state import PriceState
1718

1819

20+
class PushErrorReason(StrEnum):
21+
RATE_LIMIT = "rate_limit"
22+
USER_LIMIT = "user_limit"
23+
INTERNAL_ERROR = "internal_error"
24+
UNKNOWN = "unknown"
25+
26+
1927
class Publisher:
2028
"""
2129
HIP-3 oracle publisher handler
@@ -106,7 +114,7 @@ def publish(self):
106114
pass
107115
except Exception as e:
108116
logger.exception("Unexpected exception in push request: {}", repr(e))
109-
self._update_attempts_total("error", "internal_error")
117+
self._update_attempts_total("error", PushErrorReason.INTERNAL_ERROR, list(oracle_pxs.keys()))
110118
else:
111119
logger.debug("push disabled")
112120

@@ -130,7 +138,7 @@ def _handle_response(self, response, symbols: list[str]):
130138
logger.debug("oracle update response: {}", response)
131139
status = response.get("status")
132140
if status == "ok":
133-
self._update_attempts_total("success")
141+
self._update_attempts_total("success", None, symbols)
134142
time_secs = int(time.time())
135143

136144
# update last publish time for each symbol in dex
@@ -139,7 +147,7 @@ def _handle_response(self, response, symbols: list[str]):
139147
self.metrics.last_pushed_time.set(time_secs, labels)
140148
elif status == "err":
141149
error_reason = self._get_error_reason(response)
142-
self._update_attempts_total("error", error_reason)
150+
self._update_attempts_total("error", error_reason, symbols)
143151
if error_reason != "rate_limit":
144152
logger.error("Error response: {}", response)
145153

@@ -190,24 +198,26 @@ def _send_single_multisig_update(self, exchange, oracle_pxs, all_mark_pxs, exter
190198
)]
191199
return exchange.multi_sig(self.multisig_address, action, signatures, timestamp)
192200

193-
def _update_attempts_total(self, status: str, error_reason: str | None=None):
201+
def _update_attempts_total(self, status: str, error_reason: str | None, symbols: list[str]):
194202
labels = {**self.metrics_labels, "status": status}
195203
if error_reason:
196204
# don't flag rate limiting as this is expected with redundancy
197205
if error_reason == "rate_limit":
198206
return
199207
labels["error_reason"] = error_reason
200208

201-
self.metrics.update_attempts_total.add(1, labels)
209+
for symbol in symbols:
210+
labels["symbol"] = symbol
211+
self.metrics.update_attempts_total.add(1, labels)
202212

203213
def _get_error_reason(self, response):
204214
response = response.get("response")
205215
if not response:
206216
return None
207217
elif "Oracle price update too often" in response:
208-
return "rate_limit"
218+
return PushErrorReason.RATE_LIMIT
209219
elif "Too many cumulative requests" in response:
210-
return "user_limit"
220+
return PushErrorReason.USER_LIMIT
211221
else:
212222
logger.warning("Unrecognized error response: {}", response)
213-
return "unknown"
223+
return PushErrorReason.UNKNOWN

0 commit comments

Comments
 (0)