Skip to content

Commit 64a92b2

Browse files
authored
[python] Move histogram metric from internal to public interface/files (#36405)
1 parent 7bfe0e1 commit 64a92b2

File tree

12 files changed

+277
-428
lines changed

12 files changed

+277
-428
lines changed

sdks/python/apache_beam/internal/metrics/cells.py

Lines changed: 0 additions & 165 deletions
This file was deleted.

sdks/python/apache_beam/internal/metrics/cells_test.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

sdks/python/apache_beam/internal/metrics/metric.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@
3535
from typing import Type
3636
from typing import Union
3737

38-
from apache_beam.internal.metrics.cells import HistogramCellFactory
3938
from apache_beam.metrics import monitoring_infos
40-
from apache_beam.metrics.execution import MetricUpdater
4139
from apache_beam.metrics.metric import Metrics as UserMetrics
42-
from apache_beam.metrics.metricbase import Histogram
4340
from apache_beam.metrics.metricbase import MetricName
4441

4542
if TYPE_CHECKING:
4643
from apache_beam.metrics.cells import MetricCell
4744
from apache_beam.metrics.cells import MetricCellFactory
48-
from apache_beam.utils.histogram import BucketType
4945

5046
# Protect against environments where bigquery library is not available.
5147
# pylint: disable=wrong-import-order, wrong-import-position
@@ -82,46 +78,6 @@ def counter(
8278
MetricName(namespace=None, name=None, urn=urn, labels=labels),
8379
process_wide=process_wide)
8480

85-
@staticmethod
86-
def histogram(
87-
namespace: Union[Type, str],
88-
name: str,
89-
bucket_type: 'BucketType',
90-
logger: Optional['MetricLogger'] = None) -> 'Metrics.DelegatingHistogram':
91-
"""Obtains or creates a Histogram metric.
92-
93-
Args:
94-
namespace: A class or string that gives the namespace to a metric
95-
name: A string that gives a unique name to a metric
96-
bucket_type: A type of bucket used in a histogram. A subclass of
97-
apache_beam.utils.histogram.BucketType
98-
logger: MetricLogger for logging locally aggregated metric
99-
100-
Returns:
101-
A Histogram object.
102-
"""
103-
namespace = UserMetrics.get_namespace(namespace)
104-
return Metrics.DelegatingHistogram(
105-
MetricName(namespace, name), bucket_type, logger)
106-
107-
class DelegatingHistogram(Histogram):
108-
"""Metrics Histogram that Delegates functionality to MetricsEnvironment."""
109-
def __init__(
110-
self,
111-
metric_name: MetricName,
112-
bucket_type: 'BucketType',
113-
logger: Optional['MetricLogger']) -> None:
114-
super().__init__(metric_name)
115-
self.metric_name = metric_name
116-
self.cell_type = HistogramCellFactory(bucket_type)
117-
self.logger = logger
118-
self.updater = MetricUpdater(self.cell_type, self.metric_name)
119-
120-
def update(self, value: object) -> None:
121-
self.updater(value)
122-
if self.logger:
123-
self.logger.update(self.cell_type, self.metric_name, value)
124-
12581

12682
class MetricLogger(object):
12783
"""Simple object to locally aggregate and log metrics."""

0 commit comments

Comments
 (0)