Support for wildcard in pipeline
This patch will support for wildcard in pipeline.yaml so we can exclude things like !storage.objects.* This patch is dedicated to Fei Long Wang who triggered my thought on the subject and proposed a first implementation. docImpact Fixes bug 1209128 Change-Id: I09a805ea7c9313b45152672a63981d5d4c263601
This commit is contained in:
parent
056e883373
commit
2363058cd3
@ -16,6 +16,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import fnmatch
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import operator
|
import operator
|
||||||
@ -241,14 +242,27 @@ class Pipeline(object):
|
|||||||
|
|
||||||
def support_meter(self, meter_name):
|
def support_meter(self, meter_name):
|
||||||
meter_name = self._variable_meter_name(meter_name)
|
meter_name = self._variable_meter_name(meter_name)
|
||||||
if ('!' + meter_name) in self.meters:
|
|
||||||
return False
|
# Special case: if we only have negation, we suppose the default it
|
||||||
if '*' in self.meters:
|
# allow
|
||||||
return True
|
if all(meter.startswith('!') for meter in self.meters):
|
||||||
elif self.meters[0][0] == '!':
|
default = True
|
||||||
return not ('!' + meter_name) in self.meters
|
|
||||||
else:
|
else:
|
||||||
return meter_name in self.meters
|
default = False
|
||||||
|
|
||||||
|
# Support wildcard like storage.* and !disk.*
|
||||||
|
# Start with negation, we consider that the order is deny, allow
|
||||||
|
if any(fnmatch.fnmatch(meter_name, meter[1:])
|
||||||
|
for meter in self.meters
|
||||||
|
if meter[0] == '!'):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if any(fnmatch.fnmatch(meter_name, meter)
|
||||||
|
for meter in self.meters
|
||||||
|
if meter[0] != '!'):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return default
|
||||||
|
|
||||||
def flush(self, ctxt):
|
def flush(self, ctxt):
|
||||||
"""Flush data after all samples have been injected to pipeline."""
|
"""Flush data after all samples have been injected to pipeline."""
|
||||||
|
@ -325,6 +325,37 @@ class TestPipeline(base.TestCase):
|
|||||||
self.assertTrue(pipeline_manager.pipelines[0].support_meter('b'))
|
self.assertTrue(pipeline_manager.pipelines[0].support_meter('b'))
|
||||||
self.assertFalse(pipeline_manager.pipelines[0].support_meter('c'))
|
self.assertFalse(pipeline_manager.pipelines[0].support_meter('c'))
|
||||||
|
|
||||||
|
def test_wildcard_and_excluded_wildcard_counters(self):
|
||||||
|
counter_cfg = ['*', '!disk.*']
|
||||||
|
self.pipeline_cfg[0]['counters'] = counter_cfg
|
||||||
|
pipeline_manager = pipeline.PipelineManager(self.pipeline_cfg,
|
||||||
|
self.transformer_manager)
|
||||||
|
self.assertFalse(pipeline_manager.pipelines[0].
|
||||||
|
support_meter('disk.read.bytes'))
|
||||||
|
self.assertTrue(pipeline_manager.pipelines[0].support_meter('cpu'))
|
||||||
|
|
||||||
|
def test_included_counter_and_wildcard_counters(self):
|
||||||
|
counter_cfg = ['cpu', 'disk.*']
|
||||||
|
self.pipeline_cfg[0]['counters'] = counter_cfg
|
||||||
|
pipeline_manager = pipeline.PipelineManager(self.pipeline_cfg,
|
||||||
|
self.transformer_manager)
|
||||||
|
self.assertTrue(pipeline_manager.pipelines[0].
|
||||||
|
support_meter('disk.read.bytes'))
|
||||||
|
self.assertTrue(pipeline_manager.pipelines[0].support_meter('cpu'))
|
||||||
|
self.assertFalse(pipeline_manager.pipelines[0].
|
||||||
|
support_meter('instance'))
|
||||||
|
|
||||||
|
def test_excluded_counter_and_excluded_wildcard_counters(self):
|
||||||
|
counter_cfg = ['!cpu', '!disk.*']
|
||||||
|
self.pipeline_cfg[0]['counters'] = counter_cfg
|
||||||
|
pipeline_manager = pipeline.PipelineManager(self.pipeline_cfg,
|
||||||
|
self.transformer_manager)
|
||||||
|
self.assertFalse(pipeline_manager.pipelines[0].
|
||||||
|
support_meter('disk.read.bytes'))
|
||||||
|
self.assertFalse(pipeline_manager.pipelines[0].support_meter('cpu'))
|
||||||
|
self.assertTrue(pipeline_manager.pipelines[0].
|
||||||
|
support_meter('instance'))
|
||||||
|
|
||||||
def test_multiple_pipeline(self):
|
def test_multiple_pipeline(self):
|
||||||
self.pipeline_cfg.append({
|
self.pipeline_cfg.append({
|
||||||
'name': 'second_pipeline',
|
'name': 'second_pipeline',
|
||||||
|
Loading…
Reference in New Issue
Block a user