Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conf: stat_manager #4135

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions source/jormungandr/jormungandr/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,33 @@
STAT_CIRCUIT_BREAKER_TIMEOUT_S = int(os.getenv('JORMUNGANDR_STAT_CIRCUIT_BREAKER_TIMEOUT_S', 60))

default_stat_connection_retry_policy = {
# First retry immediately
'interval_start': 0,
# then increase by 1s for every retry
'interval_step': 1,
# but don't exceed 1s between retries.
'interval_max': 1,
# give up after 5 tries.
'max_retries': 5,
'timeout': 1,
}

STAT_CONNECTION_RETRY_POLICY = (
json.loads(os.getenv('JORMUNGANDR_STAT_CONNECTION_RETRY_POLICY', '{}'))
or default_stat_connection_retry_policy
)

default_stat_transport_options = {
'interval_start': 0,
'interval_step': 1,
'interval_max': 1,
'max_retries': 3,
}

STAT_TRANSPORT_OPTIONS = (
json.loads(os.getenv('JORMUNGANDR_STAT_TRANSPORT_OPTIONS', '{}')) or default_stat_transport_options
)

# Cache configuration, see https://pythonhosted.org/Flask-Caching/ for more information
default_cache = {
'CACHE_TYPE': 'null', # by default cache is not activated
Expand Down
30 changes: 17 additions & 13 deletions source/jormungandr/jormungandr/stat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,19 @@ def __init__(self, auto_delete=False):
self.broker_url = app.config.get('BROKER_URL', None)
self.exchange_name = app.config.get('EXCHANGE_NAME', None)
self.connection_timeout = app.config.get('STAT_CONNECTION_TIMEOUT', 1)
self.interval_start = app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("interval_start", 0)
self.interval_step = app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("interval_step", 1)
self.interval_max = app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("interval_max", 1)
self.max_retries = app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("max_retries", 5)

self.retry_policy = {
'interval_start': app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("interval_start", 0),
'interval_step': app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("interval_step", 1),
'interval_max': app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("interval_max", 1),
'max_retries': app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("max_retries", 5),
"timeout": app.config.get('STAT_CONNECTION_RETRY_POLICY', {}).get("timeout", 1),
}
self.transport_options = {
'interval_start': app.config.get('STAT_TRANSPORT_OPTIONS', {}).get("interval_start", 0),
'interval_step': app.config.get('STAT_TRANSPORT_OPTIONS', {}).get("interval_step", 1),
'interval_max': app.config.get('STAT_TRANSPORT_OPTIONS', {}).get("interval_max", 1),
'max_retries': app.config.get('STAT_TRANSPORT_OPTIONS', {}).get("max_retries", 3),
}
if self.save_stat:
try:
self._init_rabbitmq(auto_delete)
Expand All @@ -145,15 +153,11 @@ def _init_rabbitmq(self, auto_delete=False):
"""
connection to rabbitmq and initialize queues
"""
self.connection = kombu.Connection(self.broker_url, connect_timeout=self.connection_timeout)
retry_policy = {
'interval_start': self.interval_start,
'interval_step': self.interval_step,
'interval_max': self.interval_max,
'max_retries': self.max_retries,
}
self.connection = kombu.Connection(
self.broker_url, connect_timeout=self.connection_timeout, transport_options=self.transport_options
)

self.connection.ensure_connection(**retry_policy)
self.connection.ensure_connection(**self.retry_policy)
self.exchange = kombu.Exchange(self.exchange_name, type="topic", auto_delete=auto_delete)
self.producer = self.connection.Producer(exchange=self.exchange)

Expand Down