lostluck commented on a change in pull request #15923:
URL: https://github.com/apache/beam/pull/15923#discussion_r745974958



##########
File path: sdks/go/pkg/beam/core/runtime/metricsx/metricsx.go
##########
@@ -150,7 +183,15 @@ func extractGaugeValue(reader *bytes.Reader) 
(metrics.GaugeValue, error) {
 }
 
 func newLabels(miLabels map[string]string) *metrics.Labels {
-       labels := metrics.UserLabels(miLabels["PTRANSFORM"], 
miLabels["NAMESPACE"], miLabels["NAME"])
+       labels := metrics.Labels{}
+       if miLabels["PTRANSFORM"] != "" {
+               labels = metrics.UserLabels(miLabels["PTRANSFORM"], 
miLabels["NAMESPACE"], miLabels["NAME"])
+               return &labels
+       }
+       if miLabels["PCOLLECTION"] != "" {
+               labels = metrics.PCollectionLabels(miLabels["PCOLLECTION"])
+               return &labels
+       }
        return &labels

Review comment:
       Unless one is setting fields conditionally, there's no reason to 
pre-declare a variable at the top of a function.
   ```suggestion
        if miLabels["PTRANSFORM"] != "" {
                labels := metrics.UserLabels(miLabels["PTRANSFORM"], 
miLabels["NAMESPACE"], miLabels["NAME"])
                return &labels
        }
        if miLabels["PCOLLECTION"] != "" {
                labels := metrics.PCollectionLabels(miLabels["PCOLLECTION"])
                return &labels
        }
        return &metrics.Labels{}
   ```




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to