Ejemplo n.º 1
0
  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
Ejemplo n.º 2
0
  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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
  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
Ejemplo n.º 5
0
    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'])
Ejemplo n.º 6
0
    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')
Ejemplo n.º 7
0
 def getFilesystemPath(self, metric):
     return self.tree.getFilesystemPath(TaggedSeries.encode(metric))
Ejemplo n.º 8
0
 def setMetadata(self, metric, key, value):
     node = self.tree.getNode(TaggedSeries.encode(metric))
     metadata = node.readMetadata()
     metadata[key] = value
     node.writeMetadata(metadata)
Ejemplo n.º 9
0
 def getMetadata(self, metric, key):
     return self.tree.getNode(
         TaggedSeries.encode(metric)).readMetadata()[key]
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 def exists(self, metric):
     return self.tree.hasNode(TaggedSeries.encode(metric))
Ejemplo n.º 12
0
 def write(self, metric, datapoints):
     self.tree.store(TaggedSeries.encode(metric), datapoints)
Ejemplo n.º 13
0
 def getFilesystemPath(self, metric):
     return join(self.data_dir,
                 TaggedSeries.encode(metric, sep) + '.wsp')
Ejemplo n.º 14
0
 def _getFilesystemPath(self, metric, tag_hash_filenames):
     return join(
         self.data_dir,
         TaggedSeries.encode(metric, sep, hash_only=tag_hash_filenames)
         + '.wsp')
Ejemplo n.º 15
0
 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)
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 def _getFilesystemPath(self, metric, tag_hash_filenames):
   return join(
     self.data_dir,
     TaggedSeries.encode(metric, sep, hash_only=tag_hash_filenames) + '.wsp'
   )