Fix exclude database and retention policy tags is shared (#7323)
This commit is contained in:
parent
48f5da7e33
commit
eb8d805370
|
@ -272,8 +272,12 @@ func (c *httpClient) Write(ctx context.Context, metrics []telegraf.Metric) error
|
||||||
// Avoid modifying the metric in case we need to retry the request.
|
// Avoid modifying the metric in case we need to retry the request.
|
||||||
metric = metric.Copy()
|
metric = metric.Copy()
|
||||||
metric.Accept()
|
metric.Accept()
|
||||||
metric.RemoveTag(c.config.DatabaseTag)
|
if c.config.ExcludeDatabaseTag {
|
||||||
metric.RemoveTag(c.config.RetentionPolicyTag)
|
metric.RemoveTag(c.config.DatabaseTag)
|
||||||
|
}
|
||||||
|
if c.config.ExcludeRetentionPolicyTag {
|
||||||
|
metric.RemoveTag(c.config.RetentionPolicyTag)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
batches[dbrp] = append(batches[dbrp], metric)
|
batches[dbrp] = append(batches[dbrp], metric)
|
||||||
|
|
|
@ -907,6 +907,37 @@ func TestDBRPTags(t *testing.T) {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "exclude database tag keeps retention policy tag",
|
||||||
|
config: influxdb.HTTPConfig{
|
||||||
|
URL: u,
|
||||||
|
SkipDatabaseCreation: true,
|
||||||
|
Database: "telegraf",
|
||||||
|
RetentionPolicyTag: "rp",
|
||||||
|
ExcludeDatabaseTag: true,
|
||||||
|
Log: testutil.Logger{},
|
||||||
|
},
|
||||||
|
metrics: []telegraf.Metric{
|
||||||
|
testutil.MustMetric(
|
||||||
|
"cpu",
|
||||||
|
map[string]string{
|
||||||
|
"rp": "foo",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"value": 42.0,
|
||||||
|
},
|
||||||
|
time.Unix(0, 0),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
handlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||||
|
require.Equal(t, r.FormValue("db"), "telegraf")
|
||||||
|
require.Equal(t, r.FormValue("rp"), "foo")
|
||||||
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Contains(t, string(body), "cpu,rp=foo value=42")
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue