From 0851de714d8df6f3a13e54ff1228ea35e6ff37eb Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Thu, 15 Feb 2018 18:24:09 -0800 Subject: [PATCH] Add url tag only if not already set --- plugins/inputs/http/README.md | 3 --- plugins/inputs/http/http.go | 5 +---- plugins/inputs/http/http_test.go | 3 +-- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/plugins/inputs/http/README.md b/plugins/inputs/http/README.md index 85a57c99a..2c22aaa42 100644 --- a/plugins/inputs/http/README.md +++ b/plugins/inputs/http/README.md @@ -20,9 +20,6 @@ The HTTP input plugin collects metrics from one or more HTTP(S) endpoints. The # username = "username" # password = "pa$$word" - ## Tag all metrics with the url - # tag_url = true - ## Optional SSL Config # ssl_ca = "/etc/telegraf/ca.pem" # ssl_cert = "/etc/telegraf/cert.pem" diff --git a/plugins/inputs/http/http.go b/plugins/inputs/http/http.go index 1f6a2e924..00a13e3f3 100644 --- a/plugins/inputs/http/http.go +++ b/plugins/inputs/http/http.go @@ -24,9 +24,6 @@ type HTTP struct { Username string Password string - // Option to add "url" tag to each metric - TagURL bool `toml:"tag_url"` - // Path to CA file SSLCA string `toml:"ssl_ca"` // Path to host cert file @@ -183,7 +180,7 @@ func (h *HTTP) gatherURL( } for _, metric := range metrics { - if h.TagURL { + if !metric.HasTag("url") { metric.AddTag("url", url) } acc.AddFields(metric.Name(), metric.Fields(), metric.Tags(), metric.Time()) diff --git a/plugins/inputs/http/http_test.go b/plugins/inputs/http/http_test.go index fd352829c..843015990 100644 --- a/plugins/inputs/http/http_test.go +++ b/plugins/inputs/http/http_test.go @@ -23,8 +23,7 @@ func TestHTTPwithJSONFormat(t *testing.T) { url := fakeServer.URL + "/endpoint" plugin := &plugin.HTTP{ - URLs: []string{url}, - TagURL: true, + URLs: []string{url}, } metricName := "metricName" p, _ := parsers.NewJSONParser(metricName, nil, nil)