Add better error message consuming and dict processing

Change-Id: Iccdc69260318aabc9f8c79c8ea9efb84bdeea531
This commit is contained in:
Dina Belova 2014-12-29 13:44:11 +03:00
parent a6419e6cf3
commit da4b4e85b2
3 changed files with 8 additions and 4 deletions

View File

@ -18,6 +18,7 @@ class OpenTSDBError(Exception):
def __init__(self, msg=None):
if msg is None:
msg = 'Unknown OpenTSDB error occurred. \n %s \n %s'
self.msg = msg
super(OpenTSDBError, self).__init__(msg)

View File

@ -107,7 +107,7 @@ class RESTOpenTSDBClient(base.BaseOpenTSDBClient):
except Exception:
raise opentsdbclient.OpenTSDBError(resp.text)
if 'errors' in res:
if 'error' in res:
raise opentsdbclient.OpenTSDBError(res['error'])
return res

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import itertools
import logging
import random
@ -198,11 +199,13 @@ class SocketOpenTSDBClient(base.BaseOpenTSDBClient):
'has been collected' % self.max_uncaught_exceptions)
raise
def compose_line_from_meter(self, meter_dict):
def compose_line_from_meter(self, m_dict):
meter_dict = copy.deepcopy(m_dict)
tags = meter_dict.pop('tags')
tags = ''.join(' %s=%s' % (k, v) for k, v in six.iteritems(tags))
tags_str = ''.join(' %s=%s' % (k, v) for k, v in six.iteritems(tags))
line = '%(metric)s %(timestamp)d %(value)s' % meter_dict
return '%(metric)s%(tags)s' % {'metric': line, 'tags': tags}
meter_dict['tags'] = tags
return '%(metric)s%(tags)s' % {'metric': line, 'tags': tags_str}
def send_data(self):
req = ''.join("put %s\n" % self.compose_line_from_meter(meter_dict)