dianfu commented on a change in pull request #11543: [FLINK-16672][python] 
Support Counter, Gauge, Meter, Distribution metric type for Python UDF
URL: https://github.com/apache/flink/pull/11543#discussion_r399302874
 
 

 ##########
 File path: flink-python/pyflink/metrics/metricbase.py
 ##########
 @@ -76,3 +107,97 @@ def add_group(self, name: str, extra: str = None) -> 
'MetricGroup':
         else:
             return self._add_group(name, MetricGroupType.key)\
                 ._add_group(extra, MetricGroupType.value)
+
+    def counter(self, name: str) -> 'Counter':
+        from apache_beam.metrics.metric import Metrics
+        return Counter(Metrics.counter(self._get_namespace(), name))
+
+    def gauge(self, name: str, obj: Callable[[], int]) -> None:
+        from apache_beam.metrics.metric import Metrics
+        self._flink_gauge[name] = obj
+        self._beam_gauge[name] = Metrics.gauge(self._get_namespace(), name)
+
+    def meter(self, name: str, time_span_in_seconds: int = 60) -> 'Meter':
+        from apache_beam.metrics.metric import Metrics
+        # There is no meter type in Beam, use counter to implement meter
+        return Meter(
+            Metrics.counter(self._get_namespace(time_span_in_seconds), name),
+            time_span_in_seconds)
+
+    def distribution(self, name: str) -> 'Distribution':
+        from apache_beam.metrics.metric import Metrics
+        return Distribution(Metrics.distribution(self._get_namespace(), name))
+
+    def _get_metric_group_names_and_types(self) -> ([], []):
+        if self._name is None:
+            return [], []
+        else:
+            names, types = self._parent._get_metric_group_names_and_types()
+            names.append(self._name)
+            types.append(str(self._metric_group_type))
+            return names, types
+
+    def _get_namespace(self, time=None) -> str:
+        (names, metric_group_type) = self._get_metric_group_names_and_types()
 
 Review comment:
   The parenthese could be removed

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to