[ 
https://issues.apache.org/jira/browse/BEAM-4374?focusedWorklogId=153787&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-153787
 ]

ASF GitHub Bot logged work on BEAM-4374:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Oct/18 07:20
            Start Date: 12/Oct/18 07:20
    Worklog Time Spent: 10m 
      Work Description: robertwb commented on a change in pull request #6205: 
[BEAM-4374] Implementing a subset of the new metrics framework in python.
URL: https://github.com/apache/beam/pull/6205#discussion_r224691628
 
 

 ##########
 File path: sdks/python/apache_beam/metrics/monitoring_infos.py
 ##########
 @@ -0,0 +1,246 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# cython: language_level=3
+# cython: profile=True
+
+from __future__ import absolute_import
+
+import time
+
+from google.protobuf import timestamp_pb2
+
+from apache_beam.metrics.cells import DistributionData
+from apache_beam.metrics.cells import DistributionResult
+from apache_beam.metrics.cells import GaugeData
+from apache_beam.metrics.cells import GaugeResult
+from apache_beam.portability import common_urns
+from apache_beam.portability.api.beam_fn_api_pb2 import CounterData
+from apache_beam.portability.api.beam_fn_api_pb2 import Metric
+from apache_beam.portability.api.beam_fn_api_pb2 import MonitoringInfo
+
+ELEMENT_COUNT_URN = common_urns.monitoring_infos.ELEMENT_COUNT.urn
+START_BUNDLE_MSECS_URN = common_urns.monitoring_infos.START_BUNDLE_MSECS.urn
+PROCESS_BUNDLE_MSECS_URN = 
common_urns.monitoring_infos.PROCESS_BUNDLE_MSECS.urn
+FINISH_BUNDLE_MSECS_URN = common_urns.monitoring_infos.FINISH_BUNDLE_MSECS.urn
+TOTAL_MSECS_URN = common_urns.monitoring_infos.TOTAL_MSECS.urn
+USER_COUNTER_URN_PREFIX = (
+    common_urns.monitoring_infos.USER_COUNTER_URN_PREFIX.urn)
+
+# TODO(ajamato): Implement the remaining types, i.e. Double types
+# Extrema types, etc. See:
+# https://s.apache.org/beam-fn-api-metrics
+SUM_INT64_TYPE = common_urns.monitoring_info_types.SUM_INT64_TYPE.urn
+DISTRIBUTION_INT64_TYPE = (
+    common_urns.monitoring_info_types.DISTRIBUTION_INT64_TYPE.urn)
+LATEST_INT64_TYPE = common_urns.monitoring_info_types.LATEST_INT64_TYPE.urn
+
+COUNTER_TYPES = set([SUM_INT64_TYPE])
+DISTRIBUTION_TYPES = set([DISTRIBUTION_INT64_TYPE])
+GAUGE_TYPES = set([LATEST_INT64_TYPE])
+
+
+def to_timestamp_proto(timestamp_secs):
+  """Converts seconds since epoch to a google.protobuf.Timestamp.
+
+  Args:
+    timestamp_secs: The timestamp in seconds since epoch.
+  """
+  seconds = int(timestamp_secs)
+  nanos = int((timestamp_secs - seconds) * 10**9)
+  return timestamp_pb2.Timestamp(seconds=seconds, nanos=nanos)
+
+
+def to_timestamp_secs(timestamp_proto):
+  """Converts a google.protobuf.Timestamp to seconds since epoch.
+
+  Args:
+    timestamp_proto: The google.protobuf.Timestamp.
+  """
+  return timestamp_proto.seconds + timestamp_proto.nanos * 10**-9
+
+
+def extract_counter_value(monitoring_info_proto):
+  """Returns the int coutner value of the monitoring info."""
+  if is_counter(monitoring_info_proto) or is_gauge(monitoring_info_proto):
+    return monitoring_info_proto.metric.counter_data.int64_value
+  return None
+
+
+def extract_distribution(monitoring_info_proto):
+  """Returns the relevant DistributionInt64 or DistributionDouble.
+
+  Args:
+    monitoring_info_proto: The monitoring infor for the distribution.
+  """
+  if is_distribution(monitoring_info_proto):
+    return monitoring_info_proto.metric.distribution_data.int_distribution_data
+  return None
+
+
+def create_labels(ptransform='', tag=''):
+  """Create the label dictionary based on the provided tags.
+
+  Args:
+    ptransform: The ptransform/step name.
+    tag: he output tag name, used as a label.
+  """
+  labels = {}
+  if tag:
+    labels['TAG'] = tag
+  if ptransform:
+    labels['PTRANSFORM'] = ptransform
+  return labels
+
+
+def int64_counter(urn, metric, ptransform='', tag=''):
 
 Review comment:
   This code feels very repetitive; isn't this excactly the kind of thing we 
should be pulling out of the yaml file? 

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 153787)
    Time Spent: 7h 20m  (was: 7h 10m)

> Update existing metrics in the FN API to use new Metric Schema
> --------------------------------------------------------------
>
>                 Key: BEAM-4374
>                 URL: https://issues.apache.org/jira/browse/BEAM-4374
>             Project: Beam
>          Issue Type: New Feature
>          Components: beam-model
>            Reporter: Alex Amato
>            Priority: Major
>          Time Spent: 7h 20m
>  Remaining Estimate: 0h
>
> Update existing metrics to use the new proto and cataloging schema defined in:
> [_https://s.apache.org/beam-fn-api-metrics_]
>  * Check in new protos
>  * Define catalog file for metrics
>  * Port existing metrics to use this new format, based on catalog 
> names+metadata



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to