You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/09/16 03:44:50 UTC

[GitHub] [pulsar] freeznet commented on a change in pull request #12013: [Issue 9772][Go Functions]Allow User Metrics

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

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