|
35 | 35 | from typing import Type |
36 | 36 | from typing import Union |
37 | 37 |
|
38 | | -from apache_beam.internal.metrics.cells import HistogramCellFactory |
39 | 38 | from apache_beam.metrics import monitoring_infos |
40 | | -from apache_beam.metrics.execution import MetricUpdater |
41 | 39 | from apache_beam.metrics.metric import Metrics as UserMetrics |
42 | | -from apache_beam.metrics.metricbase import Histogram |
43 | 40 | from apache_beam.metrics.metricbase import MetricName |
44 | 41 |
|
45 | 42 | if TYPE_CHECKING: |
46 | 43 | from apache_beam.metrics.cells import MetricCell |
47 | 44 | from apache_beam.metrics.cells import MetricCellFactory |
48 | | - from apache_beam.utils.histogram import BucketType |
49 | 45 |
|
50 | 46 | # Protect against environments where bigquery library is not available. |
51 | 47 | # pylint: disable=wrong-import-order, wrong-import-position |
@@ -82,46 +78,6 @@ def counter( |
82 | 78 | MetricName(namespace=None, name=None, urn=urn, labels=labels), |
83 | 79 | process_wide=process_wide) |
84 | 80 |
|
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 | | - |
125 | 81 |
|
126 | 82 | class MetricLogger(object): |
127 | 83 | """Simple object to locally aggregate and log metrics.""" |
|
0 commit comments