Skip to content

Commit

Permalink
app/{vmagent,vminsert}: properly preserve db tag from query string …
Browse files Browse the repository at this point in the history
…passed to Influx line protocol query

Previously `db` tag from the query string wasn't added to metrics after encountering `db` tag in the Influx line

Updates #653
  • Loading branch information
valyala committed Jul 28, 2020
1 parent baebe86 commit f6d4275
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/vmagent/influx/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ func insertRows(db string, rows []parser.Row) error {
for i := range rows {
r := &rows[i]
commonLabels = commonLabels[:0]
hasDBKey := false
for j := range r.Tags {
tag := &r.Tags[j]
if tag.Key == "db" {
db = ""
hasDBKey = true
}
commonLabels = append(commonLabels, prompbmarshal.Label{
Name: tag.Key,
Value: tag.Value,
})
}
if len(db) > 0 {
if len(db) > 0 && !hasDBKey {
commonLabels = append(commonLabels, prompbmarshal.Label{
Name: "db",
Value: db,
Expand Down
7 changes: 5 additions & 2 deletions app/vminsert/influx/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func insertRows(at *auth.Token, db string, rows []parser.Row, mayOverrideAccount
for i := range rows {
r := &rows[i]
ic.Labels = ic.Labels[:0]
hasDBKey := false
for j := range r.Tags {
tag := &r.Tags[j]
if mayOverrideAccountProjectID {
Expand All @@ -82,11 +83,13 @@ func insertRows(at *auth.Token, db string, rows []parser.Row, mayOverrideAccount
}
}
if tag.Key == "db" {
db = ""
hasDBKey = true
}
ic.AddLabel(tag.Key, tag.Value)
}
ic.AddLabel("db", db)
if !hasDBKey {
ic.AddLabel("db", db)
}
ctx.metricGroupBuf = ctx.metricGroupBuf[:0]
if !*skipMeasurement {
ctx.metricGroupBuf = append(ctx.metricGroupBuf, r.Measurement...)
Expand Down

0 comments on commit f6d4275

Please sign in to comment.