11import asyncio
2+ from enum import StrEnum
23import time
34
45from loguru import logger
1617from 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+
1927class 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