Change counter to sample vocable in cm.transformer
This changes counter to sample vocable in ceilometer.transformer code Parts of the blueprint remove-counter Change-Id: I81b840299f25425f5d43a2aef6272927eadd6cda
This commit is contained in:
parent
6f7da3a192
commit
34462ca549
@ -36,7 +36,7 @@ class TransformerExtensionManager(extension.ExtensionManager):
|
|||||||
|
|
||||||
|
|
||||||
class TransformerBase(object):
|
class TransformerBase(object):
|
||||||
"""Base class for plugins that transform the counter."""
|
"""Base class for plugins that transform the sample."""
|
||||||
|
|
||||||
__metaclass__ = abc.ABCMeta
|
__metaclass__ = abc.ABCMeta
|
||||||
|
|
||||||
@ -53,15 +53,15 @@ class TransformerBase(object):
|
|||||||
super(TransformerBase, self).__init__()
|
super(TransformerBase, self).__init__()
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def handle_sample(self, context, counter):
|
def handle_sample(self, context, sample):
|
||||||
"""Transform a counter.
|
"""Transform a sample.
|
||||||
|
|
||||||
:param context: Passed from the data collector.
|
:param context: Passed from the data collector.
|
||||||
:param counter: A counter.
|
:param sample: A sample.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def flush(self, context):
|
def flush(self, context):
|
||||||
"""Flush counters cached previously.
|
"""Flush samples cached previously.
|
||||||
|
|
||||||
:param context: Passed from the data collector.
|
:param context: Passed from the data collector.
|
||||||
"""
|
"""
|
||||||
|
@ -20,26 +20,26 @@ from ceilometer import transformer
|
|||||||
|
|
||||||
|
|
||||||
class TransformerAccumulator(transformer.TransformerBase):
|
class TransformerAccumulator(transformer.TransformerBase):
|
||||||
"""Transformer that accumulates counter until a threshold, and then flush
|
"""Transformer that accumulates sample until a threshold, and then flush
|
||||||
them out in the wild.
|
them out in the wild.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, size=1, **kwargs):
|
def __init__(self, size=1, **kwargs):
|
||||||
if size >= 1:
|
if size >= 1:
|
||||||
self.counters = []
|
self.samples = []
|
||||||
self.size = size
|
self.size = size
|
||||||
super(TransformerAccumulator, self).__init__(**kwargs)
|
super(TransformerAccumulator, self).__init__(**kwargs)
|
||||||
|
|
||||||
def handle_sample(self, context, counter):
|
def handle_sample(self, context, sample):
|
||||||
if self.size >= 1:
|
if self.size >= 1:
|
||||||
self.counters.append(counter)
|
self.samples.append(sample)
|
||||||
else:
|
else:
|
||||||
return counter
|
return sample
|
||||||
|
|
||||||
def flush(self, context):
|
def flush(self, context):
|
||||||
if len(self.counters) >= self.size:
|
if len(self.samples) >= self.size:
|
||||||
x = self.counters
|
x = self.samples
|
||||||
self.counters = []
|
self.samples = []
|
||||||
return x
|
return x
|
||||||
return []
|
return []
|
||||||
|
@ -57,8 +57,8 @@ class ScalingTransformer(transformer.TransformerBase):
|
|||||||
def __init__(self, source={}, target={}, **kwargs):
|
def __init__(self, source={}, target={}, **kwargs):
|
||||||
"""Initialize transformer with configured parameters.
|
"""Initialize transformer with configured parameters.
|
||||||
|
|
||||||
:param source: dict containing source counter unit
|
:param source: dict containing source sample unit
|
||||||
:param target: dict containing target counter name, type,
|
:param target: dict containing target sample name, type,
|
||||||
unit and scaling factor (a missing value
|
unit and scaling factor (a missing value
|
||||||
connotes no change)
|
connotes no change)
|
||||||
"""
|
"""
|
||||||
@ -71,44 +71,44 @@ class ScalingTransformer(transformer.TransformerBase):
|
|||||||
super(ScalingTransformer, self).__init__(**kwargs)
|
super(ScalingTransformer, self).__init__(**kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _scale(counter, scale):
|
def _scale(s, scale):
|
||||||
"""Apply the scaling factor (either a straight multiplicative
|
"""Apply the scaling factor (either a straight multiplicative
|
||||||
factor or else a string to be eval'd).
|
factor or else a string to be eval'd).
|
||||||
"""
|
"""
|
||||||
ns = Namespace(counter.as_dict())
|
ns = Namespace(s.as_dict())
|
||||||
|
|
||||||
return ((eval(scale, {}, ns) if isinstance(scale, basestring)
|
return ((eval(scale, {}, ns) if isinstance(scale, basestring)
|
||||||
else counter.volume * scale) if scale else counter.volume)
|
else s.volume * scale) if scale else s.volume)
|
||||||
|
|
||||||
def _convert(self, counter, growth=1):
|
def _convert(self, s, growth=1):
|
||||||
"""Transform the appropriate counter fields.
|
"""Transform the appropriate sample fields.
|
||||||
"""
|
"""
|
||||||
scale = self.target.get('scale')
|
scale = self.target.get('scale')
|
||||||
return sample.Sample(
|
return sample.Sample(
|
||||||
name=self.target.get('name', counter.name),
|
name=self.target.get('name', s.name),
|
||||||
unit=self.target.get('unit', counter.unit),
|
unit=self.target.get('unit', s.unit),
|
||||||
type=self.target.get('type', counter.type),
|
type=self.target.get('type', s.type),
|
||||||
volume=self._scale(counter, scale) * growth,
|
volume=self._scale(s, scale) * growth,
|
||||||
user_id=counter.user_id,
|
user_id=s.user_id,
|
||||||
project_id=counter.project_id,
|
project_id=s.project_id,
|
||||||
resource_id=counter.resource_id,
|
resource_id=s.resource_id,
|
||||||
timestamp=counter.timestamp,
|
timestamp=s.timestamp,
|
||||||
resource_metadata=counter.resource_metadata
|
resource_metadata=s.resource_metadata
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle_sample(self, context, counter):
|
def handle_sample(self, context, s):
|
||||||
"""Handle a sample, converting if necessary."""
|
"""Handle a sample, converting if necessary."""
|
||||||
LOG.debug('handling counter %s', (counter,))
|
LOG.debug('handling sample %s', (s,))
|
||||||
if (self.source.get('unit', counter.unit) == counter.unit):
|
if (self.source.get('unit', s.unit) == s.unit):
|
||||||
counter = self._convert(counter)
|
s = self._convert(s)
|
||||||
LOG.debug(_('converted to: %s') % (counter,))
|
LOG.debug(_('converted to: %s') % (s,))
|
||||||
return counter
|
return s
|
||||||
|
|
||||||
|
|
||||||
class RateOfChangeTransformer(ScalingTransformer):
|
class RateOfChangeTransformer(ScalingTransformer):
|
||||||
"""Transformer based on the rate of change of a counter volume,
|
"""Transformer based on the rate of change of a sample volume,
|
||||||
for example taking the current and previous volumes of a
|
for example taking the current and previous volumes of a
|
||||||
cumulative counter and producing a gauge value based on the
|
cumulative sample and producing a gauge value based on the
|
||||||
proportion of some maximum used.
|
proportion of some maximum used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -118,32 +118,32 @@ class RateOfChangeTransformer(ScalingTransformer):
|
|||||||
self.cache = {}
|
self.cache = {}
|
||||||
super(RateOfChangeTransformer, self).__init__(**kwargs)
|
super(RateOfChangeTransformer, self).__init__(**kwargs)
|
||||||
|
|
||||||
def handle_sample(self, context, counter):
|
def handle_sample(self, context, s):
|
||||||
"""Handle a sample, converting if necessary."""
|
"""Handle a sample, converting if necessary."""
|
||||||
LOG.debug('handling counter %s', (counter,))
|
LOG.debug('handling sample %s', (s,))
|
||||||
key = counter.name + counter.resource_id
|
key = s.name + s.resource_id
|
||||||
prev = self.cache.get(key)
|
prev = self.cache.get(key)
|
||||||
timestamp = timeutils.parse_isotime(counter.timestamp)
|
timestamp = timeutils.parse_isotime(s.timestamp)
|
||||||
self.cache[key] = (counter.volume, timestamp)
|
self.cache[key] = (s.volume, timestamp)
|
||||||
|
|
||||||
if prev:
|
if prev:
|
||||||
prev_volume = prev[0]
|
prev_volume = prev[0]
|
||||||
prev_timestamp = prev[1]
|
prev_timestamp = prev[1]
|
||||||
time_delta = timeutils.delta_seconds(prev_timestamp, timestamp)
|
time_delta = timeutils.delta_seconds(prev_timestamp, timestamp)
|
||||||
# we only allow negative deltas for noncumulative counters, whereas
|
# we only allow negative deltas for noncumulative samples, whereas
|
||||||
# for cumulative we assume that a reset has occurred in the interim
|
# for cumulative we assume that a reset has occurred in the interim
|
||||||
# so that the current volume gives a lower bound on growth
|
# so that the current volume gives a lower bound on growth
|
||||||
volume_delta = (counter.volume - prev_volume
|
volume_delta = (s.volume - prev_volume
|
||||||
if (prev_volume <= counter.volume or
|
if (prev_volume <= s.volume or
|
||||||
counter.type != sample.TYPE_CUMULATIVE)
|
s.type != sample.TYPE_CUMULATIVE)
|
||||||
else counter.volume)
|
else s.volume)
|
||||||
rate_of_change = ((1.0 * volume_delta / time_delta)
|
rate_of_change = ((1.0 * volume_delta / time_delta)
|
||||||
if time_delta else 0.0)
|
if time_delta else 0.0)
|
||||||
|
|
||||||
counter = self._convert(counter, rate_of_change)
|
s = self._convert(s, rate_of_change)
|
||||||
LOG.debug(_('converted to: %s') % (counter,))
|
LOG.debug(_('converted to: %s') % (s,))
|
||||||
else:
|
else:
|
||||||
LOG.warn(_('dropping counter with no predecessor: %s') %
|
LOG.warn(_('dropping sample with no predecessor: %s') %
|
||||||
(counter,))
|
(s,))
|
||||||
counter = None
|
s = None
|
||||||
return counter
|
return s
|
||||||
|
Loading…
Reference in New Issue
Block a user