Skip to content

feat: Add retry strategy with backoff of 0.5s #159

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

Merged
merged 1 commit into from
Oct 27, 2020
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
104 changes: 66 additions & 38 deletions sdcclient/_common.py

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions sdcclient/_monitor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json
import re

import requests

from sdcclient._common import _SdcCommon
from sdcclient.monitor import EventsClientV2, DashboardsClientV3

Expand All @@ -24,7 +22,7 @@ def get_alerts(self):
**Example**
`examples/list_alerts.py <https://github.com/draios/python-sdc-client/blob/master/examples/list_alerts.py>`_
'''
res = requests.get(self.url + '/api/alerts', headers=self.hdrs, verify=self.ssl_verify)
res = self.http.get(self.url + '/api/alerts', headers=self.hdrs, verify=self.ssl_verify)
return self._request_result(res)

def get_notifications(self, from_ts, to_ts, state=None, resolved=None):
Expand Down Expand Up @@ -57,7 +55,7 @@ def get_notifications(self, from_ts, to_ts, state=None, resolved=None):
if resolved is not None:
params['resolved'] = resolved

res = requests.get(self.url + '/api/notifications', headers=self.hdrs, params=params, verify=self.ssl_verify)
res = self.http.get(self.url + '/api/notifications', headers=self.hdrs, params=params, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]
return [True, res.json()]
Expand All @@ -82,7 +80,7 @@ def update_notification_resolution(self, notification, resolved):
notification['resolved'] = resolved
data = {'notification': notification}

res = requests.put(self.url + '/api/notifications/' + str(notification['id']), headers=self.hdrs, data=json.dumps(data), verify=self.ssl_verify)
res = self.http.put(self.url + '/api/notifications/' + str(notification['id']), headers=self.hdrs, data=json.dumps(data), verify=self.ssl_verify)
return self._request_result(res)

def create_alert(self, name=None, description=None, severity=None, for_atleast_s=None, condition=None,
Expand Down Expand Up @@ -121,7 +119,7 @@ def create_alert(self, name=None, description=None, severity=None, for_atleast_s
#
# Get the list of alerts from the server
#
res = requests.get(self.url + '/api/alerts', headers=self.hdrs, verify=self.ssl_verify)
res = self.http.get(self.url + '/api/alerts', headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]
res.json()
Expand Down Expand Up @@ -167,7 +165,7 @@ def create_alert(self, name=None, description=None, severity=None, for_atleast_s
#
# Create the new alert
#
res = requests.post(self.url + '/api/alerts', headers=self.hdrs, data=json.dumps(alert_json), verify=self.ssl_verify)
res = self.http.post(self.url + '/api/alerts', headers=self.hdrs, data=json.dumps(alert_json), verify=self.ssl_verify)
return self._request_result(res)

def update_alert(self, alert):
Expand All @@ -186,7 +184,7 @@ def update_alert(self, alert):
if 'id' not in alert:
return [False, "Invalid alert format"]

res = requests.put(self.url + '/api/alerts/' + str(alert['id']), headers=self.hdrs, data=json.dumps({"alert": alert}), verify=self.ssl_verify)
res = self.http.put(self.url + '/api/alerts/' + str(alert['id']), headers=self.hdrs, data=json.dumps({"alert": alert}), verify=self.ssl_verify)
return self._request_result(res)

def delete_alert(self, alert):
Expand All @@ -205,7 +203,7 @@ def delete_alert(self, alert):
if 'id' not in alert:
return [False, 'Invalid alert format']

res = requests.delete(self.url + '/api/alerts/' + str(alert['id']), headers=self.hdrs, verify=self.ssl_verify)
res = self.http.delete(self.url + '/api/alerts/' + str(alert['id']), headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]

Expand All @@ -221,7 +219,7 @@ def get_explore_grouping_hierarchy(self):
**Example**
`examples/print_explore_grouping.py <https://github.com/draios/python-sdc-client/blob/master/examples/print_explore_grouping.py>`_
'''
res = requests.get(self.url + '/api/groupConfigurations', headers=self.hdrs, verify=self.ssl_verify)
res = self.http.get(self.url + '/api/groupConfigurations', headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]

Expand Down Expand Up @@ -259,7 +257,7 @@ def set_explore_grouping_hierarchy(self, new_hierarchy):
for item in new_hierarchy:
body['groups'][0]['groupBy'].append({'metric': item})

res = requests.put(self.url + '/api/groupConfigurations/explore', headers=self.hdrs,
res = self.http.put(self.url + '/api/groupConfigurations/explore', headers=self.hdrs,
data=json.dumps(body), verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]
Expand All @@ -277,7 +275,7 @@ def get_metrics(self):
**Example**
`examples/list_metrics.py <https://github.com/draios/python-sdc-client/blob/master/examples/list_metrics.py>`_
'''
res = requests.get(self.url + '/api/data/metrics', headers=self.hdrs, verify=self.ssl_verify)
res = self.http.get(self.url + '/api/data/metrics', headers=self.hdrs, verify=self.ssl_verify)
return self._request_result(res)

@staticmethod
Expand Down
12 changes: 5 additions & 7 deletions sdcclient/_monitor_v1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
import copy
import requests
import re
import json

from sdcclient._monitor import SdMonitorClient

Expand Down Expand Up @@ -75,7 +73,7 @@ def create_dashboard_from_template(self, dashboard_name, template, scope, shared
#
# Create the new dashboard
#
res = requests.post(self.url + self._dashboards_api_endpoint, headers=self.hdrs, data=json.dumps({'dashboard': template}), verify=self.ssl_verify)
res = self.http.post(self.url + self._dashboards_api_endpoint, headers=self.hdrs, data=json.dumps({'dashboard': template}), verify=self.ssl_verify)
return self._request_result(res)

def create_dashboard(self, name):
Expand All @@ -101,7 +99,7 @@ def create_dashboard(self, name):
#
# Create the new dashboard
#
res = requests.post(self.url + self._dashboards_api_endpoint, headers=self.hdrs, data=json.dumps({'dashboard': dashboard_configuration}),
res = self.http.post(self.url + self._dashboards_api_endpoint, headers=self.hdrs, data=json.dumps({'dashboard': dashboard_configuration}),
verify=self.ssl_verify)
return self._request_result(res)

Expand Down Expand Up @@ -242,7 +240,7 @@ def add_dashboard_panel(self, dashboard, name, panel_type, metrics, scope=None,
#
# Update dashboard
#
res = requests.put(self.url + self._dashboards_api_endpoint + '/' + str(dashboard['id']), headers=self.hdrs, data=json.dumps({'dashboard': dashboard_configuration}),
res = self.http.put(self.url + self._dashboards_api_endpoint + '/' + str(dashboard['id']), headers=self.hdrs, data=json.dumps({'dashboard': dashboard_configuration}),
verify=self.ssl_verify)
return self._request_result(res)

Expand Down Expand Up @@ -283,7 +281,7 @@ def filter_fn(panel):
#
# Update dashboard
#
res = requests.put(self.url + self._dashboards_api_endpoint + '/' + str(dashboard['id']), headers=self.hdrs, data=json.dumps({'dashboard': dashboard_configuration}),
res = self.http.put(self.url + self._dashboards_api_endpoint + '/' + str(dashboard['id']), headers=self.hdrs, data=json.dumps({'dashboard': dashboard_configuration}),
verify=self.ssl_verify)
return self._request_result(res)
else:
Expand Down
Loading