API refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-07 16:25:52 +09:00
parent 76d0d86211
commit 91c7e04474
1171 changed files with 81940 additions and 44117 deletions

View File

@@ -7,6 +7,8 @@ class Avg(AbstractSampledStat):
"""
An AbstractSampledStat that maintains a simple average over its samples.
"""
__slots__ = ('_initial_value', '_samples', '_current')
def __init__(self):
super(Avg, self).__init__(0.0)

View File

@@ -7,6 +7,8 @@ class Count(AbstractSampledStat):
"""
An AbstractSampledStat that maintains a simple count of what it has seen.
"""
__slots__ = ('_initial_value', '_samples', '_current')
def __init__(self):
super(Count, self).__init__(0.0)

View File

@@ -4,6 +4,8 @@ import math
class Histogram(object):
__slots__ = ('_hist', '_count', '_bin_scheme')
def __init__(self, bin_scheme):
self._hist = [0.0] * bin_scheme.bins
self._count = 0.0
@@ -40,6 +42,8 @@ class Histogram(object):
return '{%s}' % ','.join(values)
class ConstantBinScheme(object):
__slots__ = ('_min', '_max', '_bins', '_bucket_width')
def __init__(self, bins, min_val, max_val):
if bins < 2:
raise ValueError('Must have at least 2 bins.')
@@ -69,6 +73,8 @@ class Histogram(object):
return int(((x - self._min) / self._bucket_width) + 1)
class LinearBinScheme(object):
__slots__ = ('_bins', '_max', '_scale')
def __init__(self, num_bins, max_val):
self._bins = num_bins
self._max = max_val

View File

@@ -5,6 +5,8 @@ from kafka.metrics.stats.sampled_stat import AbstractSampledStat
class Max(AbstractSampledStat):
"""An AbstractSampledStat that gives the max over its samples."""
__slots__ = ('_initial_value', '_samples', '_current')
def __init__(self):
super(Max, self).__init__(float('-inf'))

View File

@@ -7,6 +7,8 @@ from kafka.metrics.stats.sampled_stat import AbstractSampledStat
class Min(AbstractSampledStat):
"""An AbstractSampledStat that gives the min over its samples."""
__slots__ = ('_initial_value', '_samples', '_current')
def __init__(self):
super(Min, self).__init__(float(sys.maxsize))

View File

@@ -2,6 +2,8 @@ from __future__ import absolute_import
class Percentile(object):
__slots__ = ('_metric_name', '_percentile')
def __init__(self, metric_name, percentile):
self._metric_name = metric_name
self._percentile = float(percentile)

View File

@@ -13,6 +13,9 @@ class BucketSizing(object):
class Percentiles(AbstractSampledStat, AbstractCompoundStat):
"""A compound stat that reports one or more percentiles"""
__slots__ = ('_initial_value', '_samples', '_current',
'_percentiles', '_buckets', '_bin_scheme')
def __init__(self, size_in_bytes, bucketing, max_val, min_val=0.0,
percentiles=None):
super(Percentiles, self).__init__(0.0)
@@ -27,7 +30,7 @@ class Percentiles(AbstractSampledStat, AbstractCompoundStat):
' to be 0.0.')
self.bin_scheme = Histogram.LinearBinScheme(self._buckets, max_val)
else:
ValueError('Unknown bucket type: %s' % (bucketing,))
raise ValueError('Unknown bucket type: %s' % (bucketing,))
def stats(self):
measurables = []

View File

@@ -37,6 +37,8 @@ class Rate(AbstractMeasurableStat):
occurrences (e.g. the count of values measured over the time interval)
or other such values.
"""
__slots__ = ('_stat', '_unit')
def __init__(self, time_unit=TimeUnit.SECONDS, sampled_stat=None):
self._stat = sampled_stat or SampledTotal()
self._unit = time_unit
@@ -105,6 +107,7 @@ class Rate(AbstractMeasurableStat):
class SampledTotal(AbstractSampledStat):
__slots__ = ('_initial_value', '_samples', '_current')
def __init__(self, initial_value=None):
if initial_value is not None:
raise ValueError('initial_value cannot be set on SampledTotal')

View File

@@ -3,8 +3,10 @@ from __future__ import absolute_import
import abc
from kafka.metrics.measurable_stat import AbstractMeasurableStat
from kafka.vendor.six import add_metaclass
@add_metaclass(abc.ABCMeta)
class AbstractSampledStat(AbstractMeasurableStat):
"""
An AbstractSampledStat records a single scalar value measured over
@@ -20,7 +22,7 @@ class AbstractSampledStat(AbstractMeasurableStat):
Subclasses of this class define different statistics measured
using this basic pattern.
"""
__metaclass__ = abc.ABCMeta
__slots__ = ('_initial_value', '_samples', '_current')
def __init__(self, initial_value):
self._initial_value = initial_value

View File

@@ -15,6 +15,10 @@ class Sensor(object):
the `record(double)` api and would maintain a set
of metrics about request sizes such as the average or max.
"""
__slots__ = ('_lock', '_registry', '_name', '_parents', '_metrics',
'_stats', '_config', '_inactive_sensor_expiration_time_ms',
'_last_record_time')
def __init__(self, registry, name, parents, config,
inactive_sensor_expiration_time_seconds):
if not name:

View File

@@ -5,6 +5,8 @@ from kafka.metrics.measurable_stat import AbstractMeasurableStat
class Total(AbstractMeasurableStat):
"""An un-windowed cumulative total maintained over all time."""
__slots__ = ('_total')
def __init__(self, value=0.0):
self._total = value