You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "FinalT (via GitHub)" <gi...@apache.org> on 2023/04/27 04:19:02 UTC

[GitHub] [dubbo-go] FinalT commented on a diff in pull request #2310: refactor: split metrics module into multiple files

FinalT commented on code in PR #2310:
URL: https://github.com/apache/dubbo-go/pull/2310#discussion_r1178586967


##########
metrics/prometheus/metric_set.go:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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 prometheus
+
+import (
+	"strings"
+
+	"dubbo.apache.org/dubbo-go/v3/metrics"
+	"github.com/prometheus/client_golang/prometheus"
+)
+
+// metricSet is a set of metrics that are reported to prometheus in dubbo go
+type metricSet struct {
+	// report the consumer-side's rt gauge data
+	consumerRTSummaryVec *prometheus.SummaryVec
+	// report the provider-side's rt gauge data
+	providerRTSummaryVec *prometheus.SummaryVec
+	// report the provider-side's request total counter data
+	providerRequestTotalCounterVec *prometheus.CounterVec
+	// report the consumer-side's request total counter data
+	consumerRequestTotalCounterVec *prometheus.CounterVec
+	// report the provider-side's processing request counter data
+	// providerRequestProcessingGaugeVec *prometheus.GaugeVec
+	// report the consumer-side's processing request counter data
+	// consumerRequestProcessingGaugeVec *prometheus.GaugeVec
+}
+
+var labelNames = []string{applicationNameKey, groupKey, hostnameKey, interfaceKey, ipKey, methodKey, versionKey}
+
+// init metric set and register to prometheus
+func (ms *metricSet) initAndRegister(reporterConfig *metrics.ReporterConfig) {
+	ms.consumerRTSummaryVec = newSummaryVec(buildMetricsName(consumerField, rtField, milliSecondsField, summaryField), reporterConfig.Namespace, labelNames, reporterConfig.SummaryMaxAge)
+	ms.providerRTSummaryVec = newSummaryVec(buildMetricsName(providerField, rtField, milliSecondsField, summaryField), reporterConfig.Namespace, labelNames, reporterConfig.SummaryMaxAge)
+	ms.consumerRequestTotalCounterVec = newCounterVec(buildMetricsName(consumerField, requestsField, totalField), reporterConfig.Namespace, labelNames)
+	ms.providerRequestTotalCounterVec = newCounterVec(buildMetricsName(providerField, requestsField, totalField), reporterConfig.Namespace, labelNames)
+
+	prometheus.DefaultRegisterer.MustRegister(ms.consumerRTSummaryVec, ms.providerRTSummaryVec, ms.consumerRequestTotalCounterVec, ms.providerRequestTotalCounterVec)
+}
+
+func buildMetricsName(args ...string) string {
+	sb := strings.Builder{}
+	for _, arg := range args {
+		sb.WriteString("_")
+		sb.WriteString(arg)
+	}
+	res, _ := strings.CutPrefix(sb.String(), "_")

Review Comment:
   ```suggestion
   	res := strings.TrimPrefix(sb.String(), "_")
   ```



-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org