diff --git a/pushgw/router/router_remotewrite.go b/pushgw/router/router_remotewrite.go index 71e33432c6f9703f83ad3eba415686f2aed09b46..38d3f5c1317facb24fcf193b2cb390e21e673a46 100644 --- a/pushgw/router/router_remotewrite.go +++ b/pushgw/router/router_remotewrite.go @@ -9,6 +9,7 @@ import ( "github.com/gogo/protobuf/proto" "github.com/golang/snappy" "github.com/prometheus/prometheus/prompb" + "github.com/toolkits/pkg/ginx" ) func extractMetricFromTimeSeries(s *prompb.TimeSeries) string { @@ -20,7 +21,7 @@ func extractMetricFromTimeSeries(s *prompb.TimeSeries) string { return "" } -func extractIdentFromTimeSeries(s *prompb.TimeSeries) string { +func extractIdentFromTimeSeries(s *prompb.TimeSeries, ignoreIdent bool) string { for i := 0; i < len(s.Labels); i++ { if s.Labels[i].Name == "ident" { return s.Labels[i].Value @@ -35,11 +36,13 @@ func extractIdentFromTimeSeries(s *prompb.TimeSeries) string { } } - // telegraf, output plugin: http, format: prometheusremotewrite - for i := 0; i < len(s.Labels); i++ { - if s.Labels[i].Name == "host" { - s.Labels[i].Name = "ident" - return s.Labels[i].Value + if !ignoreIdent { + // telegraf, output plugin: http, format: prometheusremotewrite + for i := 0; i < len(s.Labels); i++ { + if s.Labels[i].Name == "host" { + s.Labels[i].Name = "ident" + return s.Labels[i].Value + } } } @@ -89,7 +92,7 @@ func (rt *Router) remoteWrite(c *gin.Context) { continue } - ident = extractIdentFromTimeSeries(req.Timeseries[i]) + ident = extractIdentFromTimeSeries(req.Timeseries[i], ginx.QueryBool(c, "ignore_ident", false)) if len(ident) > 0 { // has ident tag or agent_hostname tag // register host in table target