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

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

                Author: ASF GitHub Bot
            Created on: 28/Oct/19 16:12
            Start Date: 28/Oct/19 16:12
    Worklog Time Spent: 10m 
      Work Description: Ardagan commented on pull request #9843: [BEAM-4775] 
Converting MonitoringInfos to MetricResults in PortableRunner
URL: https://github.com/apache/beam/pull/9843#discussion_r339651872
 
 

 ##########
 File path: sdks/python/apache_beam/runners/portability/portable_metrics.py
 ##########
 @@ -22,53 +22,44 @@
 from apache_beam.metrics.metric import MetricName
 
 
-class ParseMonitoringInfoMixin(object):
-  @staticmethod
-  def from_monitoring_infos(monitoring_info_list, user_metrics_only=False):
-    """Groups MonitoringInfo objects into counters, distributions and gauges.
+def from_monitoring_infos(monitoring_info_list, user_metrics_only=False):
+  """Groups MonitoringInfo objects into counters, distributions and gauges.
 
-    Args:
-      monitoring_info_list: An iterable of MonitoringInfo objects.
-      user_metrics_only: If true, includes user metrics only.
-    """
-    counters = {}
-    distributions = {}
-    gauges = {}
+  Args:
+    monitoring_info_list: An iterable of MonitoringInfo objects.
+    user_metrics_only: If true, includes user metrics only.
+  Returns:
+    A tuple containing three dictionaries: counters, distributions and gauges,
+    respectively. Each dictionary contains (MetricKey, metric result) pairs.
+  """
+  counters = {}
+  distributions = {}
+  gauges = {}
 
-    for mi in monitoring_info_list:
-      if (user_metrics_only and
-          not monitoring_infos.is_user_monitoring_info(mi)):
-        continue
+  for mi in monitoring_info_list:
+    if (user_metrics_only and
+        not monitoring_infos.is_user_monitoring_info(mi)):
+      continue
 
-      key = ParseMonitoringInfoMixin._create_metric_key(mi)
-      metric_result = (monitoring_infos.extract_metric_result_map_value(mi))
+    try:
+      key = _create_metric_key(mi)
+    except ValueError:
+      continue
+    metric_result = (monitoring_infos.extract_metric_result_map_value(mi))
 
-      if monitoring_infos.is_counter(mi):
-        counters[key] = metric_result
-      elif monitoring_infos.is_distribution(mi):
-        distributions[key] = metric_result
-      elif monitoring_infos.is_gauge(mi):
-        gauges[key] = metric_result
+    if monitoring_infos.is_counter(mi):
+      counters[key] = metric_result
+    elif monitoring_infos.is_distribution(mi):
+      distributions[key] = metric_result
+    elif monitoring_infos.is_gauge(mi):
+      gauges[key] = metric_result
 
-    return counters, distributions, gauges
+  return counters, distributions, gauges
 
-  @staticmethod
-  def _create_metric_key(monitoring_info):
-    step_name = ParseMonitoringInfoMixin._get_step_name(monitoring_info)
-    namespace, name = 
monitoring_infos.parse_namespace_and_name(monitoring_info)
-    return MetricKey(step_name, MetricName(namespace, name))
 
-  @staticmethod
-  def _get_step_name(monitoring_info):
-    keys_to_check = [monitoring_infos.PTRANSFORM_LABEL,
-                     monitoring_infos.PCOLLECTION_LABEL,
-                     'WINDOWING_STRATEGY',
-                     'CODER',
-                     'ENVIRONMENT',
-                    ]
-
-    for key in keys_to_check:
-      value = monitoring_info.labels.get(key)
-      if value:
-        return value
-    return ''
+def _create_metric_key(monitoring_info):
+  step_name = monitoring_infos.get_step_name(monitoring_info)
+  if not step_name:
+    raise ValueError("Step name is empty")
 
 Review comment:
   Dump monitoring info to error message. Otherwise this error is 
indescriptive. Ideally change text to what you expect here, for example: 
"Monitoring info should contain XXX field. Monitoring info: {}" or in this case 
it can be: "Failed to deduce step_name from MonitoringInfo: {}"
 
----------------------------------------------------------------
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:
us...@infra.apache.org


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

    Worklog Id:     (was: 334997)
    Time Spent: 53h 40m  (was: 53.5h)

> JobService should support returning metrics
> -------------------------------------------
>
>                 Key: BEAM-4775
>                 URL: https://issues.apache.org/jira/browse/BEAM-4775
>             Project: Beam
>          Issue Type: Bug
>          Components: beam-model
>            Reporter: Eugene Kirpichov
>            Assignee: Kamil Wasilewski
>            Priority: Major
>          Time Spent: 53h 40m
>  Remaining Estimate: 0h
>
> Design doc: [https://s.apache.org/get-metrics-api].
> Further discussion is ongoing on [this 
> doc|https://docs.google.com/document/d/1m83TsFvJbOlcLfXVXprQm1B7vUakhbLZMzuRrOHWnTg/edit?ts=5c826bb4#heading=h.faqan9rjc6dm].
> We want to report job metrics back to the portability harness from the runner 
> harness, for displaying to users.
> h1. Relevant PRs in flight:
> h2. Ready for Review:
>  * [#8022|https://github.com/apache/beam/pull/8022]: correct the Job RPC 
> protos from [#8018|https://github.com/apache/beam/pull/8018].
> h2. Iterating / Discussing:
>  * [#7971|https://github.com/apache/beam/pull/7971]: Flink portable metrics: 
> get ptransform from MonitoringInfo, not stage name
>  ** this is a simpler, Flink-specific PR that is basically duplicated inside 
> each of the following two, so may be worth trying to merge in first
>  * #[7915|https://github.com/apache/beam/pull/7915]: use MonitoringInfo data 
> model in Java SDK metrics
>  * [#7868|https://github.com/apache/beam/pull/7868]: MonitoringInfo URN tweaks
> h2. Merged
>  * [#8018|https://github.com/apache/beam/pull/8018]: add job metrics RPC 
> protos
>  * [#7867|https://github.com/apache/beam/pull/7867]: key MetricResult by a 
> MetricKey
>  * [#7938|https://github.com/apache/beam/pull/7938]: move MonitoringInfo 
> protos to model/pipeline module
>  * [#7883|https://github.com/apache/beam/pull/7883]: Add 
> MetricQueryResults.allMetrics() helper
>  * [#7866|https://github.com/apache/beam/pull/7866]: move function helpers 
> from fn-harness to sdks/java/core
>  * [#7890|https://github.com/apache/beam/pull/7890]: consolidate MetricResult 
> implementations
> h2. Closed
>  * [#7934|https://github.com/apache/beam/pull/7934]: job metrics RPC + SDK 
> support
>  * [#7876|https://github.com/apache/beam/pull/7876]: Clean up metric protos; 
> support integer distributions, gauges



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to