You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/08/06 01:02:40 UTC

[GitHub] [beam] ajamato commented on a change in pull request #15289: [BEAM-6374] Emit PCollection metrics from GoSDK

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-unsubscribe@beam.apache.org

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