freeznet commented on a change in pull request #12013:
URL: https://github.com/apache/pulsar/pull/12013#discussion_r709726464



##########
File path: pulsar-function-go/pf/instance.go
##########
@@ -75,9 +77,20 @@ func newGoInstance() *goInstance {
                return producer
        }
 
+       metricsLabels := goInstance.getMetricsLabels()
+
+       var userMetrics sync.Map
+       goInstance.context.recordMetric = func(metricName string, metricValue 
float64) {
+               v, ok := userMetrics.Load(metricName)
+               if !ok {
+                       v, _ = userMetrics.LoadOrStore(metricName, 
userMetricSummary.WithLabelValues(append(metricsLabels, metricName)...))
+               }
+               v.(prometheus.Observer).Observe(metricValue)
+       }
+

Review comment:
       Can we move this part to `context.go`?

##########
File path: pulsar-function-go/pf/stats.go
##########
@@ -122,6 +126,11 @@ var (
                prometheus.GaugeOpts{
                        Name: PulsarFunctionMetricsPrefix + "system_exception",
                        Help: "Exception from system code."}, 
exceptionMetricsLabelNames)
+
+       userMetricSummary = prometheus.NewSummaryVec(
+               prometheus.SummaryOpts{
+                       Name: PulsarFunctionMetricsPrefix + UserMetric,
+                       Help: "Pulsar Function user defined metric"}, 
userMetricLabelNames)

Review comment:
       please make sure the go's metrics are same as the java's
   
https://github.com/apache/pulsar/blob/3231caa894a24fa9048adf4628316d280d02c679/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/ContextImpl.java#L204-L214




-- 
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: commits-unsubscr...@pulsar.apache.org

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


Reply via email to