app/vminsert/influx: set db label only if Influx line doesnt have db tag

This commit is contained in:
Aliaksandr Valialkin 2019-08-24 13:51:51 +03:00
parent 023675c33e
commit 38711526d3

View file

@ -89,11 +89,17 @@ func (ctx *pushCtx) InsertRows(at *auth.Token, db string) error {
for i := range rows {
r := &rows[i]
ic.Labels = ic.Labels[:0]
ic.AddLabel("db", db)
hasDBLabel := false
for j := range r.Tags {
tag := &r.Tags[j]
if tag.Key == "db" {
hasDBLabel = true
}
ic.AddLabel(tag.Key, tag.Value)
}
if len(db) > 0 && !hasDBLabel {
ic.AddLabel("db", db)
}
ic.MetricNameBuf = storage.MarshalMetricNameRaw(ic.MetricNameBuf[:0], at.AccountID, at.ProjectID, ic.Labels)
metricNameBufLen := len(ic.MetricNameBuf)
ctx.metricGroupBuf = append(ctx.metricGroupBuf[:0], r.Measurement...)