def process(self, metric, datapoint): # normalize metric name (reorder tags) try: metric = TaggedSeries.parse(metric).path except Exception as err: log.msg('Error parsing metric %s: %s' % (metric, err)) self.cache.store(metric, datapoint) return Processor.NO_OUTPUT
def process(self, metric, datapoint): if settings.TAG_RELAY_NORMALIZED: # normalize metric name try: metric = TaggedSeries.parse(metric).path except Exception as err: log.msg('Error parsing metric %s: %s' % (metric, err)) # continue anyway with processing the unnormalized metric for robustness state.client_manager.sendDatapoint(metric, datapoint) return pipeline.Processor.NO_OUTPUT
def test_sanitizing_name_as_tag_value(self): test_cases = [ { 'original': "my~.test.abc", 'expected': "my~.test.abc", }, { 'original': "a.b.c", 'expected': "a.b.c", }, { 'original': "~~a~~.~~~b~~~.~~~c~~~", 'expected': "a~~.~~~b~~~.~~~c~~~", }, { 'original': "a.b.c~", 'expected': "a.b.c~", }, { 'original': "~a.b.c", 'expected': "a.b.c", }, { 'original': "~a~", 'expected': "a~", }, { 'original': "~~~", 'raises': True, }, { 'original': "~", 'raises': True, }, ] for test_case in test_cases: if test_case.get('raises', False): self.assertRaises( Exception, TaggedSeries.sanitize_name_as_tag_value, test_case['original'], ) else: result = TaggedSeries.sanitize_name_as_tag_value(test_case['original']) self.assertEquals(result, test_case['expected'])
def test_validate_tag_key_and_value(self): # assert that it raises exception when sanitized name is still not valid with self.assertRaises(Exception): # sanitized name is going to be '', which is not a valid tag value TaggedSeries.sanitize_name_as_tag_value('~~~~') with self.assertRaises(Exception): # given tag value is invalid because it has length 0 TaggedSeries.validateTagAndValue('metric.name;tag=') with self.assertRaises(Exception): # given tag key is invalid because it has length 0 TaggedSeries.validateTagAndValue('metric.name;=value') with self.assertRaises(Exception): # given tag is missing = TaggedSeries.validateTagAndValue('metric.name;tagvalue') with self.assertRaises(Exception): # given tag value is invalid because it starts with ~ TaggedSeries.validateTagAndValue('metric.name;tag=~value') with self.assertRaises(Exception): # given tag key is invalid because it contains ! TaggedSeries.validateTagAndValue('metric.name;ta!g=value')
def getFilesystemPath(self, metric): return self.tree.getFilesystemPath(TaggedSeries.encode(metric))
def setMetadata(self, metric, key, value): node = self.tree.getNode(TaggedSeries.encode(metric)) metadata = node.readMetadata() metadata[key] = value node.writeMetadata(metadata)
def getMetadata(self, metric, key): return self.tree.getNode( TaggedSeries.encode(metric)).readMetadata()[key]
def create(self, metric, retentions, xfilesfactor, aggregation_method): self.tree.createNode(TaggedSeries.encode(metric), retentions=retentions, timeStep=retentions[0][0], xFilesFactor=xfilesfactor, aggregationMethod=aggregation_method)
def exists(self, metric): return self.tree.hasNode(TaggedSeries.encode(metric))
def write(self, metric, datapoints): self.tree.store(TaggedSeries.encode(metric), datapoints)
def getFilesystemPath(self, metric): return join(self.data_dir, TaggedSeries.encode(metric, sep) + '.wsp')
def _getFilesystemPath(self, metric, tag_hash_filenames): return join( self.data_dir, TaggedSeries.encode(metric, sep, hash_only=tag_hash_filenames) + '.wsp')
def encode(self, metric, tag_hash_filenames=None): if tag_hash_filenames is None: tag_hash_filenames = self.tag_hash_filenames return TaggedSeries.encode(metric, hash_only=tag_hash_filenames)
def _getFilesystemPath(self, metric, tag_hash_filenames): return join( self.data_dir, TaggedSeries.encode(metric, sep, hash_only=tag_hash_filenames) + '.wsp' )