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

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

                Author: ASF GitHub Bot
            Created on: 06/Aug/21 01:02
            Start Date: 06/Aug/21 01:02
    Worklog Time Spent: 10m 
      Work Description: ajamato commented on a change in pull request #15289:
URL: https://github.com/apache/beam/pull/15289#discussion_r683867941



##########
File path: sdks/go/pkg/beam/core/runtime/harness/monitoring.go
##########
@@ -163,38 +162,65 @@ func monitoring(p *exec.Plan) ([]*pipepb.MonitoringInfo, 
map[string][]byte) {
        }.ExtractFrom(store)
 
        // Get the execution monitoring information from the bundle plan.
-       if snapshot, ok := p.Progress(); ok {
-               payload, err := metricsx.Int64Counter(snapshot.Count)
+
+       snapshot, ok := p.Progress()
+       if !ok {
+               return monitoringInfo, payloads
+       }
+       for _, pcol := range snapshot.PCols {
+               payload, err := metricsx.Int64Counter(pcol.ElementCount)
                if err != nil {
                        panic(err)
                }
 
                // TODO(BEAM-9934): This metric should account for elements in 
multiple windows.
-               payloads[getShortID(metrics.PCollectionLabels(snapshot.PID), 
metricsx.UrnElementCount)] = payload
+               payloads[getShortID(metrics.PCollectionLabels(pcol.ID), 
metricsx.UrnElementCount)] = payload
+
                monitoringInfo = append(monitoringInfo,
                        &pipepb.MonitoringInfo{
                                Urn:  
metricsx.UrnToString(metricsx.UrnElementCount),
                                Type: 
metricsx.UrnToType(metricsx.UrnElementCount),
                                Labels: map[string]string{
-                                       "PCOLLECTION": snapshot.PID,
+                                       "PCOLLECTION": pcol.ID,
                                },
                                Payload: payload,
                        })
 
-               payloads[getShortID(metrics.PTransformLabels(snapshot.ID), 
metricsx.UrnDataChannelReadIndex)] = payload
-               monitoringInfo = append(monitoringInfo,
-                       &pipepb.MonitoringInfo{
-                               Urn:  
metricsx.UrnToString(metricsx.UrnDataChannelReadIndex),
-                               Type: 
metricsx.UrnToType(metricsx.UrnDataChannelReadIndex),
-                               Labels: map[string]string{
-                                       "PTRANSFORM": snapshot.ID,
-                               },
-                               Payload: payload,
-                       })
+               // Skip pcollections without size
+               if pcol.SizeCount != 0 {
+                       payload, err := 
metricsx.Int64Distribution(pcol.SizeCount, pcol.SizeSum, pcol.SizeMin, 
pcol.SizeMax)
+                       if err != nil {
+                               panic(err)
+                       }
+                       monitoringInfo = append(monitoringInfo,
+                               &pipepb.MonitoringInfo{
+                                       Urn:  
"beam:metric:sampled_byte_size:v1",
+                                       Type: 
"beam:metrics:distribution_int_64",
+                                       Labels: map[string]string{
+                                               "PCOLLECTION": pcol.ID,

Review comment:
       This must be the exact same string as the pcollection id passed into the 
ProcessBundleDescriptor
   
   
https://github.com/apache/beam/blob/243128a8fc52798e1b58b0cf1a271d95ee7aa241/model/fn-execution/src/main/proto/beam_fn_api.proto#L198

##########
File path: sdks/go/pkg/beam/core/runtime/harness/monitoring.go
##########
@@ -163,38 +162,65 @@ func monitoring(p *exec.Plan) ([]*pipepb.MonitoringInfo, 
map[string][]byte) {
        }.ExtractFrom(store)
 
        // Get the execution monitoring information from the bundle plan.
-       if snapshot, ok := p.Progress(); ok {
-               payload, err := metricsx.Int64Counter(snapshot.Count)
+
+       snapshot, ok := p.Progress()
+       if !ok {
+               return monitoringInfo, payloads
+       }
+       for _, pcol := range snapshot.PCols {
+               payload, err := metricsx.Int64Counter(pcol.ElementCount)
                if err != nil {
                        panic(err)
                }
 
                // TODO(BEAM-9934): This metric should account for elements in 
multiple windows.
-               payloads[getShortID(metrics.PCollectionLabels(snapshot.PID), 
metricsx.UrnElementCount)] = payload
+               payloads[getShortID(metrics.PCollectionLabels(pcol.ID), 
metricsx.UrnElementCount)] = payload
+
                monitoringInfo = append(monitoringInfo,
                        &pipepb.MonitoringInfo{
                                Urn:  
metricsx.UrnToString(metricsx.UrnElementCount),
                                Type: 
metricsx.UrnToType(metricsx.UrnElementCount),
                                Labels: map[string]string{
-                                       "PCOLLECTION": snapshot.PID,
+                                       "PCOLLECTION": pcol.ID,
                                },
                                Payload: payload,
                        })
 
-               payloads[getShortID(metrics.PTransformLabels(snapshot.ID), 
metricsx.UrnDataChannelReadIndex)] = payload
-               monitoringInfo = append(monitoringInfo,
-                       &pipepb.MonitoringInfo{
-                               Urn:  
metricsx.UrnToString(metricsx.UrnDataChannelReadIndex),
-                               Type: 
metricsx.UrnToType(metricsx.UrnDataChannelReadIndex),
-                               Labels: map[string]string{
-                                       "PTRANSFORM": snapshot.ID,
-                               },
-                               Payload: payload,
-                       })
+               // Skip pcollections without size
+               if pcol.SizeCount != 0 {
+                       payload, err := 
metricsx.Int64Distribution(pcol.SizeCount, pcol.SizeSum, pcol.SizeMin, 
pcol.SizeMax)
+                       if err != nil {
+                               panic(err)
+                       }
+                       monitoringInfo = append(monitoringInfo,
+                               &pipepb.MonitoringInfo{
+                                       Urn:  
"beam:metric:sampled_byte_size:v1",
+                                       Type: 
"beam:metrics:distribution_int_64",

Review comment:
       Maybe use the same pattern as above
   
   Urn:  metricsx.UrnToString(metricsx.UrnSampledByteSize),
   Type: metricsx.UrnToType(metricsx.UrnSampledByteSize),

##########
File path: sdks/go/pkg/beam/core/runtime/harness/harness.go
##########
@@ -305,7 +313,7 @@ func (c *control) handleInstruction(ctx context.Context, 
req *fnpb.InstructionRe
                data.Close()
                state.Close()
 
-               mons, pylds := monitoring(plan)
+               mons, pylds := monitoring(plan, store)

Review comment:
       Just an FYI
   You only should populate ProcessBundleResponse's monitoring_data. And should 
NOT populate monitoring_infos which is deprecated.
   
https://github.com/apache/beam/blob/243128a8fc52798e1b58b0cf1a271d95ee7aa241/model/fn-execution/src/main/proto/beam_fn_api.proto#L328
   
   You will need to implement the MonitoringInfoMetadataResposne instruction 
for the InstructionRequest/Response
   
https://github.com/apache/beam/blob/243128a8fc52798e1b58b0cf1a271d95ee7aa241/model/fn-execution/src/main/proto/beam_fn_api.proto#L138
   On the MonitoringInfosMetadataResponse you will provide full MonitoringInfos.
   This is the optimization to prevent sending all that data on every 
ProcessBundle[Progress]Response
   
   
   
   
   (I'm a bit unclear on what's being done with short ids here. You may already 
be doing this correctly)

##########
File path: sdks/go/pkg/beam/core/runtime/exec/pcollection.go
##########
@@ -0,0 +1,153 @@
+// 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 exec
+
+import (
+       "context"
+       "fmt"
+       "math"
+       "math/rand"
+       "sync"
+       "sync/atomic"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/core/graph/coder"
+)
+
+// PCollection is a passthrough node to collect PCollection metrics, and
+// must be placed as the Out node of any producer of a PCollection.
+//
+// In particular, must not be placed after a Multiplex, and must be placed
+// after a Flatten.
+type PCollection struct {

Review comment:
       FWIW here are the implementations in java and python
   https://github.com/apache/beam/pull/8416
   
   
https://github.com/apache/beam/commit/d807210c3aa28f34c13b89f3f16bc104051532b0
   
   I dunno if you really need to introduce a PCollection abstraction for it. 
There might be simpler ways.
   
   I also will point out that it may not be wise to run the coder on every 
element. Instead run it on a random sample of elements only. Doing it on every 
element will degrade performance.
   
   I believe the algorithm in java was to record the first N elements. Then 
randomly record elements with smaller and smaller frequency based on the number 
of elements which were already sampled.

##########
File path: sdks/go/pkg/beam/core/runtime/harness/monitoring.go
##########
@@ -163,38 +162,65 @@ func monitoring(p *exec.Plan) ([]*pipepb.MonitoringInfo, 
map[string][]byte) {
        }.ExtractFrom(store)
 
        // Get the execution monitoring information from the bundle plan.
-       if snapshot, ok := p.Progress(); ok {
-               payload, err := metricsx.Int64Counter(snapshot.Count)
+
+       snapshot, ok := p.Progress()
+       if !ok {
+               return monitoringInfo, payloads
+       }
+       for _, pcol := range snapshot.PCols {
+               payload, err := metricsx.Int64Counter(pcol.ElementCount)
                if err != nil {
                        panic(err)
                }
 
                // TODO(BEAM-9934): This metric should account for elements in 
multiple windows.
-               payloads[getShortID(metrics.PCollectionLabels(snapshot.PID), 
metricsx.UrnElementCount)] = payload
+               payloads[getShortID(metrics.PCollectionLabels(pcol.ID), 
metricsx.UrnElementCount)] = payload
+
                monitoringInfo = append(monitoringInfo,
                        &pipepb.MonitoringInfo{
                                Urn:  
metricsx.UrnToString(metricsx.UrnElementCount),
                                Type: 
metricsx.UrnToType(metricsx.UrnElementCount),
                                Labels: map[string]string{
-                                       "PCOLLECTION": snapshot.PID,
+                                       "PCOLLECTION": pcol.ID,
                                },
                                Payload: payload,
                        })
 
-               payloads[getShortID(metrics.PTransformLabels(snapshot.ID), 
metricsx.UrnDataChannelReadIndex)] = payload
-               monitoringInfo = append(monitoringInfo,
-                       &pipepb.MonitoringInfo{
-                               Urn:  
metricsx.UrnToString(metricsx.UrnDataChannelReadIndex),
-                               Type: 
metricsx.UrnToType(metricsx.UrnDataChannelReadIndex),
-                               Labels: map[string]string{
-                                       "PTRANSFORM": snapshot.ID,
-                               },
-                               Payload: payload,
-                       })
+               // Skip pcollections without size
+               if pcol.SizeCount != 0 {
+                       payload, err := 
metricsx.Int64Distribution(pcol.SizeCount, pcol.SizeSum, pcol.SizeMin, 
pcol.SizeMax)
+                       if err != nil {
+                               panic(err)
+                       }
+                       monitoringInfo = append(monitoringInfo,
+                               &pipepb.MonitoringInfo{
+                                       Urn:  
"beam:metric:sampled_byte_size:v1",
+                                       Type: 
"beam:metrics:distribution_int_64",
+                                       Labels: map[string]string{
+                                               "PCOLLECTION": pcol.ID,

Review comment:
       Otherwise looks like it matches the spec :)
   
   
https://github.com/apache/beam/blob/4a78a81f1e9f2f9f73eda34c9eb5651eb9dad885/model/pipeline/src/main/proto/metrics.proto#L216




-- 
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.

To unsubscribe, e-mail: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

    Worklog Id:     (was: 634902)
    Time Spent: 2h 20m  (was: 2h 10m)

> "elements added" for input and output collections is always empty
> -----------------------------------------------------------------
>
>                 Key: BEAM-6374
>                 URL: https://issues.apache.org/jira/browse/BEAM-6374
>             Project: Beam
>          Issue Type: Bug
>          Components: runner-dataflow, sdk-go
>            Reporter: Andrew Brampton
>            Priority: P3
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
>
> The field for "Elements added" and "Estimated size" is always blank when 
> running a Go binary on Dataflow. For example when running the work count 
> example: https://pasteboard.co/HVf80BU.png



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

Reply via email to