From 9cfeb54c6aad2e845a9ab5748f7a7186e06a6919 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Tue, 19 Apr 2022 22:59:31 +0200 Subject: [PATCH] use custom retry strategy for bad network --- logs/AppLogging.py | 2 +- logs/LogSender.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/logs/AppLogging.py b/logs/AppLogging.py index f4e8640..0842f84 100644 --- a/logs/AppLogging.py +++ b/logs/AppLogging.py @@ -9,4 +9,4 @@ def init_logger(): filemode='a', format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', - level=logging.DEBUG) + level=logging.INFO) diff --git a/logs/LogSender.py b/logs/LogSender.py index 7aa23cb..4ca7521 100644 --- a/logs/LogSender.py +++ b/logs/LogSender.py @@ -30,12 +30,44 @@ LOG_APPOINTMENT_TIMEOUT = "TIMEOUT" LOG_APPOINTMENT_CONTACT_NOT_FOUND = "CONTACT_NOT_FOUND" LOG_APPOINTMENT_SUCCESS = "SUCCESS" +custom_retry_strategy = oci.retry.RetryStrategyBuilder( + # Make up to 10 service calls + max_attempts_check=True, + max_attempts=10, + + # Don't exceed a total of 600 seconds for all service calls + total_elapsed_time_check=True, + total_elapsed_time_seconds=600, + + # Wait 45 seconds between attempts + retry_max_wait_between_calls_seconds=45, + + # Use 2 seconds as the base number for doing sleep time calculations + retry_base_sleep_time_seconds=2, + + # Retry on certain service errors: + # + # - 5xx code received for the request + # - Any 429 (this is signified by the empty array in the retry config) + # - 400s where the code is QuotaExceeded or LimitExceeded + service_error_check=True, + service_error_retry_on_any_5xx=True, + service_error_retry_config={ + 400: ['QuotaExceeded', 'LimitExceeded'], + 429: [] + }, + + # Use exponential backoff and retry with full jitter, but on throttles use + # exponential backoff and retry with equal jitter + backoff_type=oci.retry.BACKOFF_FULL_JITTER_EQUAL_ON_THROTTLE_VALUE +).get_retry_strategy() + class LogSender: def __init__(self): self._config = oci.config.from_file("~/.oci/logger_config_appointment") self._identity = oci.identity.IdentityClient(self._config) - self._loggingingestion_client = LoggingClient(self._config,timeout=60.0) + self._loggingingestion_client = LoggingClient(self._config, timeout=60.0, retry_strategy=custom_retry_strategy) def send_appoint_result(self, result: ReserveResultPojo): if result.type == PublishType.SUCCESS: