本文整理汇总了Python中carbon.rewrite.RewriteRuleManager类的典型用法代码示例。如果您正苦于以下问题:Python RewriteRuleManager类的具体用法?Python RewriteRuleManager怎么用?Python RewriteRuleManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RewriteRuleManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
def process(self, metric, datapoint):
increment('datapointsReceived')
for rule in RewriteRuleManager.rules(PRE):
metric = rule.apply(metric)
aggregate_metrics = set()
for rule in RuleManager.rules:
aggregate_metric = rule.get_aggregate_metric(metric)
if aggregate_metric is None:
continue
else:
aggregate_metrics.add(aggregate_metric)
values_buffer = BufferManager.get_buffer(aggregate_metric)
if not values_buffer.configured:
values_buffer.configure_aggregation(rule.frequency, rule.aggregation_func)
values_buffer.input(datapoint)
for rule in RewriteRuleManager.rules(POST):
metric = rule.apply(metric)
if metric not in aggregate_metrics:
yield (metric, datapoint)
示例2: process
def process(self, metric, datapoint):
increment('datapointsReceived')
for rule in RewriteRuleManager.rules(PRE):
metric = rule.apply(metric)
aggregate_metrics = set()
for rule in RuleManager.rules:
aggregate_metric = rule.get_aggregate_metric(metric)
if aggregate_metric is None:
continue
else:
aggregate_metrics.add(aggregate_metric)
values_buffer = BufferManager.get_buffer(aggregate_metric)
if not values_buffer.configured:
values_buffer.configure_aggregation(rule.frequency, rule.aggregation_func)
values_buffer.input(datapoint)
for rule in RewriteRuleManager.rules(POST):
metric = rule.apply(metric)
if settings.FORWARD_ALL and metric not in aggregate_metrics:
if settings.LOG_AGGREGATOR_MISSES and len(aggregate_metrics) == 0:
log.msg(
"Couldn't match metric %s with any aggregation rule. Passing on un-aggregated." % metric)
yield (metric, datapoint)
示例3: createAggregatorService
def createAggregatorService(config):
from carbon.aggregator import receiver
from carbon.aggregator.rules import RuleManager
from carbon.routers import ConsistentHashingRouter
from carbon.client import CarbonClientManager
from carbon.rewrite import RewriteRuleManager
from carbon.conf import settings
from carbon import events
root_service = createBaseService(config)
# Configure application components
router = ConsistentHashingRouter()
client_manager = CarbonClientManager(router)
client_manager.setServiceParent(root_service)
events.metricReceived.addHandler(receiver.process)
events.metricGenerated.addHandler(client_manager.sendDatapoint)
RuleManager.read_from(settings["aggregation-rules"])
if exists(settings["rewrite-rules"]):
RewriteRuleManager.read_from(settings["rewrite-rules"])
if not settings.DESTINATIONS:
raise CarbonConfigException("Required setting DESTINATIONS is missing from carbon.conf")
for destination in util.parseDestinations(settings.DESTINATIONS):
client_manager.startClient(destination)
return root_service
示例4: test_read_clears_if_no_file
def test_read_clears_if_no_file(self):
import carbon.rewrite
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'exists', Mock(return_value=False)):
with patch.object(RewriteRuleManager, 'clear') as clear_mock:
RewriteRuleManager.read_rules()
clear_mock.assert_called_once_with()
示例5: test_read_records_mtime
def test_read_records_mtime(self):
import carbon.rewrite
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', mock_open(), create=True):
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
RewriteRuleManager.read_rules()
self.assertEqual(1234, RewriteRuleManager.rules_last_read)
示例6: test_read_opens_file_if_mtime_newer
def test_read_opens_file_if_mtime_newer(self):
import carbon.rewrite
RewriteRuleManager.rules_last_read = 1234
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', mock_open(), create=True) as open_mock:
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=5678)):
RewriteRuleManager.read_rules()
self.assertTrue(open_mock.called)
示例7: test_comments_ignored
def test_comments_ignored(self):
import carbon.rewrite
open_mock = Mock(return_value=iter(self.commented_config.splitlines()))
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', open_mock, create=True):
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
RewriteRuleManager.read_rules()
self.assertEqual(1, len(RewriteRuleManager.rules('pre')))
示例8: test_section_parsed_into_ruleset
def test_section_parsed_into_ruleset(self):
import carbon.rewrite
open_mock = Mock(return_value=iter(self.sample_config.splitlines()))
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', open_mock, create=True):
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
RewriteRuleManager.read_rules()
self.assertTrue('pre' in RewriteRuleManager.rulesets)
示例9: test_read_doesnt_open_file_if_mtime_unchanged
def test_read_doesnt_open_file_if_mtime_unchanged(self):
import carbon.rewrite
mtime = 1234
RewriteRuleManager.rules_last_read = mtime
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'open', mock_open(), create=True) as open_mock:
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=1234)):
RewriteRuleManager.read_rules()
self.assertFalse(open_mock.called)
示例10: test_rules_unchanged_if_mtime_unchanged
def test_rules_unchanged_if_mtime_unchanged(self):
import carbon.rewrite
mtime = 1234
rulesets = {'pre': [Mock(RewriteRule)]}
RewriteRuleManager.rules_last_read = mtime
RewriteRuleManager.rulesets.update(rulesets)
RewriteRuleManager.rules_file = 'foo.conf'
with patch.object(carbon.rewrite, 'exists', Mock(return_value=True)):
with patch.object(carbon.rewrite, 'getmtime', Mock(return_value=mtime)):
RewriteRuleManager.read_rules()
self.assertEqual(rulesets, RewriteRuleManager.rulesets)
示例11: createAggregatorService
def createAggregatorService(config):
from carbon.events import metricReceived
from carbon.aggregator import receiver
from carbon.aggregator.rules import RuleManager
from carbon.aggregator import client
from carbon.rewrite import RewriteRuleManager
from carbon.conf import settings
root_service = createBaseService(config)
# Configure application components
metricReceived.installHandler(receiver.process)
RuleManager.read_from(settings["aggregation-rules"])
if exists(settings["rewrite-rules"]):
RewriteRuleManager.read_from(settings["rewrite-rules"])
client.connect(settings["DESTINATION_HOST"],
int(settings["DESTINATION_PORT"]))
return root_service
示例12: test_request_for_nonexistent_rules_returns_iterable
def test_request_for_nonexistent_rules_returns_iterable(self):
try:
iter(RewriteRuleManager.rules('foo'))
except TypeError:
self.fail("RewriteRuleManager.rules() returned a non-iterable type")
示例13: tearDown
def tearDown(self):
instrumentation.stats.clear()
BufferManager.clear()
RuleManager.clear()
RewriteRuleManager.clear()
示例14: setupRewriterProcessor
def setupRewriterProcessor(root_service, settings):
from carbon.rewrite import RewriteRuleManager
rewrite_rules_path = settings["rewrite-rules"]
RewriteRuleManager.read_from(rewrite_rules_path)
示例15: tearDown
def tearDown(self):
RewriteRuleManager.rules_file = None
RewriteRuleManager.rules_last_read = 0.0
RewriteRuleManager.clear()