Don't allow inputs to overwrite host tag
closes #1054 This affects tags in the following plugins: - cassandra - disque - rethinkdb
This commit is contained in:
parent
46aaaa9b70
commit
9aec58c6b8
|
@ -24,6 +24,10 @@ for more details.
|
||||||
only. Previously there was an undocumented behavior where filters would match
|
only. Previously there was an undocumented behavior where filters would match
|
||||||
based on _prefix_ in addition to globs. This means that a filter like
|
based on _prefix_ in addition to globs. This means that a filter like
|
||||||
`fielddrop = ["time_"]` will need to be changed to `fielddrop = ["time_*"]`
|
`fielddrop = ["time_"]` will need to be changed to `fielddrop = ["time_*"]`
|
||||||
|
- The following plugins have changed their tags to _not_ overwrite the host tag:
|
||||||
|
- cassandra: `host -> cassandra_host`
|
||||||
|
- disque: `host -> disque_host`
|
||||||
|
- rethinkdb: `host -> rethinkdb_host`
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
@ -31,6 +35,7 @@ based on _prefix_ in addition to globs. This means that a filter like
|
||||||
- [#1015](https://github.com/influxdata/telegraf/pull/1015): Docker plugin schema refactor.
|
- [#1015](https://github.com/influxdata/telegraf/pull/1015): Docker plugin schema refactor.
|
||||||
- [#889](https://github.com/influxdata/telegraf/pull/889): Improved MySQL plugin. Thanks @maksadbek!
|
- [#889](https://github.com/influxdata/telegraf/pull/889): Improved MySQL plugin. Thanks @maksadbek!
|
||||||
- [#1060](https://github.com/influxdata/telegraf/pull/1060): TTL metrics added to MongoDB input plugin
|
- [#1060](https://github.com/influxdata/telegraf/pull/1060): TTL metrics added to MongoDB input plugin
|
||||||
|
- [#1056](https://github.com/influxdata/telegraf/pull/1056): Don't allow inputs to overwrite host tags.
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
@ -84,17 +84,13 @@ func (ac *accumulator) AddFields(
|
||||||
if tags == nil {
|
if tags == nil {
|
||||||
tags = make(map[string]string)
|
tags = make(map[string]string)
|
||||||
}
|
}
|
||||||
// Apply plugin-wide tags if set
|
|
||||||
for k, v := range ac.inputConfig.Tags {
|
|
||||||
if _, ok := tags[k]; !ok {
|
|
||||||
tags[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Apply daemon-wide tags if set
|
// Apply daemon-wide tags if set
|
||||||
for k, v := range ac.defaultTags {
|
for k, v := range ac.defaultTags {
|
||||||
if _, ok := tags[k]; !ok {
|
|
||||||
tags[k] = v
|
tags[k] = v
|
||||||
}
|
}
|
||||||
|
// Apply plugin-wide tags if set
|
||||||
|
for k, v := range ac.inputConfig.Tags {
|
||||||
|
tags[k] = v
|
||||||
}
|
}
|
||||||
ac.inputConfig.Filter.FilterTags(tags)
|
ac.inputConfig.Filter.FilterTags(tags)
|
||||||
|
|
||||||
|
|
|
@ -9,17 +9,9 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
//"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*type Server struct {
|
|
||||||
Host string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Port string
|
|
||||||
}*/
|
|
||||||
|
|
||||||
type JolokiaClient interface {
|
type JolokiaClient interface {
|
||||||
MakeRequest(req *http.Request) (*http.Response, error)
|
MakeRequest(req *http.Request) (*http.Response, error)
|
||||||
}
|
}
|
||||||
|
@ -55,12 +47,6 @@ type jmxMetric interface {
|
||||||
addTagsFields(out map[string]interface{})
|
addTagsFields(out map[string]interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func addServerTags(host string, tags map[string]string) {
|
|
||||||
if host != "" && host != "localhost" && host != "127.0.0.1" {
|
|
||||||
tags["host"] = host
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newJavaMetric(host string, metric string,
|
func newJavaMetric(host string, metric string,
|
||||||
acc telegraf.Accumulator) *javaMetric {
|
acc telegraf.Accumulator) *javaMetric {
|
||||||
return &javaMetric{host: host, metric: metric, acc: acc}
|
return &javaMetric{host: host, metric: metric, acc: acc}
|
||||||
|
@ -120,7 +106,7 @@ func (j javaMetric) addTagsFields(out map[string]interface{}) {
|
||||||
|
|
||||||
tokens := parseJmxMetricRequest(mbean)
|
tokens := parseJmxMetricRequest(mbean)
|
||||||
addTokensToTags(tokens, tags)
|
addTokensToTags(tokens, tags)
|
||||||
addServerTags(j.host, tags)
|
tags["cassandra_host"] = j.host
|
||||||
|
|
||||||
if _, ok := tags["mname"]; !ok {
|
if _, ok := tags["mname"]; !ok {
|
||||||
//Queries for a single value will not return a "name" tag in the response.
|
//Queries for a single value will not return a "name" tag in the response.
|
||||||
|
@ -148,7 +134,7 @@ func addCassandraMetric(mbean string, c cassandraMetric,
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
tokens := parseJmxMetricRequest(mbean)
|
tokens := parseJmxMetricRequest(mbean)
|
||||||
addTokensToTags(tokens, tags)
|
addTokensToTags(tokens, tags)
|
||||||
addServerTags(c.host, tags)
|
tags["cassandra_host"] = c.host
|
||||||
addValuesAsFields(values, fields, tags["mname"])
|
addValuesAsFields(values, fields, tags["mname"])
|
||||||
c.acc.AddFields(tokens["class"]+tokens["type"], fields, tags)
|
c.acc.AddFields(tokens["class"]+tokens["type"], fields, tags)
|
||||||
|
|
||||||
|
|
|
@ -163,12 +163,12 @@ func TestHttpJsonJavaMultiValue(t *testing.T) {
|
||||||
"HeapMemoryUsage_used": 203288528.0,
|
"HeapMemoryUsage_used": 203288528.0,
|
||||||
}
|
}
|
||||||
tags1 := map[string]string{
|
tags1 := map[string]string{
|
||||||
"host": "10.10.10.10",
|
"cassandra_host": "10.10.10.10",
|
||||||
"mname": "HeapMemoryUsage",
|
"mname": "HeapMemoryUsage",
|
||||||
}
|
}
|
||||||
|
|
||||||
tags2 := map[string]string{
|
tags2 := map[string]string{
|
||||||
"host": "10.10.10.11",
|
"cassandra_host": "10.10.10.11",
|
||||||
"mname": "HeapMemoryUsage",
|
"mname": "HeapMemoryUsage",
|
||||||
}
|
}
|
||||||
acc.AssertContainsTaggedFields(t, "javaMemory", fields, tags1)
|
acc.AssertContainsTaggedFields(t, "javaMemory", fields, tags1)
|
||||||
|
@ -190,7 +190,7 @@ func TestHttpJsonJavaMultiType(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"host": "10.10.10.10",
|
"cassandra_host": "10.10.10.10",
|
||||||
"mname": "ConcurrentMarkSweep",
|
"mname": "ConcurrentMarkSweep",
|
||||||
}
|
}
|
||||||
acc.AssertContainsTaggedFields(t, "javaGarbageCollector", fields, tags)
|
acc.AssertContainsTaggedFields(t, "javaGarbageCollector", fields, tags)
|
||||||
|
@ -231,7 +231,7 @@ func TestHttpJsonCassandraMultiValue(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"host": "10.10.10.10",
|
"cassandra_host": "10.10.10.10",
|
||||||
"mname": "ReadLatency",
|
"mname": "ReadLatency",
|
||||||
"keyspace": "test_keyspace1",
|
"keyspace": "test_keyspace1",
|
||||||
"scope": "test_table",
|
"scope": "test_table",
|
||||||
|
@ -268,14 +268,14 @@ func TestHttpJsonCassandraNestedMultiValue(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tags1 := map[string]string{
|
tags1 := map[string]string{
|
||||||
"host": "10.10.10.10",
|
"cassandra_host": "10.10.10.10",
|
||||||
"mname": "ReadLatency",
|
"mname": "ReadLatency",
|
||||||
"keyspace": "test_keyspace1",
|
"keyspace": "test_keyspace1",
|
||||||
"scope": "test_table1",
|
"scope": "test_table1",
|
||||||
}
|
}
|
||||||
|
|
||||||
tags2 := map[string]string{
|
tags2 := map[string]string{
|
||||||
"host": "10.10.10.10",
|
"cassandra_host": "10.10.10.10",
|
||||||
"mname": "ReadLatency",
|
"mname": "ReadLatency",
|
||||||
"keyspace": "test_keyspace2",
|
"keyspace": "test_keyspace2",
|
||||||
"scope": "test_table2",
|
"scope": "test_table2",
|
||||||
|
|
|
@ -162,7 +162,7 @@ func (g *Disque) gatherServer(addr *url.URL, acc telegraf.Accumulator) error {
|
||||||
var read int
|
var read int
|
||||||
|
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
tags := map[string]string{"host": addr.String()}
|
tags := map[string]string{"disque_host": addr.String()}
|
||||||
for read < sz {
|
for read < sz {
|
||||||
line, err := r.ReadString('\n')
|
line, err := r.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -97,8 +97,8 @@ func (s *Server) getServerStatus() error {
|
||||||
|
|
||||||
func (s *Server) getDefaultTags() map[string]string {
|
func (s *Server) getDefaultTags() map[string]string {
|
||||||
tags := make(map[string]string)
|
tags := make(map[string]string)
|
||||||
tags["host"] = s.Url.Host
|
tags["rethinkdb_host"] = s.Url.Host
|
||||||
tags["hostname"] = s.serverStatus.Network.Hostname
|
tags["rethinkdb_hostname"] = s.serverStatus.Network.Hostname
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ func TestGetDefaultTags(t *testing.T) {
|
||||||
in string
|
in string
|
||||||
out string
|
out string
|
||||||
}{
|
}{
|
||||||
{"host", server.Url.Host},
|
{"rethinkdb_host", server.Url.Host},
|
||||||
{"hostname", server.serverStatus.Network.Hostname},
|
{"rethinkdb_hostname", server.serverStatus.Network.Hostname},
|
||||||
}
|
}
|
||||||
defaultTags := server.getDefaultTags()
|
defaultTags := server.getDefaultTags()
|
||||||
for _, tt := range tagTests {
|
for _, tt := range tagTests {
|
||||||
|
|
Loading…
Reference in New Issue