提交 80874a74 编写于 作者: U Ulric Qin

refactor logic: do not extract ident when ignore_ident exists

上级 6cc61256
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"github.com/golang/snappy" "github.com/golang/snappy"
"github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/prompb"
"github.com/toolkits/pkg/ginx"
) )
func extractMetricFromTimeSeries(s *prompb.TimeSeries) string { func extractMetricFromTimeSeries(s *prompb.TimeSeries) string {
...@@ -20,7 +21,7 @@ func extractMetricFromTimeSeries(s *prompb.TimeSeries) string { ...@@ -20,7 +21,7 @@ func extractMetricFromTimeSeries(s *prompb.TimeSeries) string {
return "" return ""
} }
func extractIdentFromTimeSeries(s *prompb.TimeSeries) string { func extractIdentFromTimeSeries(s *prompb.TimeSeries, ignoreIdent bool) string {
for i := 0; i < len(s.Labels); i++ { for i := 0; i < len(s.Labels); i++ {
if s.Labels[i].Name == "ident" { if s.Labels[i].Name == "ident" {
return s.Labels[i].Value return s.Labels[i].Value
...@@ -35,11 +36,13 @@ func extractIdentFromTimeSeries(s *prompb.TimeSeries) string { ...@@ -35,11 +36,13 @@ func extractIdentFromTimeSeries(s *prompb.TimeSeries) string {
} }
} }
// telegraf, output plugin: http, format: prometheusremotewrite if !ignoreIdent {
for i := 0; i < len(s.Labels); i++ { // telegraf, output plugin: http, format: prometheusremotewrite
if s.Labels[i].Name == "host" { for i := 0; i < len(s.Labels); i++ {
s.Labels[i].Name = "ident" if s.Labels[i].Name == "host" {
return s.Labels[i].Value s.Labels[i].Name = "ident"
return s.Labels[i].Value
}
} }
} }
...@@ -89,7 +92,7 @@ func (rt *Router) remoteWrite(c *gin.Context) { ...@@ -89,7 +92,7 @@ func (rt *Router) remoteWrite(c *gin.Context) {
continue continue
} }
ident = extractIdentFromTimeSeries(req.Timeseries[i]) ident = extractIdentFromTimeSeries(req.Timeseries[i], ginx.QueryBool(c, "ignore_ident", false))
if len(ident) > 0 { if len(ident) > 0 {
// has ident tag or agent_hostname tag // has ident tag or agent_hostname tag
// register host in table target // register host in table target
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册