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

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

                Author: ASF GitHub Bot
            Created on: 06/Feb/20 17:24
            Start Date: 06/Feb/20 17:24
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on pull request #10777: [BEAM-3545] 
Return metrics as MonitoringInfos
URL: https://github.com/apache/beam/pull/10777#discussion_r375973824
 
 

 ##########
 File path: sdks/go/pkg/beam/core/runtime/harness/monitoring.go
 ##########
 @@ -0,0 +1,195 @@
+// 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.
+
+package harness
+
+import (
+       "time"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/core/metrics"
+       "github.com/apache/beam/sdks/go/pkg/beam/core/runtime/exec"
+       fnpb "github.com/apache/beam/sdks/go/pkg/beam/model/fnexecution_v1"
+       ppb "github.com/apache/beam/sdks/go/pkg/beam/model/pipeline_v1"
+       "github.com/golang/protobuf/ptypes"
+)
+
+func monitoring(p *exec.Plan) (*fnpb.Metrics, []*ppb.MonitoringInfo) {
+       // Get the legacy style metrics.
+       transforms := make(map[string]*fnpb.Metrics_PTransform)
+       metrics.Extractor{
+               SumInt64: func(l metrics.Labels, v int64) {
+                       pb := getTransform(transforms, l)
+                       pb.User = append(pb.User, &fnpb.Metrics_User{
+                               MetricName: toName(l),
+                               Data: &fnpb.Metrics_User_CounterData_{
+                                       CounterData: 
&fnpb.Metrics_User_CounterData{
+                                               Value: v,
+                                       },
+                               },
+                       })
+               },
+               DistributionInt64: func(l metrics.Labels, count, sum, min, max 
int64) {
+                       pb := getTransform(transforms, l)
+                       pb.User = append(pb.User, &fnpb.Metrics_User{
+                               MetricName: toName(l),
+                               Data: &fnpb.Metrics_User_DistributionData_{
+                                       DistributionData: 
&fnpb.Metrics_User_DistributionData{
+                                               Count: count,
+                                               Sum:   sum,
+                                               Min:   min,
+                                               Max:   max,
+                                       },
+                               },
+                       })
+               },
+               GaugeInt64: func(l metrics.Labels, v int64, t time.Time) {
+                       ts, err := ptypes.TimestampProto(t)
+                       if err != nil {
+                               panic(err)
+                       }
+                       pb := getTransform(transforms, l)
+                       pb.User = append(pb.User, &fnpb.Metrics_User{
+                               MetricName: toName(l),
+                               Data: &fnpb.Metrics_User_GaugeData_{
+                                       GaugeData: &fnpb.Metrics_User_GaugeData{
+                                               Value:     v,
+                                               Timestamp: ts,
+                                       },
+                               },
+                       })
+               },
+       }.ExtractFrom(p.Store)
+
+       // Get the MonitoringInfo versions.
+       var monitoringInfo []*ppb.MonitoringInfo
+       metrics.Extractor{
+               SumInt64: func(l metrics.Labels, v int64) {
+                       monitoringInfo = append(monitoringInfo,
+                               &ppb.MonitoringInfo{
+                                       Urn:    "beam:metric:user",
+                                       Type:   "beam:metrics:sum_int_64",
+                                       Labels: userLabels(l),
+                                       Data:   int64Counter(v),
+                               })
+               },
+               DistributionInt64: func(l metrics.Labels, count, sum, min, max 
int64) {
+                       monitoringInfo = append(monitoringInfo,
+                               &ppb.MonitoringInfo{
+                                       Urn:    "beam:metric:user",
+                                       Type:   "beam:metrics:sum_int_64",
+                                       Labels: userLabels(l),
+                                       Data:   int64Distribution(count, sum, 
min, max),
+                               })
+               },
+               GaugeInt64: func(l metrics.Labels, v int64, t time.Time) {
+                       ts, err := ptypes.TimestampProto(t)
+                       if err != nil {
+                               panic(err)
+                       }
+                       monitoringInfo = append(monitoringInfo,
+                               &ppb.MonitoringInfo{
+                                       Type:      "beam:metrics:latest_int_64",
+                                       Labels:    userLabels(l),
+                                       Data:      int64Counter(v),
+                                       Timestamp: ts,
+                               })
+               },
+       }.ExtractFrom(p.Store)
+
+       // Get the execution monitoring information from the bundle plan.
+       if snapshot, ok := p.Progress(); ok {
+               // Legacy version.
+               transforms[snapshot.ID] = &fnpb.Metrics_PTransform{
+                       ProcessedElements: 
&fnpb.Metrics_PTransform_ProcessedElements{
+                               Measured: &fnpb.Metrics_PTransform_Measured{
+                                       OutputElementCounts: map[string]int64{
+                                               snapshot.Name: snapshot.Count,
+                                       },
+                               },
+                       },
+               }
+               // Monitoring info version.
+               monitoringInfo = append(monitoringInfo,
+                       &ppb.MonitoringInfo{
+                               Urn:  "beam:metric:element_count:v1",
+                               Type: "beam:metrics:sum_int_64",
+                               Labels: map[string]string{
+                                       "PCOLLECTION": snapshot.Name,
 
 Review comment:
   This should be the PCollection id
 
----------------------------------------------------------------
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]


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

    Worklog Id:     (was: 382987)
    Time Spent: 14h 40m  (was: 14.5h)

> Fn API metrics in Go SDK harness
> --------------------------------
>
>                 Key: BEAM-3545
>                 URL: https://issues.apache.org/jira/browse/BEAM-3545
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-go
>            Reporter: Kenneth Knowles
>            Assignee: Robert Burke
>            Priority: Major
>              Labels: portability
>          Time Spent: 14h 40m
>  Remaining Estimate: 0h
>




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

Reply via email to