You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/01/21 15:32:44 UTC

[servicecomb-service-center] branch master updated: Bug: not correct syncer metrics name (#1244)

This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 668407e  Bug: not correct syncer metrics name (#1244)
668407e is described below

commit 668407e955fb7471027b0d9ee6ed2f7ed3e925d1
Author: little-cui <su...@qq.com>
AuthorDate: Fri Jan 21 23:32:36 2022 +0800

    Bug: not correct syncer metrics name (#1244)
---
 datasource/manager.go   |  4 +---
 pkg/metrics/gatherer.go | 10 +++++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/datasource/manager.go b/datasource/manager.go
index 2e7c91d..9d3e5c2 100644
--- a/datasource/manager.go
+++ b/datasource/manager.go
@@ -59,9 +59,7 @@ func Init(opts Options) error {
 	if err != nil {
 		return err
 	}
-	err = dlock.Init(dlock.Options{
-		Kind: opts.Kind,
-	})
+	err = dlock.Init(dlock.Options{Kind: opts.Kind})
 	if err != nil {
 		return err
 	}
diff --git a/pkg/metrics/gatherer.go b/pkg/metrics/gatherer.go
index b8b59ba..761a7aa 100644
--- a/pkg/metrics/gatherer.go
+++ b/pkg/metrics/gatherer.go
@@ -29,6 +29,8 @@ import (
 	"github.com/go-chassis/foundation/gopool"
 )
 
+const prefixName = FamilyName + "_"
+
 var families = mapset.NewSet(FamilyName)
 
 // EmptyGather just active when metrics disabled
@@ -92,6 +94,9 @@ func (mm *Gather) Collect() error {
 	records := NewMetrics()
 	for _, mf := range mfs {
 		name := RecordName(mf.GetName())
+		if len(name) == 0 {
+			continue
+		}
 		if d := Calculate(mf); d != nil {
 			records.put(name, d)
 		}
@@ -107,7 +112,10 @@ func RecordName(metricName string) string {
 	if !isSys && len(family) == 0 {
 		return ""
 	}
-	metricName = strings.TrimPrefix(metricName, family+"_")
+	if strings.Index(metricName, prefixName) == 0 {
+		// just compatible with sc old metric name without familyName
+		metricName = strings.TrimPrefix(metricName, prefixName)
+	}
 	return metricName
 }