@@ -219,7 +219,7 @@ def get_datapoints(self, tags, start=None, end=None, order=None,
219
219
- order: ascending (asc) or descending (desc)
220
220
- limit: only return a few values (ie. 25)
221
221
- qualities: data quality value (ie. [ts.GOOD, ts.UNCERTAIN])
222
- - attributes: data attributes (ie. {'unit': 'mph'})
222
+ - attributes: dictionary of key-values (ie. {'unit': 'mph'})
223
223
- measurement: tuple of operation and value (ie. ('gt', 30))
224
224
- aggregations: summary statistics on data results (ie. 'avg')
225
225
- post: POST query instead of GET (caching implication)
@@ -241,7 +241,7 @@ def get_datapoints(self, tags, start=None, end=None, order=None,
241
241
# seems to be required all the time, so using sensible default.
242
242
if not start :
243
243
start = '1w-ago'
244
- logging .info ("Defaulting to timeseries data since %s" % (start ))
244
+ logging .warning ("Defaulting query for data with start date %s" % (start ))
245
245
246
246
# Start date can be absolute or relative, only certain legal values
247
247
# but service will throw error if used improperly. (ms, s, mi, h, d,
@@ -352,7 +352,12 @@ def get_latest(self, tags, post=False):
352
352
and more complex query.
353
353
"""
354
354
params = {}
355
- params ['tags' ] = tags
355
+ if isinstance (tags , list ):
356
+ params ['tags' ] = str .join (',' , tags )
357
+ elif isinstance (tags , str ):
358
+ params ['tags' ] = tags
359
+ else :
360
+ raise ValueError ("Expect to get tags as a str or list" )
356
361
357
362
if post :
358
363
return self ._post_latest (params )
@@ -459,17 +464,24 @@ def queue(self, name, value, quality=None, timestamp=None,
459
464
"datapoints" : [[timestamp , value , quality ]]
460
465
}
461
466
462
- # Attributes are specified for datapoint
463
- if attributes :
467
+ # Attributes are extra details for a datapoint
468
+
469
+ if attributes is not None :
470
+ if not isinstance (attributes , dict ):
471
+ raise ValueError ("Attributes are expected to be a dictionary." )
472
+
464
473
# Validate rules for attribute keys to provide guidance.
465
474
invalid_value = ':;= '
466
475
has_invalid_value = re .compile (r'[%s]' % (invalid_value )).search
467
476
has_valid_key = re .compile (r'^[\w\.\/\-]+$' ).search
468
477
469
478
for (key , val ) in list (attributes .items ()):
470
- # Values cannot be NULL
471
- if not val :
472
- raise ValueError ("Attribute (%s) must have value." % (key ))
479
+ # Values cannot be empty
480
+ if (val == '' ) or (val is None ):
481
+ raise ValueError ("Attribute (%s) must have a non-empty value." % (key ))
482
+
483
+ # Values should be treated as a string for regex validation
484
+ val = str (val )
473
485
474
486
# Values cannot contain certain arbitrary characters
475
487
if bool (has_invalid_value (val )):
0 commit comments