transformer, publisher: move down base plugin classes
Blueprint: oslo-multi-publisher Change-Id: I46768ac99dff2d5c8597916584ecef553e151531 Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
a56fb16815
commit
104f33f5bd
@ -86,47 +86,3 @@ class PollsterBase(PluginBase):
|
||||
def get_counters(self, manager, instance):
|
||||
"""Return a sequence of Counter instances from polling the
|
||||
resources."""
|
||||
|
||||
|
||||
class PublisherBase(PluginBase):
|
||||
"""Base class for plugins that publish the sampler."""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def publish_counters(self, context, counters, source):
|
||||
"Publish counters into final conduit."
|
||||
|
||||
|
||||
class TransformerBase(PluginBase):
|
||||
"""Base class for plugins that transform the counter."""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def handle_sample(self, context, counter, source):
|
||||
"""Transform a counter.
|
||||
|
||||
:param context: Passed from the data collector.
|
||||
:param counter: A counter.
|
||||
:param source: Passed from data collector.
|
||||
"""
|
||||
|
||||
def flush(self, context, source):
|
||||
"""Flush counters cached previously.
|
||||
|
||||
:param context: Passed from the data collector.
|
||||
:param source: Source of counters that are being published."""
|
||||
return []
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Setup transformer.
|
||||
|
||||
Each time a transformed is involved in a pipeline, a new transformer
|
||||
instance is created and chained into the pipeline. i.e. transformer
|
||||
instance is per pipeline. This helps if transformer need keep some
|
||||
cache and per-pipeline information.
|
||||
|
||||
:param kwargs: The parameters that are defined in pipeline config file.
|
||||
"""
|
||||
super(TransformerBase, self).__init__()
|
||||
|
@ -18,6 +18,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import abc
|
||||
from stevedore import dispatch
|
||||
|
||||
|
||||
@ -29,3 +30,13 @@ class PublisherExtensionManager(dispatch.NameDispatchExtensionManager):
|
||||
check_func=lambda x: True,
|
||||
invoke_on_load=True,
|
||||
)
|
||||
|
||||
|
||||
class PublisherBase(object):
|
||||
"""Base class for plugins that publish the sampler."""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def publish_counters(self, context, counters, source):
|
||||
"Publish counters into final conduit."
|
||||
|
@ -25,7 +25,8 @@ from oslo.config import cfg
|
||||
from ceilometer.collector import meter as meter_api
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer.openstack.common import rpc
|
||||
from ceilometer import plugin
|
||||
from ceilometer import publisher
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -46,7 +47,7 @@ def register_opts(config):
|
||||
register_opts(cfg.CONF)
|
||||
|
||||
|
||||
class MeterPublisher(plugin.PublisherBase):
|
||||
class MeterPublisher(publisher.PublisherBase):
|
||||
def publish_counters(self, context, counters, source):
|
||||
"""Send a metering message for publishing
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import abc
|
||||
from stevedore import extension
|
||||
|
||||
|
||||
@ -32,3 +33,37 @@ class TransformerExtensionManager(extension.ExtensionManager):
|
||||
|
||||
def get_ext(self, name):
|
||||
return self.by_name[name]
|
||||
|
||||
|
||||
class TransformerBase(object):
|
||||
"""Base class for plugins that transform the counter."""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Setup transformer.
|
||||
|
||||
Each time a transformed is involved in a pipeline, a new transformer
|
||||
instance is created and chained into the pipeline. i.e. transformer
|
||||
instance is per pipeline. This helps if transformer need keep some
|
||||
cache and per-pipeline information.
|
||||
|
||||
:param kwargs: The parameters that are defined in pipeline config file.
|
||||
"""
|
||||
super(TransformerBase, self).__init__()
|
||||
|
||||
@abc.abstractmethod
|
||||
def handle_sample(self, context, counter, source):
|
||||
"""Transform a counter.
|
||||
|
||||
:param context: Passed from the data collector.
|
||||
:param counter: A counter.
|
||||
:param source: Passed from data collector.
|
||||
"""
|
||||
|
||||
def flush(self, context, source):
|
||||
"""Flush counters cached previously.
|
||||
|
||||
:param context: Passed from the data collector.
|
||||
:param source: Source of counters that are being published."""
|
||||
return []
|
||||
|
@ -16,10 +16,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometer import plugin
|
||||
from ceilometer import transformer
|
||||
|
||||
|
||||
class TransformerAccumulator(plugin.TransformerBase):
|
||||
class TransformerAccumulator(transformer.TransformerBase):
|
||||
"""Transformer that accumulates counter until a threshold, and then flush
|
||||
them out in the wild. """
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
from stevedore import extension
|
||||
|
||||
from ceilometer import counter
|
||||
from ceilometer import plugin
|
||||
from ceilometer import publisher
|
||||
from ceilometer import transformer
|
||||
from ceilometer.transformer import accumulator
|
||||
@ -65,7 +64,7 @@ class TestPipeline(base.TestCase):
|
||||
def publish_counters(self, ctxt, counters, source):
|
||||
raise Exception()
|
||||
|
||||
class TransformerClass(plugin.TransformerBase):
|
||||
class TransformerClass(transformer.TransformerBase):
|
||||
samples = []
|
||||
|
||||
def __init__(self, append_name='_update'):
|
||||
@ -80,7 +79,7 @@ class TestPipeline(base.TestCase):
|
||||
newname = getattr(counter, 'name') + self.append_name
|
||||
return counter._replace(name=newname)
|
||||
|
||||
class TransformerClassDrop(plugin.TransformerBase):
|
||||
class TransformerClassDrop(transformer.TransformerBase):
|
||||
samples = []
|
||||
|
||||
def __init__(self):
|
||||
|
Loading…
Reference in New Issue
Block a user