Linter fixes - gosimple (#9046)
This commit is contained in:
parent
d5b4c3e148
commit
099ccda3f9
|
|
@ -47,7 +47,7 @@ func Compile(filters []string) (Filter, error) {
|
||||||
|
|
||||||
// hasMeta reports whether path contains any magic glob characters.
|
// hasMeta reports whether path contains any magic glob characters.
|
||||||
func hasMeta(s string) bool {
|
func hasMeta(s string) bool {
|
||||||
return strings.IndexAny(s, "*?[") >= 0
|
return strings.ContainsAny(s, "*?[")
|
||||||
}
|
}
|
||||||
|
|
||||||
type filter struct {
|
type filter struct {
|
||||||
|
|
|
||||||
|
|
@ -84,10 +84,10 @@ func (g *GlobPath) GetRoots() []string {
|
||||||
|
|
||||||
// hasMeta reports whether path contains any magic glob characters.
|
// hasMeta reports whether path contains any magic glob characters.
|
||||||
func hasMeta(path string) bool {
|
func hasMeta(path string) bool {
|
||||||
return strings.IndexAny(path, "*?[") >= 0
|
return strings.ContainsAny(path, "*?[")
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasSuperMeta reports whether path contains any super magic glob characters (**).
|
// hasSuperMeta reports whether path contains any super magic glob characters (**).
|
||||||
func hasSuperMeta(path string) bool {
|
func hasSuperMeta(path string) bool {
|
||||||
return strings.Index(path, "**") >= 0
|
return strings.Contains(path, "**")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func TestMain(m *testing.M) {
|
||||||
// externalProcess is an external "misbehaving" process that won't exit
|
// externalProcess is an external "misbehaving" process that won't exit
|
||||||
// cleanly.
|
// cleanly.
|
||||||
func externalProcess() {
|
func externalProcess() {
|
||||||
wait := make(chan int, 0)
|
wait := make(chan int)
|
||||||
fmt.Fprintln(os.Stdout, "started")
|
fmt.Fprintln(os.Stdout, "started")
|
||||||
<-wait
|
<-wait
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,8 @@ func (t *Template) Apply(line string, joiner string) (string, map[string]string,
|
||||||
field = append(field, fields[i])
|
field = append(field, fields[i])
|
||||||
case "field*":
|
case "field*":
|
||||||
field = append(field, fields[i:]...)
|
field = append(field, fields[i:]...)
|
||||||
break
|
|
||||||
case "measurement*":
|
case "measurement*":
|
||||||
measurement = append(measurement, fields[i:]...)
|
measurement = append(measurement, fields[i:]...)
|
||||||
break
|
|
||||||
default:
|
default:
|
||||||
tags[tag] = append(tags[tag], fields[i])
|
tags[tag] = append(tags[tag], fields[i])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,7 @@ func (t *telegrafLog) Write(b []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *telegrafLog) Close() error {
|
func (t *telegrafLog) Close() error {
|
||||||
var stdErrWriter io.Writer
|
stdErrWriter := os.Stderr
|
||||||
stdErrWriter = os.Stderr
|
|
||||||
// avoid closing stderr
|
// avoid closing stderr
|
||||||
if t.internalWriter != stdErrWriter {
|
if t.internalWriter != stdErrWriter {
|
||||||
closer, isCloser := t.internalWriter.(io.Closer)
|
closer, isCloser := t.internalWriter.(io.Closer)
|
||||||
|
|
|
||||||
|
|
@ -54,41 +54,41 @@ func (f *Filter) Compile() error {
|
||||||
var err error
|
var err error
|
||||||
f.nameDrop, err = filter.Compile(f.NameDrop)
|
f.nameDrop, err = filter.Compile(f.NameDrop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error compiling 'namedrop', %s", err)
|
return fmt.Errorf("error compiling 'namedrop', %s", err)
|
||||||
}
|
}
|
||||||
f.namePass, err = filter.Compile(f.NamePass)
|
f.namePass, err = filter.Compile(f.NamePass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error compiling 'namepass', %s", err)
|
return fmt.Errorf("error compiling 'namepass', %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.fieldDrop, err = filter.Compile(f.FieldDrop)
|
f.fieldDrop, err = filter.Compile(f.FieldDrop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error compiling 'fielddrop', %s", err)
|
return fmt.Errorf("error compiling 'fielddrop', %s", err)
|
||||||
}
|
}
|
||||||
f.fieldPass, err = filter.Compile(f.FieldPass)
|
f.fieldPass, err = filter.Compile(f.FieldPass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error compiling 'fieldpass', %s", err)
|
return fmt.Errorf("error compiling 'fieldpass', %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.tagExclude, err = filter.Compile(f.TagExclude)
|
f.tagExclude, err = filter.Compile(f.TagExclude)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error compiling 'tagexclude', %s", err)
|
return fmt.Errorf("error compiling 'tagexclude', %s", err)
|
||||||
}
|
}
|
||||||
f.tagInclude, err = filter.Compile(f.TagInclude)
|
f.tagInclude, err = filter.Compile(f.TagInclude)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error compiling 'taginclude', %s", err)
|
return fmt.Errorf("error compiling 'taginclude', %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range f.TagDrop {
|
for i := range f.TagDrop {
|
||||||
f.TagDrop[i].filter, err = filter.Compile(f.TagDrop[i].Filter)
|
f.TagDrop[i].filter, err = filter.Compile(f.TagDrop[i].Filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error compiling 'tagdrop', %s", err)
|
return fmt.Errorf("error compiling 'tagdrop', %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range f.TagPass {
|
for i := range f.TagPass {
|
||||||
f.TagPass[i].filter, err = filter.Compile(f.TagPass[i].Filter)
|
f.TagPass[i].filter, err = filter.Compile(f.TagPass[i].Filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error compiling 'tagpass', %s", err)
|
return fmt.Errorf("error compiling 'tagpass', %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -132,17 +132,11 @@ func (f *Filter) IsActive() bool {
|
||||||
// based on the drop/pass filter parameters
|
// based on the drop/pass filter parameters
|
||||||
func (f *Filter) shouldNamePass(key string) bool {
|
func (f *Filter) shouldNamePass(key string) bool {
|
||||||
pass := func(f *Filter) bool {
|
pass := func(f *Filter) bool {
|
||||||
if f.namePass.Match(key) {
|
return f.namePass.Match(key)
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drop := func(f *Filter) bool {
|
drop := func(f *Filter) bool {
|
||||||
if f.nameDrop.Match(key) {
|
return !f.nameDrop.Match(key)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.namePass != nil && f.nameDrop != nil {
|
if f.namePass != nil && f.nameDrop != nil {
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,4 @@ func SetLoggerOnPlugin(i interface{}, log telegraf.Logger) {
|
||||||
log.Debugf("Plugin %q defines a 'Log' field on its struct of an unexpected type %q. Expected telegraf.Logger",
|
log.Debugf("Plugin %q defines a 'Log' field on its struct of an unexpected type %q. Expected telegraf.Logger",
|
||||||
valI.Type().Name(), field.Type().String())
|
valI.Type().Name(), field.Type().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -539,9 +539,7 @@ func (m *mockOutput) Write(metrics []telegraf.Metric) error {
|
||||||
m.metrics = []telegraf.Metric{}
|
m.metrics = []telegraf.Metric{}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range metrics {
|
m.metrics = append(m.metrics, metrics...)
|
||||||
m.metrics = append(m.metrics, metric)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,4 @@ func setLoggerOnPlugin(i interface{}, log telegraf.Logger) {
|
||||||
field.Set(reflect.ValueOf(log))
|
field.Set(reflect.ValueOf(log))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -250,8 +250,6 @@ func (a *Aerospike) parseNodeInfo(stats map[string]string, hostPort string, node
|
||||||
fields[key] = parseAerospikeValue(key, v)
|
fields[key] = parseAerospikeValue(key, v)
|
||||||
}
|
}
|
||||||
acc.AddFields("aerospike_node", fields, tags, time.Now())
|
acc.AddFields("aerospike_node", fields, tags, time.Now())
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Aerospike) getNamespaces(n *as.Node) ([]string, error) {
|
func (a *Aerospike) getNamespaces(n *as.Node) ([]string, error) {
|
||||||
|
|
@ -295,8 +293,6 @@ func (a *Aerospike) parseNamespaceInfo(stats map[string]string, hostPort string,
|
||||||
nFields[key] = parseAerospikeValue(key, parts[1])
|
nFields[key] = parseAerospikeValue(key, parts[1])
|
||||||
}
|
}
|
||||||
acc.AddFields("aerospike_namespace", nFields, nTags, time.Now())
|
acc.AddFields("aerospike_namespace", nFields, nTags, time.Now())
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Aerospike) getSets(n *as.Node) ([]string, error) {
|
func (a *Aerospike) getSets(n *as.Node) ([]string, error) {
|
||||||
|
|
@ -365,8 +361,6 @@ func (a *Aerospike) parseSetInfo(stats map[string]string, hostPort string, names
|
||||||
nFields[key] = parseAerospikeValue(key, pieces[1])
|
nFields[key] = parseAerospikeValue(key, pieces[1])
|
||||||
}
|
}
|
||||||
acc.AddFields("aerospike_set", nFields, nTags, time.Now())
|
acc.AddFields("aerospike_set", nFields, nTags, time.Now())
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Aerospike) getTTLHistogram(hostPort string, namespace string, set string, n *as.Node, acc telegraf.Accumulator) error {
|
func (a *Aerospike) getTTLHistogram(hostPort string, namespace string, set string, n *as.Node, acc telegraf.Accumulator) error {
|
||||||
|
|
@ -430,7 +424,7 @@ func (a *Aerospike) parseHistogram(stats map[string]string, hostPort string, nam
|
||||||
// Normalize incase of less buckets than expected
|
// Normalize incase of less buckets than expected
|
||||||
numRecordsPerBucket := 1
|
numRecordsPerBucket := 1
|
||||||
if len(buckets) > a.NumberHistogramBuckets {
|
if len(buckets) > a.NumberHistogramBuckets {
|
||||||
numRecordsPerBucket = int(math.Ceil((float64(len(buckets)) / float64(a.NumberHistogramBuckets))))
|
numRecordsPerBucket = int(math.Ceil(float64(len(buckets)) / float64(a.NumberHistogramBuckets)))
|
||||||
}
|
}
|
||||||
|
|
||||||
bucketCount := 0
|
bucketCount := 0
|
||||||
|
|
@ -462,8 +456,6 @@ func (a *Aerospike) parseHistogram(stats map[string]string, hostPort string, nam
|
||||||
}
|
}
|
||||||
|
|
||||||
acc.AddFields(fmt.Sprintf("aerospike_histogram_%v", strings.Replace(histogramType, "-", "_", -1)), nFields, nTags, time.Now())
|
acc.AddFields(fmt.Sprintf("aerospike_histogram_%v", strings.Replace(histogramType, "-", "_", -1)), nFields, nTags, time.Now())
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitNamespaceSet(namespaceSet string) (string, string) {
|
func splitNamespaceSet(namespaceSet string) (string, string) {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func (a *externalAuth) Mechanism() string {
|
||||||
return "EXTERNAL"
|
return "EXTERNAL"
|
||||||
}
|
}
|
||||||
func (a *externalAuth) Response() string {
|
func (a *externalAuth) Response() string {
|
||||||
return fmt.Sprintf("\000")
|
return "\000"
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -288,7 +288,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
|
||||||
|
|
||||||
ch, err := a.conn.Channel()
|
ch, err := a.conn.Channel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to open a channel: %s", err.Error())
|
return nil, fmt.Errorf("failed to open a channel: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.Exchange != "" {
|
if a.Exchange != "" {
|
||||||
|
|
@ -335,7 +335,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to bind a queue: %s", err)
|
return nil, fmt.Errorf("failed to bind a queue: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,7 +345,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
|
||||||
false, // global
|
false, // global
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to set QoS: %s", err)
|
return nil, fmt.Errorf("failed to set QoS: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgs, err := ch.Consume(
|
msgs, err := ch.Consume(
|
||||||
|
|
@ -358,7 +358,7 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
|
||||||
nil, // arguments
|
nil, // arguments
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed establishing connection to queue: %s", err)
|
return nil, fmt.Errorf("failed establishing connection to queue: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return msgs, err
|
return msgs, err
|
||||||
|
|
@ -395,7 +395,7 @@ func declareExchange(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error declaring exchange: %v", err)
|
return fmt.Errorf("error declaring exchange: %v", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -437,7 +437,7 @@ func declareQueue(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error declaring queue: %v", err)
|
return nil, fmt.Errorf("error declaring queue: %v", err)
|
||||||
}
|
}
|
||||||
return &queue, nil
|
return &queue, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,12 +127,12 @@ func (c *CiscoTelemetryMDT) nxosValueXform(field *telemetry.TelemetryField, valu
|
||||||
}
|
}
|
||||||
case *telemetry.TelemetryField_Uint32Value:
|
case *telemetry.TelemetryField_Uint32Value:
|
||||||
vali, ok := value.(uint32)
|
vali, ok := value.(uint32)
|
||||||
if ok == true {
|
if ok {
|
||||||
return vali
|
return vali
|
||||||
}
|
}
|
||||||
case *telemetry.TelemetryField_Uint64Value:
|
case *telemetry.TelemetryField_Uint64Value:
|
||||||
vali, ok := value.(uint64)
|
vali, ok := value.(uint64)
|
||||||
if ok == true {
|
if ok {
|
||||||
return vali
|
return vali
|
||||||
}
|
}
|
||||||
} //switch
|
} //switch
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ func (d *DiskIO) SampleConfig() string {
|
||||||
|
|
||||||
// hasMeta reports whether s contains any special glob characters.
|
// hasMeta reports whether s contains any special glob characters.
|
||||||
func hasMeta(s string) bool {
|
func hasMeta(s string) bool {
|
||||||
return strings.IndexAny(s, "*?[") >= 0
|
return strings.ContainsAny(s, "*?[")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiskIO) init() error {
|
func (d *DiskIO) init() error {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ func setupNullDisk(t *testing.T, s *DiskIO, devName string) func() error {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if s.infoCache == nil {
|
if s.infoCache == nil {
|
||||||
s.infoCache = make(map[string]diskInfoCache, 0)
|
s.infoCache = make(map[string]diskInfoCache)
|
||||||
}
|
}
|
||||||
ic, ok := s.infoCache[devName]
|
ic, ok := s.infoCache[devName]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
@ -56,8 +54,7 @@ func (t *transportMock) CancelRequest(_ *http.Request) {
|
||||||
|
|
||||||
func checkIsMaster(es *Elasticsearch, server string, expected bool, t *testing.T) {
|
func checkIsMaster(es *Elasticsearch, server string, expected bool, t *testing.T) {
|
||||||
if es.serverInfo[server].isMaster() != expected {
|
if es.serverInfo[server].isMaster() != expected {
|
||||||
msg := fmt.Sprintf("IsMaster set incorrectly")
|
assert.Fail(t, "IsMaster set incorrectly")
|
||||||
assert.Fail(t, msg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,8 +228,7 @@ func TestGatherClusterStatsMaster(t *testing.T) {
|
||||||
|
|
||||||
IsMasterResultTokens := strings.Split(string(IsMasterResult), " ")
|
IsMasterResultTokens := strings.Split(string(IsMasterResult), " ")
|
||||||
if masterID != IsMasterResultTokens[0] {
|
if masterID != IsMasterResultTokens[0] {
|
||||||
msg := fmt.Sprintf("catmaster is incorrect")
|
assert.Fail(t, "catmaster is incorrect")
|
||||||
assert.Fail(t, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now get node status, which determines whether we're master
|
// now get node status, which determines whether we're master
|
||||||
|
|
@ -275,8 +271,7 @@ func TestGatherClusterStatsNonMaster(t *testing.T) {
|
||||||
|
|
||||||
IsNotMasterResultTokens := strings.Split(string(IsNotMasterResult), " ")
|
IsNotMasterResultTokens := strings.Split(string(IsNotMasterResult), " ")
|
||||||
if masterID != IsNotMasterResultTokens[0] {
|
if masterID != IsNotMasterResultTokens[0] {
|
||||||
msg := fmt.Sprintf("catmaster is incorrect")
|
assert.Fail(t, "catmaster is incorrect")
|
||||||
assert.Fail(t, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now get node status, which determines whether we're master
|
// now get node status, which determines whether we're master
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ func (f *Fibaro) getJSON(path string, dataStruct interface{}) error {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
err = fmt.Errorf("Response from url \"%s\" has status code %d (%s), expected %d (%s)",
|
err = fmt.Errorf("response from url \"%s\" has status code %d (%s), expected %d (%s)",
|
||||||
requestURL,
|
requestURL,
|
||||||
resp.StatusCode,
|
resp.StatusCode,
|
||||||
http.StatusText(resp.StatusCode),
|
http.StatusText(resp.StatusCode),
|
||||||
|
|
@ -159,7 +159,7 @@ func (f *Fibaro) Gather(acc telegraf.Accumulator) error {
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
// skip device in some cases
|
// skip device in some cases
|
||||||
if device.RoomID == 0 ||
|
if device.RoomID == 0 ||
|
||||||
device.Enabled == false ||
|
!device.Enabled ||
|
||||||
device.Properties.Dead == "true" ||
|
device.Properties.Dead == "true" ||
|
||||||
device.Type == "com.fibaro.zwaveDevice" {
|
device.Type == "com.fibaro.zwaveDevice" {
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,7 @@ func parse(data []byte) (datapointArray []pluginData, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, point := range endpointData.Payload {
|
datapointArray = append(datapointArray, endpointData.Payload...)
|
||||||
datapointArray = append(datapointArray, point)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -203,13 +203,13 @@ func (h *GrayLog) flatten(item map[string]interface{}, fields map[string]interfa
|
||||||
id = id + "_"
|
id = id + "_"
|
||||||
}
|
}
|
||||||
for k, i := range item {
|
for k, i := range item {
|
||||||
switch i.(type) {
|
switch i := i.(type) {
|
||||||
case int:
|
case int:
|
||||||
fields[id+k] = i.(float64)
|
fields[id+k] = float64(i)
|
||||||
case float64:
|
case float64:
|
||||||
fields[id+k] = i.(float64)
|
fields[id+k] = i
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
h.flatten(i.(map[string]interface{}), fields, id+k)
|
h.flatten(i, fields, id+k)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,9 +95,7 @@ func (h *haproxy) Gather(acc telegraf.Accumulator) error {
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
endpoints = append(endpoints, socketPath)
|
endpoints = append(endpoints, socketPath)
|
||||||
} else {
|
} else {
|
||||||
for _, match := range matches {
|
endpoints = append(endpoints, matches...)
|
||||||
endpoints = append(endpoints, match)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ func (h *HTTPResponse) createHTTPClient() (*http.Client, error) {
|
||||||
Timeout: h.ResponseTimeout.Duration,
|
Timeout: h.ResponseTimeout.Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.FollowRedirects == false {
|
if !h.FollowRedirects {
|
||||||
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
||||||
return http.ErrUseLastResponse
|
return http.ErrUseLastResponse
|
||||||
}
|
}
|
||||||
|
|
@ -247,10 +247,10 @@ func setError(err error, fields map[string]interface{}, tags map[string]string)
|
||||||
opErr, isNetErr := (urlErr.Err).(*net.OpError)
|
opErr, isNetErr := (urlErr.Err).(*net.OpError)
|
||||||
if isNetErr {
|
if isNetErr {
|
||||||
switch e := (opErr.Err).(type) {
|
switch e := (opErr.Err).(type) {
|
||||||
case (*net.DNSError):
|
case *net.DNSError:
|
||||||
setResult("dns_error", fields, tags)
|
setResult("dns_error", fields, tags)
|
||||||
return e
|
return e
|
||||||
case (*net.ParseError):
|
case *net.ParseError:
|
||||||
// Parse error has to do with parsing of IP addresses, so we
|
// Parse error has to do with parsing of IP addresses, so we
|
||||||
// group it with address errors
|
// group it with address errors
|
||||||
setResult("address_error", fields, tags)
|
setResult("address_error", fields, tags)
|
||||||
|
|
@ -412,7 +412,7 @@ func (h *HTTPResponse) Gather(acc telegraf.Accumulator) error {
|
||||||
var err error
|
var err error
|
||||||
h.compiledStringMatch, err = regexp.Compile(h.ResponseStringMatch)
|
h.compiledStringMatch, err = regexp.Compile(h.ResponseStringMatch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to compile regular expression %s : %s", h.ResponseStringMatch, err)
|
return fmt.Errorf("failed to compile regular expression %s : %s", h.ResponseStringMatch, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,7 +450,7 @@ func (h *HTTPResponse) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if addr.Scheme != "http" && addr.Scheme != "https" {
|
if addr.Scheme != "http" && addr.Scheme != "https" {
|
||||||
acc.AddError(errors.New("Only http and https are supported"))
|
acc.AddError(errors.New("only http and https are supported"))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,6 @@ func setUpTestMux() http.Handler {
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/twosecondnap", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/twosecondnap", func(w http.ResponseWriter, req *http.Request) {
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
return
|
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/nocontent", func(w http.ResponseWriter, _ *http.Request) {
|
mux.HandleFunc("/nocontent", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ func (h *InfluxDBListener) handleWrite() http.HandlerFunc {
|
||||||
var partialErrorString string
|
var partialErrorString string
|
||||||
switch parseErrorCount {
|
switch parseErrorCount {
|
||||||
case 1:
|
case 1:
|
||||||
partialErrorString = fmt.Sprintf("%s", firstParseErrorStr)
|
partialErrorString = firstParseErrorStr
|
||||||
case 2:
|
case 2:
|
||||||
partialErrorString = fmt.Sprintf("%s (and 1 other parse error)", firstParseErrorStr)
|
partialErrorString = fmt.Sprintf("%s (and 1 other parse error)", firstParseErrorStr)
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,6 @@ func (r *IntelRDT) createArgsAndStartPQOS(ctx context.Context) {
|
||||||
args = append(args, processArg)
|
args = append(args, processArg)
|
||||||
go r.readData(ctx, args, r.processesPIDsMap)
|
go r.readData(ctx, args, r.processesPIDsMap)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *IntelRDT) readData(ctx context.Context, args []string, processesPIDsAssociation map[string]string) {
|
func (r *IntelRDT) readData(ctx context.Context, args []string, processesPIDsAssociation map[string]string) {
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ func (p *Publisher) publishCores(measurement string) {
|
||||||
p.errChan <- err
|
p.errChan <- err
|
||||||
}
|
}
|
||||||
p.addToAccumulatorCores(coresString, values, timestamp)
|
p.addToAccumulatorCores(coresString, values, timestamp)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Publisher) publishProcess(measurement processMeasurement) {
|
func (p *Publisher) publishProcess(measurement processMeasurement) {
|
||||||
|
|
@ -63,7 +62,6 @@ func (p *Publisher) publishProcess(measurement processMeasurement) {
|
||||||
p.errChan <- err
|
p.errChan <- err
|
||||||
}
|
}
|
||||||
p.addToAccumulatorProcesses(process, coresString, values, timestamp)
|
p.addToAccumulatorProcesses(process, coresString, values, timestamp)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCoresMeasurement(measurements string) (string, []float64, time.Time, error) {
|
func parseCoresMeasurement(measurements string) (string, []float64, time.Time, error) {
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ func (j *Jenkins) getJobDetail(jr jobRequest, acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter out not included job.
|
// filter out not included job.
|
||||||
if j.jobFilterInclude != nil && j.jobFilterInclude.Match(jr.hierarchyName()) == false {
|
if j.jobFilterInclude != nil && !j.jobFilterInclude.Match(jr.hierarchyName()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ func (g *Gatherer) Gather(client *Client, acc telegraf.Accumulator) error {
|
||||||
// gatherResponses adds points to an accumulator from the ReadResponse objects
|
// gatherResponses adds points to an accumulator from the ReadResponse objects
|
||||||
// returned by a Jolokia agent.
|
// returned by a Jolokia agent.
|
||||||
func (g *Gatherer) gatherResponses(responses []ReadResponse, tags map[string]string, acc telegraf.Accumulator) {
|
func (g *Gatherer) gatherResponses(responses []ReadResponse, tags map[string]string, acc telegraf.Accumulator) {
|
||||||
series := make(map[string][]point, 0)
|
series := make(map[string][]point)
|
||||||
|
|
||||||
for _, metric := range g.metrics {
|
for _, metric := range g.metrics {
|
||||||
points, ok := series[metric.Name]
|
points, ok := series[metric.Name]
|
||||||
|
|
@ -55,11 +55,7 @@ func (g *Gatherer) gatherResponses(responses []ReadResponse, tags map[string]str
|
||||||
}
|
}
|
||||||
|
|
||||||
responsePoints, responseErrors := g.generatePoints(metric, responses)
|
responsePoints, responseErrors := g.generatePoints(metric, responses)
|
||||||
|
points = append(points, responsePoints...)
|
||||||
for _, responsePoint := range responsePoints {
|
|
||||||
points = append(points, responsePoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, err := range responseErrors {
|
for _, err := range responseErrors {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +84,7 @@ func (g *Gatherer) generatePoints(metric Metric, responses []ReadResponse) ([]po
|
||||||
case 404:
|
case 404:
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
errors = append(errors, fmt.Errorf("Unexpected status in response from target %s (%q): %d",
|
errors = append(errors, fmt.Errorf("unexpected status in response from target %s (%q): %d",
|
||||||
response.RequestTarget, response.RequestMbean, response.Status))
|
response.RequestTarget, response.RequestMbean, response.Status))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -750,8 +750,7 @@ func TestJolokia2_ProxyTargets(t *testing.T) {
|
||||||
|
|
||||||
func TestFillFields(t *testing.T) {
|
func TestFillFields(t *testing.T) {
|
||||||
complex := map[string]interface{}{"Value": []interface{}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
|
complex := map[string]interface{}{"Value": []interface{}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
|
||||||
var scalar interface{}
|
scalar := []interface{}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
scalar = []interface{}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
|
||||||
|
|
||||||
results := map[string]interface{}{}
|
results := map[string]interface{}{}
|
||||||
newPointBuilder(Metric{Name: "test", Mbean: "complex"}, []string{"this", "that"}, "/").fillFields("", complex, results)
|
newPointBuilder(Metric{Name: "test", Mbean: "complex"}, []string{"this", "that"}, "/").fillFields("", complex, results)
|
||||||
|
|
|
||||||
|
|
@ -169,25 +169,18 @@ func (m *OpenConfigTelemetry) extractData(r *telemetry.OpenConfigData, grpcServe
|
||||||
} else {
|
} else {
|
||||||
kv[xmlpath] = v.GetStrValue()
|
kv[xmlpath] = v.GetStrValue()
|
||||||
}
|
}
|
||||||
break
|
|
||||||
case *telemetry.KeyValue_DoubleValue:
|
case *telemetry.KeyValue_DoubleValue:
|
||||||
kv[xmlpath] = v.GetDoubleValue()
|
kv[xmlpath] = v.GetDoubleValue()
|
||||||
break
|
|
||||||
case *telemetry.KeyValue_IntValue:
|
case *telemetry.KeyValue_IntValue:
|
||||||
kv[xmlpath] = v.GetIntValue()
|
kv[xmlpath] = v.GetIntValue()
|
||||||
break
|
|
||||||
case *telemetry.KeyValue_UintValue:
|
case *telemetry.KeyValue_UintValue:
|
||||||
kv[xmlpath] = v.GetUintValue()
|
kv[xmlpath] = v.GetUintValue()
|
||||||
break
|
|
||||||
case *telemetry.KeyValue_SintValue:
|
case *telemetry.KeyValue_SintValue:
|
||||||
kv[xmlpath] = v.GetSintValue()
|
kv[xmlpath] = v.GetSintValue()
|
||||||
break
|
|
||||||
case *telemetry.KeyValue_BoolValue:
|
case *telemetry.KeyValue_BoolValue:
|
||||||
kv[xmlpath] = v.GetBoolValue()
|
kv[xmlpath] = v.GetBoolValue()
|
||||||
break
|
|
||||||
case *telemetry.KeyValue_BytesValue:
|
case *telemetry.KeyValue_BytesValue:
|
||||||
kv[xmlpath] = v.GetBytesValue()
|
kv[xmlpath] = v.GetBytesValue()
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert other tags from message
|
// Insert other tags from message
|
||||||
|
|
|
||||||
|
|
@ -219,10 +219,8 @@ func (k *Kapacitor) gatherURL(
|
||||||
// Strip out high-cardinality or duplicative tags
|
// Strip out high-cardinality or duplicative tags
|
||||||
excludeTags := []string{"host", "cluster_id", "server_id"}
|
excludeTags := []string{"host", "cluster_id", "server_id"}
|
||||||
for _, key := range excludeTags {
|
for _, key := range excludeTags {
|
||||||
if _, ok := obj.Tags[key]; ok {
|
|
||||||
delete(obj.Tags, key)
|
delete(obj.Tags, key)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Convert time-related string field to int
|
// Convert time-related string field to int
|
||||||
if _, ok := obj.Values["avg_exec_time_ns"]; ok {
|
if _, ok := obj.Values["avg_exec_time_ns"]; ok {
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,6 @@ func (m *Mesos) Gather(acc telegraf.Accumulator) error {
|
||||||
go func(master *url.URL) {
|
go func(master *url.URL) {
|
||||||
acc.AddError(m.gatherMainMetrics(master, MASTER, acc))
|
acc.AddError(m.gatherMainMetrics(master, MASTER, acc))
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return
|
|
||||||
}(master)
|
}(master)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,7 +193,6 @@ func (m *Mesos) Gather(acc telegraf.Accumulator) error {
|
||||||
go func(slave *url.URL) {
|
go func(slave *url.URL) {
|
||||||
acc.AddError(m.gatherMainMetrics(slave, SLAVE, acc))
|
acc.AddError(m.gatherMainMetrics(slave, SLAVE, acc))
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return
|
|
||||||
}(slave)
|
}(slave)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,9 +242,7 @@ func metricsDiff(role Role, w []string) []string {
|
||||||
|
|
||||||
// masterBlocks serves as kind of metrics registry grouping them in sets
|
// masterBlocks serves as kind of metrics registry grouping them in sets
|
||||||
func getMetrics(role Role, group string) []string {
|
func getMetrics(role Role, group string) []string {
|
||||||
var m map[string][]string
|
m := make(map[string][]string)
|
||||||
|
|
||||||
m = make(map[string][]string)
|
|
||||||
|
|
||||||
if role == MASTER {
|
if role == MASTER {
|
||||||
m["resources"] = []string{
|
m["resources"] = []string{
|
||||||
|
|
@ -504,13 +500,13 @@ func (m *Mesos) filterMetrics(role Role, metrics *map[string]interface{}) {
|
||||||
case "allocator":
|
case "allocator":
|
||||||
for m := range *metrics {
|
for m := range *metrics {
|
||||||
if strings.HasPrefix(m, "allocator/") {
|
if strings.HasPrefix(m, "allocator/") {
|
||||||
delete((*metrics), m)
|
delete(*metrics, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "framework_offers":
|
case "framework_offers":
|
||||||
for m := range *metrics {
|
for m := range *metrics {
|
||||||
if strings.HasPrefix(m, "master/frameworks/") || strings.HasPrefix(m, "frameworks/") {
|
if strings.HasPrefix(m, "master/frameworks/") || strings.HasPrefix(m, "frameworks/") {
|
||||||
delete((*metrics), m)
|
delete(*metrics, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -518,7 +514,7 @@ func (m *Mesos) filterMetrics(role Role, metrics *map[string]interface{}) {
|
||||||
default:
|
default:
|
||||||
for _, v := range getMetrics(role, k) {
|
for _, v := range getMetrics(role, k) {
|
||||||
if _, ok = (*metrics)[v]; ok {
|
if _, ok = (*metrics)[v]; ok {
|
||||||
delete((*metrics), v)
|
delete(*metrics, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -208,9 +208,7 @@ func (m *Modbus) InitRegister(fields []fieldContainer, name string) error {
|
||||||
|
|
||||||
addrs := []uint16{}
|
addrs := []uint16{}
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
for _, a := range field.Address {
|
addrs = append(addrs, field.Address...)
|
||||||
addrs = append(addrs, a)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs = removeDuplicates(addrs)
|
addrs = removeDuplicates(addrs)
|
||||||
|
|
|
||||||
|
|
@ -1220,9 +1220,7 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
|
||||||
// Get the entry with the highest lock
|
// Get the entry with the highest lock
|
||||||
highestLocked := lockdiffs[len(lockdiffs)-1]
|
highestLocked := lockdiffs[len(lockdiffs)-1]
|
||||||
|
|
||||||
var timeDiffMillis int64
|
timeDiffMillis := newStat.UptimeMillis - oldStat.UptimeMillis
|
||||||
timeDiffMillis = newStat.UptimeMillis - oldStat.UptimeMillis
|
|
||||||
|
|
||||||
lockToReport := highestLocked.Writes
|
lockToReport := highestLocked.Writes
|
||||||
|
|
||||||
// if the highest locked namespace is not '.'
|
// if the highest locked namespace is not '.'
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,6 @@ func (m *MQTTConsumer) onConnectionLost(_ mqtt.Client, err error) {
|
||||||
m.acc.AddError(fmt.Errorf("connection lost: %v", err))
|
m.acc.AddError(fmt.Errorf("connection lost: %v", err))
|
||||||
m.Log.Debugf("Disconnected %v", m.Servers)
|
m.Log.Debugf("Disconnected %v", m.Servers)
|
||||||
m.state = Disconnected
|
m.state = Disconnected
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MQTTConsumer) recvMessage(_ mqtt.Client, msg mqtt.Message) {
|
func (m *MQTTConsumer) recvMessage(_ mqtt.Client, msg mqtt.Message) {
|
||||||
|
|
|
||||||
|
|
@ -1858,11 +1858,11 @@ func (m *Mysql) parseValue(value sql.RawBytes) (interface{}, bool) {
|
||||||
|
|
||||||
// parseValue can be used to convert values such as "ON","OFF","Yes","No" to 0,1
|
// parseValue can be used to convert values such as "ON","OFF","Yes","No" to 0,1
|
||||||
func parseValue(value sql.RawBytes) (interface{}, bool) {
|
func parseValue(value sql.RawBytes) (interface{}, bool) {
|
||||||
if bytes.EqualFold(value, []byte("YES")) || bytes.Compare(value, []byte("ON")) == 0 {
|
if bytes.EqualFold(value, []byte("YES")) || bytes.Equal(value, []byte("ON")) {
|
||||||
return 1, true
|
return 1, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.EqualFold(value, []byte("NO")) || bytes.Compare(value, []byte("OFF")) == 0 {
|
if bytes.EqualFold(value, []byte("NO")) || bytes.Equal(value, []byte("OFF")) {
|
||||||
return 0, true
|
return 0, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,11 +183,11 @@ var Mappings = []*Mapping{
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseValue(value sql.RawBytes) (float64, bool) {
|
func ParseValue(value sql.RawBytes) (float64, bool) {
|
||||||
if bytes.Compare(value, []byte("Yes")) == 0 || bytes.Compare(value, []byte("ON")) == 0 {
|
if bytes.Equal(value, []byte("Yes")) || bytes.Equal(value, []byte("ON")) {
|
||||||
return 1, true
|
return 1, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(value, []byte("No")) == 0 || bytes.Compare(value, []byte("OFF")) == 0 {
|
if bytes.Equal(value, []byte("No")) || bytes.Equal(value, []byte("OFF")) {
|
||||||
return 0, true
|
return 0, true
|
||||||
}
|
}
|
||||||
n, err := strconv.ParseFloat(string(value), 64)
|
n, err := strconv.ParseFloat(string(value), 64)
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,11 @@ func ParseGTIDMode(value sql.RawBytes) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseValue(value sql.RawBytes) (interface{}, error) {
|
func ParseValue(value sql.RawBytes) (interface{}, error) {
|
||||||
if bytes.EqualFold(value, []byte("YES")) || bytes.Compare(value, []byte("ON")) == 0 {
|
if bytes.EqualFold(value, []byte("YES")) || bytes.Equal(value, []byte("ON")) {
|
||||||
return 1, nil
|
return 1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.EqualFold(value, []byte("NO")) || bytes.Compare(value, []byte("OFF")) == 0 {
|
if bytes.EqualFold(value, []byte("NO")) || bytes.Equal(value, []byte("OFF")) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -437,7 +437,7 @@ func TestSendRequest(t *testing.T) {
|
||||||
if test.wantErr {
|
if test.wantErr {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.Compare(resp, []byte("data")) != 0 {
|
if !bytes.Equal(resp, []byte("data")) {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"Response data mismatch. got=%q, want=%q", resp, "data")
|
"Response data mismatch. got=%q, want=%q", resp, "data")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,6 @@ func gatherSearchResult(sr *ldap.SearchResult, o *Openldap, acc telegraf.Accumul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
acc.AddFields("openldap", fields, tags)
|
acc.AddFields("openldap", fields, tags)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert a DN to metric name, eg cn=Read,cn=Waiters,cn=Monitor becomes waiters_read
|
// Convert a DN to metric name, eg cn=Read,cn=Waiters,cn=Monitor becomes waiters_read
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ func qScan(path string, acc telegraf.Accumulator) (int64, int64, int64, error) {
|
||||||
}
|
}
|
||||||
var age int64
|
var age int64
|
||||||
if !oldest.IsZero() {
|
if !oldest.IsZero() {
|
||||||
age = int64(time.Now().Sub(oldest) / time.Second)
|
age = int64(time.Since(oldest) / time.Second)
|
||||||
} else if length != 0 {
|
} else if length != 0 {
|
||||||
// system doesn't support ctime
|
// system doesn't support ctime
|
||||||
age = -1
|
age = -1
|
||||||
|
|
|
||||||
|
|
@ -289,15 +289,15 @@ type fakeRow struct {
|
||||||
|
|
||||||
func (f fakeRow) Scan(dest ...interface{}) error {
|
func (f fakeRow) Scan(dest ...interface{}) error {
|
||||||
if len(f.fields) != len(dest) {
|
if len(f.fields) != len(dest) {
|
||||||
return errors.New("Nada matchy buddy")
|
return errors.New("nada matchy buddy")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, d := range dest {
|
for i, d := range dest {
|
||||||
switch d.(type) {
|
switch d := d.(type) {
|
||||||
case (*interface{}):
|
case *interface{}:
|
||||||
*d.(*interface{}) = f.fields[i]
|
*d = f.fields[i]
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Bad type %T", d)
|
return fmt.Errorf("bad type %T", d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,8 @@ func (p *Prometheus) Init() error {
|
||||||
// Check if set as env var and is valid IP address
|
// Check if set as env var and is valid IP address
|
||||||
envVarNodeIP := os.Getenv("NODE_IP")
|
envVarNodeIP := os.Getenv("NODE_IP")
|
||||||
if envVarNodeIP == "" || net.ParseIP(envVarNodeIP) == nil {
|
if envVarNodeIP == "" || net.ParseIP(envVarNodeIP) == nil {
|
||||||
errorMessage := "The node_ip config and the environment variable NODE_IP are not set or invalid. Cannot get pod list for monitor_kubernetes_pods using node scrape scope"
|
return errors.New("the node_ip config and the environment variable NODE_IP are not set or invalid; " +
|
||||||
return errors.New(errorMessage)
|
"cannot get pod list for monitor_kubernetes_pods using node scrape scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.NodeIP = envVarNodeIP
|
p.NodeIP = envVarNodeIP
|
||||||
|
|
@ -180,15 +180,15 @@ func (p *Prometheus) Init() error {
|
||||||
var err error
|
var err error
|
||||||
p.podLabelSelector, err = labels.Parse(p.KubernetesLabelSelector)
|
p.podLabelSelector, err = labels.Parse(p.KubernetesLabelSelector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error parsing the specified label selector(s): %s", err.Error())
|
return fmt.Errorf("error parsing the specified label selector(s): %s", err.Error())
|
||||||
}
|
}
|
||||||
p.podFieldSelector, err = fields.ParseSelector(p.KubernetesFieldSelector)
|
p.podFieldSelector, err = fields.ParseSelector(p.KubernetesFieldSelector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error parsing the specified field selector(s): %s", err.Error())
|
return fmt.Errorf("error parsing the specified field selector(s): %s", err.Error())
|
||||||
}
|
}
|
||||||
isValid, invalidSelector := fieldSelectorIsSupported(p.podFieldSelector)
|
isValid, invalidSelector := fieldSelectorIsSupported(p.podFieldSelector)
|
||||||
if !isValid {
|
if !isValid {
|
||||||
return fmt.Errorf("The field selector %s is not supported for pods", invalidSelector)
|
return fmt.Errorf("the field selector %s is not supported for pods", invalidSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Log.Infof("Using pod scrape scope at node level to get pod list using cAdvisor.")
|
p.Log.Infof("Using pod scrape scope at node level to get pod list using cAdvisor.")
|
||||||
|
|
@ -227,7 +227,7 @@ type URLAndAddress struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Prometheus) GetAllURLs() (map[string]URLAndAddress, error) {
|
func (p *Prometheus) GetAllURLs() (map[string]URLAndAddress, error) {
|
||||||
allURLs := make(map[string]URLAndAddress, 0)
|
allURLs := make(map[string]URLAndAddress)
|
||||||
for _, u := range p.URLs {
|
for _, u := range p.URLs {
|
||||||
URL, err := url.Parse(u)
|
URL, err := url.Parse(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -261,23 +261,23 @@ func TestInitConfigErrors(t *testing.T) {
|
||||||
p.NodeIP = "10.240.0.0.0"
|
p.NodeIP = "10.240.0.0.0"
|
||||||
os.Setenv("NODE_IP", "10.000.0.0.0")
|
os.Setenv("NODE_IP", "10.000.0.0.0")
|
||||||
err := p.Init()
|
err := p.Init()
|
||||||
expectedMessage := "The node_ip config and the environment variable NODE_IP are not set or invalid. Cannot get pod list for monitor_kubernetes_pods using node scrape scope"
|
expectedMessage := "the node_ip config and the environment variable NODE_IP are not set or invalid. Cannot get pod list for monitor_kubernetes_pods using node scrape scope"
|
||||||
assert.Equal(t, expectedMessage, err.Error())
|
require.Error(t, err, expectedMessage)
|
||||||
os.Setenv("NODE_IP", "10.000.0.0")
|
os.Setenv("NODE_IP", "10.000.0.0")
|
||||||
|
|
||||||
p.KubernetesLabelSelector = "label0==label0, label0 in (=)"
|
p.KubernetesLabelSelector = "label0==label0, label0 in (=)"
|
||||||
err = p.Init()
|
err = p.Init()
|
||||||
expectedMessage = "Error parsing the specified label selector(s): unable to parse requirement: found '=', expected: ',', ')' or identifier"
|
expectedMessage = "error parsing the specified label selector(s): unable to parse requirement: found '=', expected: ',', ')' or identifier"
|
||||||
assert.Equal(t, expectedMessage, err.Error())
|
require.Error(t, err, expectedMessage)
|
||||||
p.KubernetesLabelSelector = "label0==label"
|
p.KubernetesLabelSelector = "label0==label"
|
||||||
|
|
||||||
p.KubernetesFieldSelector = "field,"
|
p.KubernetesFieldSelector = "field,"
|
||||||
err = p.Init()
|
err = p.Init()
|
||||||
expectedMessage = "Error parsing the specified field selector(s): invalid selector: 'field,'; can't understand 'field'"
|
expectedMessage = "error parsing the specified field selector(s): invalid selector: 'field,'; can't understand 'field'"
|
||||||
assert.Equal(t, expectedMessage, err.Error())
|
require.Error(t, err, expectedMessage)
|
||||||
|
|
||||||
p.KubernetesFieldSelector = "spec.containerNames=containerNames"
|
p.KubernetesFieldSelector = "spec.containerNames=containerNames"
|
||||||
err = p.Init()
|
err = p.Init()
|
||||||
expectedMessage = "The field selector spec.containerNames is not supported for pods"
|
expectedMessage = "the field selector spec.containerNames is not supported for pods"
|
||||||
assert.Equal(t, expectedMessage, err.Error())
|
require.Error(t, err, expectedMessage)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ func fillnode(parentNode Node, oidName string, ids []string) {
|
||||||
// ids = ["1", "3", "6", ...]
|
// ids = ["1", "3", "6", ...]
|
||||||
id, ids := ids[0], ids[1:]
|
id, ids := ids[0], ids[1:]
|
||||||
node, ok := parentNode.subnodes[id]
|
node, ok := parentNode.subnodes[id]
|
||||||
if ok == false {
|
if !ok {
|
||||||
node = Node{
|
node = Node{
|
||||||
id: id,
|
id: id,
|
||||||
name: "",
|
name: "",
|
||||||
|
|
|
||||||
|
|
@ -151,11 +151,8 @@ func sendTrap(t *testing.T, goSNMP gosnmp.GoSNMP, trap gosnmp.SnmpTrap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReceiveTrap(t *testing.T) {
|
func TestReceiveTrap(t *testing.T) {
|
||||||
var now uint32
|
now := uint32(123123123)
|
||||||
now = 123123123
|
fakeTime := time.Unix(456456456, 456)
|
||||||
|
|
||||||
var fakeTime time.Time
|
|
||||||
fakeTime = time.Unix(456456456, 456)
|
|
||||||
|
|
||||||
type entry struct {
|
type entry struct {
|
||||||
oid string
|
oid string
|
||||||
|
|
|
||||||
|
|
@ -162,8 +162,5 @@ func TestRunningStats_PercentileLimit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fuzzyEqual(a, b, epsilon float64) bool {
|
func fuzzyEqual(a, b, epsilon float64) bool {
|
||||||
if math.Abs(a-b) > epsilon {
|
return math.Abs(a-b) <= epsilon
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ func (s *Sysstat) parse(acc telegraf.Accumulator, option string, ts time.Time) e
|
||||||
tags: make(map[string]string),
|
tags: make(map[string]string),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g, _ := m[device]
|
g := m[device]
|
||||||
if len(g.tags) == 0 {
|
if len(g.tags) == 0 {
|
||||||
for k, v := range tags {
|
for k, v := range tags {
|
||||||
g.tags[k] = v
|
g.tags[k] = v
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,7 @@ func TestTengineTags(t *testing.T) {
|
||||||
|
|
||||||
func TestTengineGeneratesMetrics(t *testing.T) {
|
func TestTengineGeneratesMetrics(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var rsp string
|
rsp := tengineSampleResponse
|
||||||
rsp = tengineSampleResponse
|
|
||||||
fmt.Fprintln(w, rsp)
|
fmt.Fprintln(w, rsp)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
|
||||||
|
|
@ -891,7 +891,7 @@ func (e *Endpoint) chunkify(ctx context.Context, res *resourceKind, now time.Tim
|
||||||
numQs := 0
|
numQs := 0
|
||||||
|
|
||||||
for _, object := range res.objects {
|
for _, object := range res.objects {
|
||||||
timeBuckets := make(map[int64]*types.PerfQuerySpec, 0)
|
timeBuckets := make(map[int64]*types.PerfQuerySpec)
|
||||||
for metricIdx, metric := range res.metrics {
|
for metricIdx, metric := range res.metrics {
|
||||||
// Determine time of last successful collection
|
// Determine time of last successful collection
|
||||||
metricName := e.getMetricNameForID(metric.CounterId)
|
metricName := e.getMetricNameForID(metric.CounterId)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func (t *TSCache) Purge() {
|
||||||
defer t.mux.Unlock()
|
defer t.mux.Unlock()
|
||||||
n := 0
|
n := 0
|
||||||
for k, v := range t.table {
|
for k, v := range t.table {
|
||||||
if time.Now().Sub(v) > t.ttl {
|
if time.Since(v) > t.ttl {
|
||||||
delete(t.table, k)
|
delete(t.table, k)
|
||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ func (wb *Webhooks) Start(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
wb.srv = &http.Server{Handler: r}
|
wb.srv = &http.Server{Handler: r}
|
||||||
|
|
||||||
ln, err := net.Listen("tcp", fmt.Sprintf("%s", wb.ServiceAddress))
|
ln, err := net.Listen("tcp", wb.ServiceAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error starting server: %v", err)
|
return fmt.Errorf("error starting server: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ func (c *X509Cert) getCert(u *url.URL, timeout time.Duration) ([]*x509.Certifica
|
||||||
}
|
}
|
||||||
certs = append(certs, cert)
|
certs = append(certs, cert)
|
||||||
}
|
}
|
||||||
if rest == nil || len(rest) == 0 {
|
if len(rest) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
content = rest
|
content = rest
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package amqp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -29,7 +28,7 @@ func (a *externalAuth) Mechanism() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *externalAuth) Response() string {
|
func (a *externalAuth) Response() string {
|
||||||
return fmt.Sprintf("\000")
|
return "\000"
|
||||||
}
|
}
|
||||||
|
|
||||||
type AMQP struct {
|
type AMQP struct {
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,10 @@ func (f *statisticField) buildDatum() []*cloudwatch.MetricDatum {
|
||||||
|
|
||||||
if f.hasAllFields() {
|
if f.hasAllFields() {
|
||||||
// If we have all required fields, we build datum with StatisticValues
|
// If we have all required fields, we build datum with StatisticValues
|
||||||
min, _ := f.values[statisticTypeMin]
|
min := f.values[statisticTypeMin]
|
||||||
max, _ := f.values[statisticTypeMax]
|
max := f.values[statisticTypeMax]
|
||||||
sum, _ := f.values[statisticTypeSum]
|
sum := f.values[statisticTypeSum]
|
||||||
count, _ := f.values[statisticTypeCount]
|
count := f.values[statisticTypeCount]
|
||||||
|
|
||||||
datum := &cloudwatch.MetricDatum{
|
datum := &cloudwatch.MetricDatum{
|
||||||
MetricName: aws.String(strings.Join([]string{f.metricName, f.fieldName}, "_")),
|
MetricName: aws.String(strings.Join([]string{f.metricName, f.fieldName}, "_")),
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,6 @@ func (c *Collector) Describe(_ chan<- *prometheus.Desc) {
|
||||||
// Sending no descriptor at all marks the Collector as "unchecked",
|
// Sending no descriptor at all marks the Collector as "unchecked",
|
||||||
// i.e. no checks will be performed at registration time, and the
|
// i.e. no checks will be performed at registration time, and the
|
||||||
// Collector may yield any Metric it sees fit in its Collect method.
|
// Collector may yield any Metric it sees fit in its Collect method.
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
|
||||||
|
|
||||||
if r.client == nil {
|
if r.client == nil {
|
||||||
if err := r.Connect(); err != nil {
|
if err := r.Connect(); err != nil {
|
||||||
return fmt.Errorf("Failed to (re)connect to Riemann: %s", err.Error())
|
return fmt.Errorf("failed to (re)connect to Riemann: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,14 +109,12 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
|
||||||
var events []*raidman.Event
|
var events []*raidman.Event
|
||||||
for _, m := range metrics {
|
for _, m := range metrics {
|
||||||
evs := r.buildRiemannEvents(m)
|
evs := r.buildRiemannEvents(m)
|
||||||
for _, ev := range evs {
|
events = append(events, evs...)
|
||||||
events = append(events, ev)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.client.SendMulti(events); err != nil {
|
if err := r.client.SendMulti(events); err != nil {
|
||||||
r.Close()
|
r.Close()
|
||||||
return fmt.Errorf("Failed to send riemann message: %s", err)
|
return fmt.Errorf("failed to send riemann message: %s", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -145,14 +143,14 @@ func (r *Riemann) buildRiemannEvents(m telegraf.Metric) []*raidman.Event {
|
||||||
Tags: r.tags(m.Tags()),
|
Tags: r.tags(m.Tags()),
|
||||||
}
|
}
|
||||||
|
|
||||||
switch value.(type) {
|
switch value := value.(type) {
|
||||||
case string:
|
case string:
|
||||||
// only send string metrics if explicitly enabled, skip otherwise
|
// only send string metrics if explicitly enabled, skip otherwise
|
||||||
if !r.StringAsState {
|
if !r.StringAsState {
|
||||||
r.Log.Debugf("Riemann event states disabled, skipping metric value [%s]", value)
|
r.Log.Debugf("Riemann event states disabled, skipping metric value [%s]", value)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
event.State = value.(string)
|
event.State = value
|
||||||
case int, int64, uint64, float32, float64:
|
case int, int64, uint64, float32, float64:
|
||||||
event.Metric = value
|
event.Metric = value
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,7 @@ func (r *Riemann) Write(metrics []telegraf.Metric) error {
|
||||||
var events []*raidman.Event
|
var events []*raidman.Event
|
||||||
for _, p := range metrics {
|
for _, p := range metrics {
|
||||||
evs := buildEvents(p, r.Separator)
|
evs := buildEvents(p, r.Separator)
|
||||||
for _, ev := range evs {
|
events = append(events, evs...)
|
||||||
events = append(events, ev)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var senderr = r.client.SendMulti(events)
|
var senderr = r.client.SendMulti(events)
|
||||||
|
|
@ -109,9 +107,9 @@ func buildEvents(p telegraf.Metric, s string) []*raidman.Event {
|
||||||
Service: serviceName(s, p.Name(), p.Tags(), fieldName),
|
Service: serviceName(s, p.Name(), p.Tags(), fieldName),
|
||||||
}
|
}
|
||||||
|
|
||||||
switch value.(type) {
|
switch value := value.(type) {
|
||||||
case string:
|
case string:
|
||||||
event.State = value.(string)
|
event.State = value
|
||||||
default:
|
default:
|
||||||
event.Metric = value
|
event.Metric = value
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,10 +130,8 @@ func (s *SignalFx) ConvertToSignalFx(metrics []telegraf.Metric) ([]*datapoint.Da
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
s.Log.Debugf("Processing the following measurement: %v", metric)
|
s.Log.Debugf("Processing the following measurement: %v", metric)
|
||||||
var timestamp = metric.Time()
|
var timestamp = metric.Time()
|
||||||
var metricType datapoint.MetricType
|
|
||||||
|
|
||||||
metricType = GetMetricType(metric.Type())
|
|
||||||
|
|
||||||
|
metricType := GetMetricType(metric.Type())
|
||||||
for field, val := range metric.Fields() {
|
for field, val := range metric.Fields() {
|
||||||
// Copy the metric tags because they are meant to be treated as
|
// Copy the metric tags because they are meant to be treated as
|
||||||
// immutable
|
// immutable
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ func buildTags(tags []*telegraf.Tag) []string {
|
||||||
indexSource = index
|
indexSource = index
|
||||||
}
|
}
|
||||||
indexSource++
|
indexSource++
|
||||||
tagsString[indexSource] = fmt.Sprintf("source=telegraf")
|
tagsString[indexSource] = "source=telegraf"
|
||||||
sort.Strings(tagsString)
|
sort.Strings(tagsString)
|
||||||
return tagsString
|
return tagsString
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package warp10
|
package warp10
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
|
|
@ -60,7 +59,7 @@ func TestHandleWarp10Error(t *testing.T) {
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`,
|
`,
|
||||||
Expected: fmt.Sprintf("Invalid token"),
|
Expected: "Invalid token",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Message: `
|
Message: `
|
||||||
|
|
@ -75,7 +74,7 @@ func TestHandleWarp10Error(t *testing.T) {
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`,
|
`,
|
||||||
Expected: fmt.Sprintf("Token Expired"),
|
Expected: "Token Expired",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Message: `
|
Message: `
|
||||||
|
|
@ -90,7 +89,7 @@ func TestHandleWarp10Error(t *testing.T) {
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`,
|
`,
|
||||||
Expected: fmt.Sprintf("Token revoked"),
|
Expected: "Token revoked",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Message: `
|
Message: `
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func NewCollectdParser(
|
||||||
func (p *CollectdParser) Parse(buf []byte) ([]telegraf.Metric, error) {
|
func (p *CollectdParser) Parse(buf []byte) ([]telegraf.Metric, error) {
|
||||||
valueLists, err := network.Parse(buf, p.popts)
|
valueLists, err := network.Parse(buf, p.popts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Collectd parser error: %s", err)
|
return nil, fmt.Errorf("collectd parser error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics := []telegraf.Metric{}
|
metrics := []telegraf.Metric{}
|
||||||
|
|
@ -105,7 +105,7 @@ func (p *CollectdParser) ParseLine(line string) (telegraf.Metric, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(metrics) != 1 {
|
if len(metrics) != 1 {
|
||||||
return nil, errors.New("Line contains multiple metrics")
|
return nil, errors.New("line contains multiple metrics")
|
||||||
}
|
}
|
||||||
|
|
||||||
return metrics[0], nil
|
return metrics[0], nil
|
||||||
|
|
@ -128,8 +128,7 @@ func UnmarshalValueList(vl *api.ValueList, multiValue string) []telegraf.Metric
|
||||||
switch multiValue {
|
switch multiValue {
|
||||||
case "split":
|
case "split":
|
||||||
for i := range vl.Values {
|
for i := range vl.Values {
|
||||||
var name string
|
name := fmt.Sprintf("%s_%s", vl.Identifier.Plugin, vl.DSName(i))
|
||||||
name = fmt.Sprintf("%s_%s", vl.Identifier.Plugin, vl.DSName(i))
|
|
||||||
tags := make(map[string]string)
|
tags := make(map[string]string)
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ func (p *GraphiteParser) ParseLine(line string) (telegraf.Metric, error) {
|
||||||
if len(tagValue) != 2 || len(tagValue[0]) == 0 || len(tagValue[1]) == 0 {
|
if len(tagValue) != 2 || len(tagValue[0]) == 0 || len(tagValue[1]) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.IndexAny(tagValue[0], "!^") != -1 {
|
if strings.ContainsAny(tagValue[0], "!^") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.Index(tagValue[1], "~") == 0 {
|
if strings.Index(tagValue[1], "~") == 0 {
|
||||||
|
|
|
||||||
|
|
@ -134,14 +134,14 @@ func (p *Parser) parseQuery(starttime time.Time, doc, selected *xmlquery.Node, c
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to query timestamp: %v", err)
|
return nil, fmt.Errorf("failed to query timestamp: %v", err)
|
||||||
}
|
}
|
||||||
switch v.(type) {
|
switch v := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
// Parse the string with the given format or assume the string to contain
|
// Parse the string with the given format or assume the string to contain
|
||||||
// a unix timestamp in seconds if no format is given.
|
// a unix timestamp in seconds if no format is given.
|
||||||
if len(config.TimestampFmt) < 1 || strings.HasPrefix(config.TimestampFmt, "unix") {
|
if len(config.TimestampFmt) < 1 || strings.HasPrefix(config.TimestampFmt, "unix") {
|
||||||
var nanoseconds int64
|
var nanoseconds int64
|
||||||
|
|
||||||
t, err := strconv.ParseFloat(v.(string), 64)
|
t, err := strconv.ParseFloat(v, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse unix timestamp: %v", err)
|
return nil, fmt.Errorf("failed to parse unix timestamp: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -158,14 +158,14 @@ func (p *Parser) parseQuery(starttime time.Time, doc, selected *xmlquery.Node, c
|
||||||
}
|
}
|
||||||
timestamp = time.Unix(0, nanoseconds)
|
timestamp = time.Unix(0, nanoseconds)
|
||||||
} else {
|
} else {
|
||||||
timestamp, err = time.Parse(config.TimestampFmt, v.(string))
|
timestamp, err = time.Parse(config.TimestampFmt, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to query timestamp format: %v", err)
|
return nil, fmt.Errorf("failed to query timestamp format: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case float64:
|
case float64:
|
||||||
// Assume the value to contain a timestamp in seconds and fractions thereof.
|
// Assume the value to contain a timestamp in seconds and fractions thereof.
|
||||||
timestamp = time.Unix(0, int64(v.(float64)*1e9))
|
timestamp = time.Unix(0, int64(v*1e9))
|
||||||
case nil:
|
case nil:
|
||||||
// No timestamp found. Just ignore the time and use "starttime"
|
// No timestamp found. Just ignore the time and use "starttime"
|
||||||
default:
|
default:
|
||||||
|
|
@ -181,13 +181,13 @@ func (p *Parser) parseQuery(starttime time.Time, doc, selected *xmlquery.Node, c
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to query tag '%s': %v", name, err)
|
return nil, fmt.Errorf("failed to query tag '%s': %v", name, err)
|
||||||
}
|
}
|
||||||
switch v.(type) {
|
switch v := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
tags[name] = v.(string)
|
tags[name] = v
|
||||||
case bool:
|
case bool:
|
||||||
tags[name] = strconv.FormatBool(v.(bool))
|
tags[name] = strconv.FormatBool(v)
|
||||||
case float64:
|
case float64:
|
||||||
tags[name] = strconv.FormatFloat(v.(float64), 'G', -1, 64)
|
tags[name] = strconv.FormatFloat(v, 'G', -1, 64)
|
||||||
case nil:
|
case nil:
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
|
|
@ -206,19 +206,19 @@ func (p *Parser) parseQuery(starttime time.Time, doc, selected *xmlquery.Node, c
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to query field (int) '%s': %v", name, err)
|
return nil, fmt.Errorf("failed to query field (int) '%s': %v", name, err)
|
||||||
}
|
}
|
||||||
switch v.(type) {
|
switch v := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
fields[name], err = strconv.ParseInt(v.(string), 10, 54)
|
fields[name], err = strconv.ParseInt(v, 10, 54)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse field (int) '%s': %v", name, err)
|
return nil, fmt.Errorf("failed to parse field (int) '%s': %v", name, err)
|
||||||
}
|
}
|
||||||
case bool:
|
case bool:
|
||||||
fields[name] = int64(0)
|
fields[name] = int64(0)
|
||||||
if v.(bool) {
|
if v {
|
||||||
fields[name] = int64(1)
|
fields[name] = int64(1)
|
||||||
}
|
}
|
||||||
case float64:
|
case float64:
|
||||||
fields[name] = int64(v.(float64))
|
fields[name] = int64(v)
|
||||||
case nil:
|
case nil:
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ func (d *Dedup) cleanup() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
d.FlushTime = time.Now()
|
d.FlushTime = time.Now()
|
||||||
keep := make(map[uint64]telegraf.Metric, 0)
|
keep := make(map[uint64]telegraf.Metric)
|
||||||
for id, metric := range d.Cache {
|
for id, metric := range d.Cache {
|
||||||
if time.Since(metric.Time()) < d.DedupInterval.Duration {
|
if time.Since(metric.Time()) < d.DedupInterval.Duration {
|
||||||
keep[id] = metric
|
keep[id] = metric
|
||||||
|
|
|
||||||
|
|
@ -55,14 +55,14 @@ func (mapper *EnumMapper) Init() error {
|
||||||
if mapping.Field != "" {
|
if mapping.Field != "" {
|
||||||
fieldFilter, err := filter.NewIncludeExcludeFilter([]string{mapping.Field}, nil)
|
fieldFilter, err := filter.NewIncludeExcludeFilter([]string{mapping.Field}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create new field filter: %w", err)
|
return fmt.Errorf("failed to create new field filter: %w", err)
|
||||||
}
|
}
|
||||||
mapper.FieldFilters[mapping.Field] = fieldFilter
|
mapper.FieldFilters[mapping.Field] = fieldFilter
|
||||||
}
|
}
|
||||||
if mapping.Tag != "" {
|
if mapping.Tag != "" {
|
||||||
tagFilter, err := filter.NewIncludeExcludeFilter([]string{mapping.Tag}, nil)
|
tagFilter, err := filter.NewIncludeExcludeFilter([]string{mapping.Tag}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create new tag filter: %s", err)
|
return fmt.Errorf("failed to create new tag filter: %s", err)
|
||||||
}
|
}
|
||||||
mapper.TagFilters[mapping.Tag] = tagFilter
|
mapper.TagFilters[mapping.Tag] = tagFilter
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +153,7 @@ func adjustValue(in interface{}) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mapping *Mapping) mapValue(original string) (interface{}, bool) {
|
func (mapping *Mapping) mapValue(original string) (interface{}, bool) {
|
||||||
if mapped, found := mapping.ValueMappings[original]; found == true {
|
if mapped, found := mapping.ValueMappings[original]; found {
|
||||||
return mapped, true
|
return mapped, true
|
||||||
}
|
}
|
||||||
if mapping.Default != nil {
|
if mapping.Default != nil {
|
||||||
|
|
|
||||||
|
|
@ -110,10 +110,7 @@ func sortMetrics(metrics []MetricAggregation, field string, reverse bool) {
|
||||||
less := func(i, j int) bool {
|
less := func(i, j int) bool {
|
||||||
iv := metrics[i].values[field]
|
iv := metrics[i].values[field]
|
||||||
jv := metrics[j].values[field]
|
jv := metrics[j].values[field]
|
||||||
if iv < jv {
|
return iv < jv
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if reverse {
|
if reverse {
|
||||||
|
|
@ -276,7 +273,7 @@ func (t *TopK) push() []telegraf.Metric {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The return value that will hold the returned metrics
|
// The return value that will hold the returned metrics
|
||||||
var ret = make([]telegraf.Metric, 0, 0)
|
var ret = make([]telegraf.Metric, 0)
|
||||||
// Get the top K metrics for each field and add them to the return value
|
// Get the top K metrics for each field and add them to the return value
|
||||||
addedKeys := make(map[string]bool)
|
addedKeys := make(map[string]bool)
|
||||||
for _, field := range t.Fields {
|
for _, field := range t.Fields {
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,7 @@ func runAndCompare(topk *TopK, metrics []telegraf.Metric, answer []telegraf.Metr
|
||||||
// Smoke tests
|
// Smoke tests
|
||||||
func TestTopkAggregatorsSmokeTests(t *testing.T) {
|
func TestTopkAggregatorsSmokeTests(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.Fields = []string{"a"}
|
topk.Fields = []string{"a"}
|
||||||
topk.GroupBy = []string{"tag_name"}
|
topk.GroupBy = []string{"tag_name"}
|
||||||
|
|
@ -160,8 +159,7 @@ func TestTopkAggregatorsSmokeTests(t *testing.T) {
|
||||||
// AddAggregateFields + Mean aggregator
|
// AddAggregateFields + Mean aggregator
|
||||||
func TestTopkMeanAddAggregateFields(t *testing.T) {
|
func TestTopkMeanAddAggregateFields(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.Aggregation = "mean"
|
topk.Aggregation = "mean"
|
||||||
topk.AddAggregateFields = []string{"a"}
|
topk.AddAggregateFields = []string{"a"}
|
||||||
|
|
@ -189,8 +187,7 @@ func TestTopkMeanAddAggregateFields(t *testing.T) {
|
||||||
// AddAggregateFields + Sum aggregator
|
// AddAggregateFields + Sum aggregator
|
||||||
func TestTopkSumAddAggregateFields(t *testing.T) {
|
func TestTopkSumAddAggregateFields(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.Aggregation = "sum"
|
topk.Aggregation = "sum"
|
||||||
topk.AddAggregateFields = []string{"a"}
|
topk.AddAggregateFields = []string{"a"}
|
||||||
|
|
@ -218,8 +215,7 @@ func TestTopkSumAddAggregateFields(t *testing.T) {
|
||||||
// AddAggregateFields + Max aggregator
|
// AddAggregateFields + Max aggregator
|
||||||
func TestTopkMaxAddAggregateFields(t *testing.T) {
|
func TestTopkMaxAddAggregateFields(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.Aggregation = "max"
|
topk.Aggregation = "max"
|
||||||
topk.AddAggregateFields = []string{"a"}
|
topk.AddAggregateFields = []string{"a"}
|
||||||
|
|
@ -247,8 +243,7 @@ func TestTopkMaxAddAggregateFields(t *testing.T) {
|
||||||
// AddAggregateFields + Min aggregator
|
// AddAggregateFields + Min aggregator
|
||||||
func TestTopkMinAddAggregateFields(t *testing.T) {
|
func TestTopkMinAddAggregateFields(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.Aggregation = "min"
|
topk.Aggregation = "min"
|
||||||
topk.AddAggregateFields = []string{"a"}
|
topk.AddAggregateFields = []string{"a"}
|
||||||
|
|
@ -276,8 +271,7 @@ func TestTopkMinAddAggregateFields(t *testing.T) {
|
||||||
// GroupBy
|
// GroupBy
|
||||||
func TestTopkGroupby1(t *testing.T) {
|
func TestTopkGroupby1(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 3
|
topk.K = 3
|
||||||
topk.Aggregation = "sum"
|
topk.Aggregation = "sum"
|
||||||
|
|
@ -301,8 +295,7 @@ func TestTopkGroupby1(t *testing.T) {
|
||||||
}
|
}
|
||||||
func TestTopkGroupby2(t *testing.T) {
|
func TestTopkGroupby2(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 3
|
topk.K = 3
|
||||||
topk.Aggregation = "mean"
|
topk.Aggregation = "mean"
|
||||||
|
|
@ -330,8 +323,7 @@ func TestTopkGroupby2(t *testing.T) {
|
||||||
}
|
}
|
||||||
func TestTopkGroupby3(t *testing.T) {
|
func TestTopkGroupby3(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 1
|
topk.K = 1
|
||||||
topk.Aggregation = "min"
|
topk.Aggregation = "min"
|
||||||
|
|
@ -356,8 +348,7 @@ func TestTopkGroupby3(t *testing.T) {
|
||||||
// GroupBy + Fields
|
// GroupBy + Fields
|
||||||
func TestTopkGroupbyFields1(t *testing.T) {
|
func TestTopkGroupbyFields1(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 4 // This settings generate less than 3 groups
|
topk.K = 4 // This settings generate less than 3 groups
|
||||||
topk.Aggregation = "mean"
|
topk.Aggregation = "mean"
|
||||||
|
|
@ -383,8 +374,7 @@ func TestTopkGroupbyFields1(t *testing.T) {
|
||||||
|
|
||||||
func TestTopkGroupbyFields2(t *testing.T) {
|
func TestTopkGroupbyFields2(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 2
|
topk.K = 2
|
||||||
topk.Aggregation = "sum"
|
topk.Aggregation = "sum"
|
||||||
|
|
@ -411,8 +401,7 @@ func TestTopkGroupbyFields2(t *testing.T) {
|
||||||
// GroupBy metric name
|
// GroupBy metric name
|
||||||
func TestTopkGroupbyMetricName1(t *testing.T) {
|
func TestTopkGroupbyMetricName1(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 1
|
topk.K = 1
|
||||||
topk.Aggregation = "sum"
|
topk.Aggregation = "sum"
|
||||||
|
|
@ -437,8 +426,7 @@ func TestTopkGroupbyMetricName1(t *testing.T) {
|
||||||
|
|
||||||
func TestTopkGroupbyMetricName2(t *testing.T) {
|
func TestTopkGroupbyMetricName2(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 2
|
topk.K = 2
|
||||||
topk.Aggregation = "sum"
|
topk.Aggregation = "sum"
|
||||||
|
|
@ -465,8 +453,7 @@ func TestTopkGroupbyMetricName2(t *testing.T) {
|
||||||
// BottomK
|
// BottomK
|
||||||
func TestTopkBottomk(t *testing.T) {
|
func TestTopkBottomk(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 3
|
topk.K = 3
|
||||||
topk.Aggregation = "sum"
|
topk.Aggregation = "sum"
|
||||||
|
|
@ -491,8 +478,7 @@ func TestTopkBottomk(t *testing.T) {
|
||||||
// GroupByKeyTag
|
// GroupByKeyTag
|
||||||
func TestTopkGroupByKeyTag(t *testing.T) {
|
func TestTopkGroupByKeyTag(t *testing.T) {
|
||||||
// Build the processor
|
// Build the processor
|
||||||
var topk TopK
|
topk := *New()
|
||||||
topk = *New()
|
|
||||||
topk.Period = oneSecondDuration
|
topk.Period = oneSecondDuration
|
||||||
topk.K = 3
|
topk.K = 3
|
||||||
topk.Aggregation = "sum"
|
topk.Aggregation = "sum"
|
||||||
|
|
|
||||||
|
|
@ -256,14 +256,14 @@ func BenchmarkReader(b *testing.B) {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
metrics := make([]telegraf.Metric, 1000, 1000)
|
metrics := make([]telegraf.Metric, 1000)
|
||||||
for i := range metrics {
|
for i := range metrics {
|
||||||
metrics[i] = m
|
metrics[i] = m
|
||||||
}
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
readbuf := make([]byte, 4096, 4096)
|
readbuf := make([]byte, 4096)
|
||||||
serializer := NewSerializer()
|
serializer := NewSerializer()
|
||||||
reader := NewReader(metrics, serializer)
|
reader := NewReader(metrics, serializer)
|
||||||
for {
|
for {
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,6 @@ func (r *Registry) set(key uint64, s Stat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r.stats[key][s.FieldName()] = s
|
r.stats[key][s.FieldName()] = s
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func key(measurement string, tags map[string]string) uint64 {
|
func key(measurement string, tags map[string]string) uint64 {
|
||||||
|
|
|
||||||
|
|
@ -235,11 +235,9 @@ func (a *Accumulator) AddError(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Accumulator) SetPrecision(_ time.Duration) {
|
func (a *Accumulator) SetPrecision(_ time.Duration) {
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Accumulator) DisablePrecision() {
|
func (a *Accumulator) DisablePrecision() {
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Accumulator) Debug() bool {
|
func (a *Accumulator) Debug() bool {
|
||||||
|
|
@ -394,7 +392,6 @@ func (a *Accumulator) AssertDoesNotContainsTaggedFields(
|
||||||
assert.Fail(t, msg)
|
assert.Fail(t, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
func (a *Accumulator) AssertContainsFields(
|
func (a *Accumulator) AssertContainsFields(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
|
|
|
||||||
|
|
@ -99,16 +99,12 @@ func newMetricDiff(metric telegraf.Metric) *metricDiff {
|
||||||
m := &metricDiff{}
|
m := &metricDiff{}
|
||||||
m.Measurement = metric.Name()
|
m.Measurement = metric.Name()
|
||||||
|
|
||||||
for _, tag := range metric.TagList() {
|
m.Tags = append(m.Tags, metric.TagList()...)
|
||||||
m.Tags = append(m.Tags, tag)
|
|
||||||
}
|
|
||||||
sort.Slice(m.Tags, func(i, j int) bool {
|
sort.Slice(m.Tags, func(i, j int) bool {
|
||||||
return m.Tags[i].Key < m.Tags[j].Key
|
return m.Tags[i].Key < m.Tags[j].Key
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, field := range metric.FieldList() {
|
m.Fields = append(m.Fields, metric.FieldList()...)
|
||||||
m.Fields = append(m.Fields, field)
|
|
||||||
}
|
|
||||||
sort.Slice(m.Fields, func(i, j int) bool {
|
sort.Slice(m.Fields, func(i, j int) bool {
|
||||||
return m.Fields[i].Key < m.Fields[j].Key
|
return m.Fields[i].Key < m.Fields[j].Key
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue