From 7d326ef306e22c554263da87646ed25d099fed47 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Fri, 17 Jun 2022 09:56:10 +0800 Subject: [PATCH] use metrics as hash key --- Makefile | 2 +- src/server/idents/idents.go | 4 ++-- src/server/router/router_datadog.go | 6 ++---- src/server/router/router_openfalcon.go | 6 ++---- src/server/router/router_opentsdb.go | 6 ++---- src/server/router/router_prom.go | 17 ++++++++++------- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index e39d489d..ba6ff3a4 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ NOW = $(shell date -u '+%Y%m%d%I%M%S') -RELEASE_VERSION = 5.9.2 +RELEASE_VERSION = 5.9.3 APP = n9e SERVER_BIN = $(APP) diff --git a/src/server/idents/idents.go b/src/server/idents/idents.go index 9531a55b..aa69a5da 100644 --- a/src/server/idents/idents.go +++ b/src/server/idents/idents.go @@ -168,7 +168,7 @@ func pushMetrics() { common.AppendLabels(pt, target) } - writer.Writers.PushSample("default_ident_target_up", pt) + writer.Writers.PushSample("target_up", pt) } // 把actives传给TargetCache,看看除了active的部分,还有别的target么?有的话返回,设置target_up = 0 @@ -193,6 +193,6 @@ func pushMetrics() { }) common.AppendLabels(pt, dead) - writer.Writers.PushSample("default_ident_target_up", pt) + writer.Writers.PushSample("target_up", pt) } } diff --git a/src/server/router/router_datadog.go b/src/server/router/router_datadog.go index 15043904..01e79267 100644 --- a/src/server/router/router_datadog.go +++ b/src/server/router/router_datadog.go @@ -261,12 +261,10 @@ func datadogSeries(c *gin.Context) { if has { common.AppendLabels(pt, target) } - - writer.Writers.PushSample(ident, pt) - } else { - writer.Writers.PushSample("default_hash_string", pt) } + writer.Writers.PushSample(item.Metric, pt) + succ++ } diff --git a/src/server/router/router_openfalcon.go b/src/server/router/router_openfalcon.go index c6a68453..4eb885b6 100644 --- a/src/server/router/router_openfalcon.go +++ b/src/server/router/router_openfalcon.go @@ -206,12 +206,10 @@ func falconPush(c *gin.Context) { if has { common.AppendLabels(pt, target) } - - writer.Writers.PushSample(ident, pt) - } else { - writer.Writers.PushSample("default_hash_string", pt) } + writer.Writers.PushSample(arr[i].Metric, pt) + succ++ } diff --git a/src/server/router/router_opentsdb.go b/src/server/router/router_opentsdb.go index 2a0e07b4..40d5fb3c 100644 --- a/src/server/router/router_opentsdb.go +++ b/src/server/router/router_opentsdb.go @@ -190,12 +190,10 @@ func handleOpenTSDB(c *gin.Context) { if has { common.AppendLabels(pt, target) } - - writer.Writers.PushSample(host, pt) - } else { - writer.Writers.PushSample("default_hash_string", pt) } + writer.Writers.PushSample(arr[i].Metric, pt) + succ++ } diff --git a/src/server/router/router_prom.go b/src/server/router/router_prom.go index 36e498d6..544ac092 100644 --- a/src/server/router/router_prom.go +++ b/src/server/router/router_prom.go @@ -59,9 +59,10 @@ func remoteWrite(c *gin.Context) { } var ( - now = time.Now().Unix() - ids = make(map[string]interface{}) - ident string + now = time.Now().Unix() + ids = make(map[string]interface{}) + ident string + metric string ) for i := 0; i < count; i++ { @@ -72,6 +73,10 @@ func remoteWrite(c *gin.Context) { if req.Timeseries[i].Labels[j].Name == "ident" { ident = req.Timeseries[i].Labels[j].Value } + + if req.Timeseries[i].Labels[j].Name == "__name__" { + metric = req.Timeseries[i].Labels[j].Value + } } if ident == "" { @@ -94,11 +99,9 @@ func remoteWrite(c *gin.Context) { if has { common.AppendLabels(req.Timeseries[i], target) } - - writer.Writers.PushSample(ident, req.Timeseries[i]) - } else { - writer.Writers.PushSample("default_hash_string", req.Timeseries[i]) } + + writer.Writers.PushSample(metric, req.Timeseries[i]) } promstat.CounterSampleTotal.WithLabelValues(config.C.ClusterName, "prometheus").Add(float64(count))