fix: Linter fixes for plugins/inputs/[t-z]* (#10105)
This commit is contained in:
parent
f82528dd8a
commit
146fff3183
|
|
@ -122,14 +122,14 @@ func (w *MultilineMatchWhichLine) UnmarshalText(data []byte) (err error) {
|
|||
switch strings.ToUpper(s) {
|
||||
case `PREVIOUS`, `"PREVIOUS"`, `'PREVIOUS'`:
|
||||
*w = Previous
|
||||
return
|
||||
return nil
|
||||
|
||||
case `NEXT`, `"NEXT"`, `'NEXT'`:
|
||||
*w = Next
|
||||
return
|
||||
return nil
|
||||
}
|
||||
*w = -1
|
||||
return fmt.Errorf("E! [inputs.tail] unknown multiline MatchWhichLine")
|
||||
return fmt.Errorf("unknown multiline MatchWhichLine")
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler
|
||||
|
|
@ -138,5 +138,5 @@ func (w MultilineMatchWhichLine) MarshalText() ([]byte, error) {
|
|||
if s != "" {
|
||||
return []byte(s), nil
|
||||
}
|
||||
return nil, fmt.Errorf("E! [inputs.tail] unknown multiline MatchWhichLine")
|
||||
return nil, fmt.Errorf("unknown multiline MatchWhichLine")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMultilineConfigOK(t *testing.T) {
|
||||
|
|
@ -17,7 +18,7 @@ func TestMultilineConfigOK(t *testing.T) {
|
|||
|
||||
_, err := c.NewMultiline()
|
||||
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
}
|
||||
|
||||
func TestMultilineConfigError(t *testing.T) {
|
||||
|
|
@ -28,7 +29,7 @@ func TestMultilineConfigError(t *testing.T) {
|
|||
|
||||
_, err := c.NewMultiline()
|
||||
|
||||
assert.Error(t, err, "The pattern was invalid")
|
||||
require.Error(t, err, "The pattern was invalid")
|
||||
}
|
||||
|
||||
func TestMultilineConfigTimeoutSpecified(t *testing.T) {
|
||||
|
|
@ -39,9 +40,9 @@ func TestMultilineConfigTimeoutSpecified(t *testing.T) {
|
|||
Timeout: &duration,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
|
||||
assert.Equal(t, duration, *m.config.Timeout)
|
||||
require.Equal(t, duration, *m.config.Timeout)
|
||||
}
|
||||
|
||||
func TestMultilineConfigDefaultTimeout(t *testing.T) {
|
||||
|
|
@ -51,9 +52,9 @@ func TestMultilineConfigDefaultTimeout(t *testing.T) {
|
|||
MatchWhichLine: Previous,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
|
||||
assert.Equal(t, duration, *m.config.Timeout)
|
||||
require.Equal(t, duration, *m.config.Timeout)
|
||||
}
|
||||
|
||||
func TestMultilineIsEnabled(t *testing.T) {
|
||||
|
|
@ -62,11 +63,11 @@ func TestMultilineIsEnabled(t *testing.T) {
|
|||
MatchWhichLine: Previous,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
|
||||
isEnabled := m.IsEnabled()
|
||||
|
||||
assert.True(t, isEnabled, "Should have been enabled")
|
||||
require.True(t, isEnabled, "Should have been enabled")
|
||||
}
|
||||
|
||||
func TestMultilineIsDisabled(t *testing.T) {
|
||||
|
|
@ -74,11 +75,11 @@ func TestMultilineIsDisabled(t *testing.T) {
|
|||
MatchWhichLine: Previous,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
|
||||
isEnabled := m.IsEnabled()
|
||||
|
||||
assert.False(t, isEnabled, "Should have been disabled")
|
||||
require.False(t, isEnabled, "Should have been disabled")
|
||||
}
|
||||
|
||||
func TestMultilineFlushEmpty(t *testing.T) {
|
||||
|
|
@ -87,12 +88,12 @@ func TestMultilineFlushEmpty(t *testing.T) {
|
|||
MatchWhichLine: Previous,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
var buffer bytes.Buffer
|
||||
|
||||
text := m.Flush(&buffer)
|
||||
|
||||
assert.Empty(t, text)
|
||||
require.Empty(t, text)
|
||||
}
|
||||
|
||||
func TestMultilineFlush(t *testing.T) {
|
||||
|
|
@ -101,15 +102,15 @@ func TestMultilineFlush(t *testing.T) {
|
|||
MatchWhichLine: Previous,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
var buffer bytes.Buffer
|
||||
_, err = buffer.WriteString("foo")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
text := m.Flush(&buffer)
|
||||
|
||||
assert.Equal(t, "foo", text)
|
||||
assert.Zero(t, buffer.Len())
|
||||
require.Equal(t, "foo", text)
|
||||
require.Zero(t, buffer.Len())
|
||||
}
|
||||
|
||||
func TestMultiLineProcessLinePrevious(t *testing.T) {
|
||||
|
|
@ -118,28 +119,28 @@ func TestMultiLineProcessLinePrevious(t *testing.T) {
|
|||
MatchWhichLine: Previous,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
var buffer bytes.Buffer
|
||||
|
||||
text := m.ProcessLine("1", &buffer)
|
||||
assert.Empty(t, text)
|
||||
assert.NotZero(t, buffer.Len())
|
||||
require.Empty(t, text)
|
||||
require.NotZero(t, buffer.Len())
|
||||
|
||||
text = m.ProcessLine("=>2", &buffer)
|
||||
assert.Empty(t, text)
|
||||
assert.NotZero(t, buffer.Len())
|
||||
require.Empty(t, text)
|
||||
require.NotZero(t, buffer.Len())
|
||||
|
||||
text = m.ProcessLine("=>3", &buffer)
|
||||
assert.Empty(t, text)
|
||||
assert.NotZero(t, buffer.Len())
|
||||
require.Empty(t, text)
|
||||
require.NotZero(t, buffer.Len())
|
||||
|
||||
text = m.ProcessLine("4", &buffer)
|
||||
assert.Equal(t, "1=>2=>3", text)
|
||||
assert.NotZero(t, buffer.Len())
|
||||
require.Equal(t, "1=>2=>3", text)
|
||||
require.NotZero(t, buffer.Len())
|
||||
|
||||
text = m.ProcessLine("5", &buffer)
|
||||
assert.Equal(t, "4", text)
|
||||
assert.Equal(t, "5", buffer.String())
|
||||
require.Equal(t, "4", text)
|
||||
require.Equal(t, "5", buffer.String())
|
||||
}
|
||||
|
||||
func TestMultiLineProcessLineNext(t *testing.T) {
|
||||
|
|
@ -148,28 +149,28 @@ func TestMultiLineProcessLineNext(t *testing.T) {
|
|||
MatchWhichLine: Next,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
var buffer bytes.Buffer
|
||||
|
||||
text := m.ProcessLine("1=>", &buffer)
|
||||
assert.Empty(t, text)
|
||||
assert.NotZero(t, buffer.Len())
|
||||
require.Empty(t, text)
|
||||
require.NotZero(t, buffer.Len())
|
||||
|
||||
text = m.ProcessLine("2=>", &buffer)
|
||||
assert.Empty(t, text)
|
||||
assert.NotZero(t, buffer.Len())
|
||||
require.Empty(t, text)
|
||||
require.NotZero(t, buffer.Len())
|
||||
|
||||
text = m.ProcessLine("3=>", &buffer)
|
||||
assert.Empty(t, text)
|
||||
assert.NotZero(t, buffer.Len())
|
||||
require.Empty(t, text)
|
||||
require.NotZero(t, buffer.Len())
|
||||
|
||||
text = m.ProcessLine("4", &buffer)
|
||||
assert.Equal(t, "1=>2=>3=>4", text)
|
||||
assert.Zero(t, buffer.Len())
|
||||
require.Equal(t, "1=>2=>3=>4", text)
|
||||
require.Zero(t, buffer.Len())
|
||||
|
||||
text = m.ProcessLine("5", &buffer)
|
||||
assert.Equal(t, "5", text)
|
||||
assert.Zero(t, buffer.Len())
|
||||
require.Equal(t, "5", text)
|
||||
require.Zero(t, buffer.Len())
|
||||
}
|
||||
|
||||
func TestMultiLineMatchStringWithInvertMatchFalse(t *testing.T) {
|
||||
|
|
@ -179,13 +180,13 @@ func TestMultiLineMatchStringWithInvertMatchFalse(t *testing.T) {
|
|||
InvertMatch: false,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
|
||||
matches1 := m.matchString("t=>")
|
||||
matches2 := m.matchString("t")
|
||||
|
||||
assert.True(t, matches1)
|
||||
assert.False(t, matches2)
|
||||
require.True(t, matches1)
|
||||
require.False(t, matches2)
|
||||
}
|
||||
|
||||
func TestMultiLineMatchStringWithInvertTrue(t *testing.T) {
|
||||
|
|
@ -195,41 +196,41 @@ func TestMultiLineMatchStringWithInvertTrue(t *testing.T) {
|
|||
InvertMatch: true,
|
||||
}
|
||||
m, err := c.NewMultiline()
|
||||
assert.NoError(t, err, "Configuration was OK.")
|
||||
require.NoError(t, err, "Configuration was OK.")
|
||||
|
||||
matches1 := m.matchString("t=>")
|
||||
matches2 := m.matchString("t")
|
||||
|
||||
assert.False(t, matches1)
|
||||
assert.True(t, matches2)
|
||||
require.False(t, matches1)
|
||||
require.True(t, matches2)
|
||||
}
|
||||
|
||||
func TestMultilineWhat(t *testing.T) {
|
||||
var w1 MultilineMatchWhichLine
|
||||
assert.NoError(t, w1.UnmarshalTOML([]byte(`"previous"`)))
|
||||
assert.Equal(t, Previous, w1)
|
||||
require.NoError(t, w1.UnmarshalTOML([]byte(`"previous"`)))
|
||||
require.Equal(t, Previous, w1)
|
||||
|
||||
var w2 MultilineMatchWhichLine
|
||||
assert.NoError(t, w2.UnmarshalTOML([]byte(`previous`)))
|
||||
assert.Equal(t, Previous, w2)
|
||||
require.NoError(t, w2.UnmarshalTOML([]byte(`previous`)))
|
||||
require.Equal(t, Previous, w2)
|
||||
|
||||
var w3 MultilineMatchWhichLine
|
||||
assert.NoError(t, w3.UnmarshalTOML([]byte(`'previous'`)))
|
||||
assert.Equal(t, Previous, w3)
|
||||
require.NoError(t, w3.UnmarshalTOML([]byte(`'previous'`)))
|
||||
require.Equal(t, Previous, w3)
|
||||
|
||||
var w4 MultilineMatchWhichLine
|
||||
assert.NoError(t, w4.UnmarshalTOML([]byte(`"next"`)))
|
||||
assert.Equal(t, Next, w4)
|
||||
require.NoError(t, w4.UnmarshalTOML([]byte(`"next"`)))
|
||||
require.Equal(t, Next, w4)
|
||||
|
||||
var w5 MultilineMatchWhichLine
|
||||
assert.NoError(t, w5.UnmarshalTOML([]byte(`next`)))
|
||||
assert.Equal(t, Next, w5)
|
||||
require.NoError(t, w5.UnmarshalTOML([]byte(`next`)))
|
||||
require.Equal(t, Next, w5)
|
||||
|
||||
var w6 MultilineMatchWhichLine
|
||||
assert.NoError(t, w6.UnmarshalTOML([]byte(`'next'`)))
|
||||
assert.Equal(t, Next, w6)
|
||||
require.NoError(t, w6.UnmarshalTOML([]byte(`'next'`)))
|
||||
require.Equal(t, Next, w6)
|
||||
|
||||
var w7 MultilineMatchWhichLine
|
||||
assert.Error(t, w7.UnmarshalTOML([]byte(`nope`)))
|
||||
assert.Equal(t, MultilineMatchWhichLine(-1), w7)
|
||||
require.Error(t, w7.UnmarshalTOML([]byte(`nope`)))
|
||||
require.Equal(t, MultilineMatchWhichLine(-1), w7)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
|
|
@ -81,7 +80,7 @@ func TestTailBadLine(t *testing.T) {
|
|||
acc.Wait(1)
|
||||
|
||||
tt.Stop()
|
||||
assert.Contains(t, buf.String(), "Malformed log line")
|
||||
require.Contains(t, buf.String(), "Malformed log line")
|
||||
}
|
||||
|
||||
func TestTailDosLineEndings(t *testing.T) {
|
||||
|
|
@ -137,7 +136,7 @@ func TestGrokParseLogFilesWithMultiline(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, tt.Start(&acc))
|
||||
require.NoError(t, tt.Start(&acc))
|
||||
defer tt.Stop()
|
||||
|
||||
acc.Wait(3)
|
||||
|
|
@ -168,7 +167,7 @@ func TestGrokParseLogFilesWithMultiline(t *testing.T) {
|
|||
"loglevel": "ERROR",
|
||||
})
|
||||
|
||||
assert.Equal(t, uint64(3), acc.NMetrics())
|
||||
require.Equal(t, uint64(3), acc.NMetrics())
|
||||
}
|
||||
|
||||
func TestGrokParseLogFilesWithMultilineTimeout(t *testing.T) {
|
||||
|
|
@ -201,7 +200,7 @@ func TestGrokParseLogFilesWithMultilineTimeout(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, tt.Start(&acc))
|
||||
require.NoError(t, tt.Start(&acc))
|
||||
time.Sleep(11 * time.Millisecond) // will force timeout
|
||||
_, err = tmpfile.WriteString("[04/Jun/2016:12:41:48 +0100] INFO HelloExample: This is info\r\n")
|
||||
require.NoError(t, err)
|
||||
|
|
@ -213,7 +212,7 @@ func TestGrokParseLogFilesWithMultilineTimeout(t *testing.T) {
|
|||
require.NoError(t, tmpfile.Sync())
|
||||
acc.Wait(3)
|
||||
tt.Stop()
|
||||
assert.Equal(t, uint64(3), acc.NMetrics())
|
||||
require.Equal(t, uint64(3), acc.NMetrics())
|
||||
expectedPath := tmpfile.Name()
|
||||
|
||||
acc.AssertContainsTaggedFields(t, "tail_grok",
|
||||
|
|
@ -254,9 +253,9 @@ func TestGrokParseLogFilesWithMultilineTailerCloseFlushesMultilineBuffer(t *test
|
|||
require.NoError(t, err)
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, tt.Start(&acc))
|
||||
require.NoError(t, tt.Start(&acc))
|
||||
acc.Wait(3)
|
||||
assert.Equal(t, uint64(3), acc.NMetrics())
|
||||
require.Equal(t, uint64(3), acc.NMetrics())
|
||||
// Close tailer, so multiline buffer is flushed
|
||||
tt.Stop()
|
||||
acc.Wait(4)
|
||||
|
|
@ -561,7 +560,6 @@ func TestCharacterEncoding(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
plugin := &Tail{
|
||||
Files: []string{filepath.Join(testdataDir, tt.testfiles)},
|
||||
FromBeginning: tt.fromBeginning,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package tcp_listener
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
|
|
@ -88,7 +87,7 @@ func (t *TCPListener) Start(acc telegraf.Accumulator) error {
|
|||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
||||
log.Println("W! DEPRECATED: the TCP listener plugin has been deprecated " +
|
||||
t.Log.Warn("DEPRECATED: the TCP listener plugin has been deprecated " +
|
||||
"in favor of the socket_listener plugin " +
|
||||
"(https://github.com/influxdata/telegraf/tree/master/plugins/inputs/socket_listener)")
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,10 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/plugins/parsers"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -96,10 +95,10 @@ func TestHighTrafficTCP(t *testing.T) {
|
|||
require.NoError(t, conn.(*net.TCPConn).CloseWrite())
|
||||
buf := []byte{0}
|
||||
_, err = conn.Read(buf)
|
||||
assert.Equal(t, err, io.EOF)
|
||||
require.Equal(t, err, io.EOF)
|
||||
listener.Stop()
|
||||
|
||||
assert.Equal(t, 100000, int(acc.NMetrics()))
|
||||
require.Equal(t, 100000, int(acc.NMetrics()))
|
||||
}
|
||||
|
||||
func TestConnectTCP(t *testing.T) {
|
||||
|
|
@ -168,14 +167,14 @@ func TestConcurrentConns(t *testing.T) {
|
|||
buf := make([]byte, 1500)
|
||||
n, err := conn.Read(buf)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t,
|
||||
require.Equal(t,
|
||||
"Telegraf maximum concurrent TCP connections (2) reached, closing.\n"+
|
||||
"You may want to increase max_tcp_connections in"+
|
||||
" the Telegraf tcp listener configuration.\n",
|
||||
string(buf[:n]))
|
||||
|
||||
_, err = conn.Read(buf)
|
||||
assert.Equal(t, io.EOF, err)
|
||||
require.Equal(t, io.EOF, err)
|
||||
}
|
||||
|
||||
// Test that MaxTCPConnections is respected when max==1
|
||||
|
|
@ -203,14 +202,14 @@ func TestConcurrentConns1(t *testing.T) {
|
|||
buf := make([]byte, 1500)
|
||||
n, err := conn.Read(buf)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t,
|
||||
require.Equal(t,
|
||||
"Telegraf maximum concurrent TCP connections (1) reached, closing.\n"+
|
||||
"You may want to increase max_tcp_connections in"+
|
||||
" the Telegraf tcp listener configuration.\n",
|
||||
string(buf[:n]))
|
||||
|
||||
_, err = conn.Read(buf)
|
||||
assert.Equal(t, io.EOF, err)
|
||||
require.Equal(t, io.EOF, err)
|
||||
}
|
||||
|
||||
// Test that MaxTCPConnections is respected
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import (
|
|||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
const tengineSampleResponse = `127.0.0.1,784,1511,2,2,1,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0`
|
||||
|
|
@ -22,7 +22,7 @@ func TestTengineTags(t *testing.T) {
|
|||
for _, url1 := range urls {
|
||||
addr, _ = url.Parse(url1)
|
||||
tagMap := getTags(addr, "127.0.0.1")
|
||||
assert.Contains(t, tagMap["server"], "localhost")
|
||||
require.Contains(t, tagMap["server"], "localhost")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ func (t *Twemproxy) Gather(acc telegraf.Accumulator) error {
|
|||
|
||||
var stats map[string]interface{}
|
||||
if err = json.Unmarshal(body, &stats); err != nil {
|
||||
return errors.New("Error decoding JSON response")
|
||||
return errors.New("error decoding JSON response")
|
||||
}
|
||||
|
||||
tags := make(map[string]string)
|
||||
|
|
@ -124,11 +124,8 @@ func (t *Twemproxy) processServer(
|
|||
) {
|
||||
fields := make(map[string]interface{})
|
||||
for key, value := range data {
|
||||
switch key {
|
||||
default:
|
||||
if val, ok := value.(float64); ok {
|
||||
fields[key] = val
|
||||
}
|
||||
if val, ok := value.(float64); ok {
|
||||
fields[key] = val
|
||||
}
|
||||
}
|
||||
acc.AddFields("twemproxy_pool_server", fields, tags)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import (
|
|||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
const sampleAddr = "127.0.0.1:22222"
|
||||
|
|
@ -65,15 +66,12 @@ func mockTwemproxyServer() (net.Listener, error) {
|
|||
return nil, err
|
||||
}
|
||||
go func(l net.Listener) {
|
||||
for {
|
||||
conn, _ := l.Accept()
|
||||
if _, err := conn.Write([]byte(sampleStats)); err != nil {
|
||||
return
|
||||
}
|
||||
if err := conn.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
break
|
||||
conn, _ := l.Accept()
|
||||
if _, err := conn.Write([]byte(sampleStats)); err != nil {
|
||||
return
|
||||
}
|
||||
if err := conn.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
}(listener)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package udp_listener
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -96,7 +95,7 @@ func (u *UDPListener) Start(acc telegraf.Accumulator) error {
|
|||
u.Lock()
|
||||
defer u.Unlock()
|
||||
|
||||
log.Println("W! DEPRECATED: the UDP listener plugin has been deprecated " +
|
||||
u.Log.Warn("DEPRECATED: the UDP listener plugin has been deprecated " +
|
||||
"in favor of the socket_listener plugin " +
|
||||
"(https://github.com/influxdata/telegraf/tree/master/plugins/inputs/socket_listener)")
|
||||
|
||||
|
|
@ -172,8 +171,7 @@ func (u *UDPListener) udpListenLoop() {
|
|||
|
||||
n, _, err := u.listener.ReadFromUDP(buf)
|
||||
if err != nil {
|
||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
||||
} else {
|
||||
if err, ok := err.(net.Error); !ok || !err.Timeout() {
|
||||
u.Log.Error(err.Error())
|
||||
}
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func UnboundControl(output string) func(unbound Unbound) (*bytes.Buffer, error) {
|
||||
|
|
@ -21,12 +22,12 @@ func TestParseFullOutput(t *testing.T) {
|
|||
}
|
||||
err := v.Gather(acc)
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, acc.HasMeasurement("unbound"))
|
||||
require.True(t, acc.HasMeasurement("unbound"))
|
||||
|
||||
assert.Len(t, acc.Metrics, 1)
|
||||
assert.Equal(t, acc.NFields(), 63)
|
||||
require.Len(t, acc.Metrics, 1)
|
||||
require.Equal(t, acc.NFields(), 63)
|
||||
|
||||
acc.AssertContainsFields(t, "unbound", parsedFullOutput)
|
||||
}
|
||||
|
|
@ -39,13 +40,13 @@ func TestParseFullOutputThreadAsTag(t *testing.T) {
|
|||
}
|
||||
err := v.Gather(acc)
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, acc.HasMeasurement("unbound"))
|
||||
assert.True(t, acc.HasMeasurement("unbound_threads"))
|
||||
require.True(t, acc.HasMeasurement("unbound"))
|
||||
require.True(t, acc.HasMeasurement("unbound_threads"))
|
||||
|
||||
assert.Len(t, acc.Metrics, 2)
|
||||
assert.Equal(t, acc.NFields(), 63)
|
||||
require.Len(t, acc.Metrics, 2)
|
||||
require.Equal(t, acc.NFields(), 63)
|
||||
|
||||
acc.AssertContainsFields(t, "unbound", parsedFullOutputThreadAsTagMeasurementUnbound)
|
||||
acc.AssertContainsFields(t, "unbound_threads", parsedFullOutputThreadAsTagMeasurementUnboundThreads)
|
||||
|
|
|
|||
|
|
@ -78,20 +78,20 @@ func (u *Uwsgi) Gather(acc telegraf.Accumulator) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (u *Uwsgi) gatherServer(acc telegraf.Accumulator, url *url.URL) error {
|
||||
func (u *Uwsgi) gatherServer(acc telegraf.Accumulator, address *url.URL) error {
|
||||
var err error
|
||||
var r io.ReadCloser
|
||||
var s StatsServer
|
||||
|
||||
switch url.Scheme {
|
||||
switch address.Scheme {
|
||||
case "tcp":
|
||||
r, err = net.DialTimeout(url.Scheme, url.Host, time.Duration(u.Timeout))
|
||||
r, err = net.DialTimeout(address.Scheme, address.Host, time.Duration(u.Timeout))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.source = url.Host
|
||||
s.source = address.Host
|
||||
case "unix":
|
||||
r, err = net.DialTimeout(url.Scheme, url.Path, time.Duration(u.Timeout))
|
||||
r, err = net.DialTimeout(address.Scheme, address.Path, time.Duration(u.Timeout))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -100,20 +100,20 @@ func (u *Uwsgi) gatherServer(acc telegraf.Accumulator, url *url.URL) error {
|
|||
s.source = ""
|
||||
}
|
||||
case "http":
|
||||
resp, err := u.client.Get(url.String())
|
||||
resp, err := u.client.Get(address.String()) //nolint:bodyclose // response body is closed after switch
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r = resp.Body
|
||||
s.source = url.Host
|
||||
s.source = address.Host
|
||||
default:
|
||||
return fmt.Errorf("'%s' is not a supported scheme", url.Scheme)
|
||||
return fmt.Errorf("'%s' is not a supported scheme", address.Scheme)
|
||||
}
|
||||
|
||||
defer r.Close()
|
||||
|
||||
if err := json.NewDecoder(r).Decode(&s); err != nil {
|
||||
return fmt.Errorf("failed to decode json payload from '%s': %s", url.String(), err.Error())
|
||||
return fmt.Errorf("failed to decode json payload from '%s': %s", address.String(), err.Error())
|
||||
}
|
||||
|
||||
u.gatherStatServer(acc, &s)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
|
|
@ -27,7 +27,7 @@ func TestGather(t *testing.T) {
|
|||
run: fakeVarnishStat(smOutput),
|
||||
Stats: []string{"*"},
|
||||
}
|
||||
assert.NoError(t, v.Gather(acc))
|
||||
require.NoError(t, v.Gather(acc))
|
||||
|
||||
acc.HasMeasurement("varnish")
|
||||
for tag, fields := range parsedSmOutput {
|
||||
|
|
@ -43,12 +43,12 @@ func TestParseFullOutput(t *testing.T) {
|
|||
run: fakeVarnishStat(fullOutput),
|
||||
Stats: []string{"*"},
|
||||
}
|
||||
assert.NoError(t, v.Gather(acc))
|
||||
require.NoError(t, v.Gather(acc))
|
||||
|
||||
acc.HasMeasurement("varnish")
|
||||
flat := flatten(acc.Metrics)
|
||||
assert.Len(t, acc.Metrics, 6)
|
||||
assert.Equal(t, 293, len(flat))
|
||||
require.Len(t, acc.Metrics, 6)
|
||||
require.Equal(t, 293, len(flat))
|
||||
}
|
||||
|
||||
func TestFilterSomeStats(t *testing.T) {
|
||||
|
|
@ -57,12 +57,12 @@ func TestFilterSomeStats(t *testing.T) {
|
|||
run: fakeVarnishStat(fullOutput),
|
||||
Stats: []string{"MGT.*", "VBE.*"},
|
||||
}
|
||||
assert.NoError(t, v.Gather(acc))
|
||||
require.NoError(t, v.Gather(acc))
|
||||
|
||||
acc.HasMeasurement("varnish")
|
||||
flat := flatten(acc.Metrics)
|
||||
assert.Len(t, acc.Metrics, 2)
|
||||
assert.Equal(t, 16, len(flat))
|
||||
require.Len(t, acc.Metrics, 2)
|
||||
require.Equal(t, 16, len(flat))
|
||||
}
|
||||
|
||||
func TestFieldConfig(t *testing.T) {
|
||||
|
|
@ -79,11 +79,11 @@ func TestFieldConfig(t *testing.T) {
|
|||
run: fakeVarnishStat(fullOutput),
|
||||
Stats: strings.Split(fieldCfg, ","),
|
||||
}
|
||||
assert.NoError(t, v.Gather(acc))
|
||||
require.NoError(t, v.Gather(acc))
|
||||
|
||||
acc.HasMeasurement("varnish")
|
||||
flat := flatten(acc.Metrics)
|
||||
assert.Equal(t, expected, len(flat))
|
||||
require.Equal(t, expected, len(flat))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,20 +14,20 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf/filter"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/performance"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
|
||||
"github.com/influxdata/telegraf/filter"
|
||||
)
|
||||
|
||||
var isolateLUN = regexp.MustCompile(".*/([^/]+)/?$")
|
||||
var isolateLUN = regexp.MustCompile(`.*/([^/]+)/?$`)
|
||||
|
||||
var isIPv4 = regexp.MustCompile("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$")
|
||||
var isIPv4 = regexp.MustCompile(`^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`)
|
||||
|
||||
var isIPv6 = regexp.MustCompile("^(?:[A-Fa-f0-9]{0,4}:){1,7}[A-Fa-f0-9]{1,4}$")
|
||||
var isIPv6 = regexp.MustCompile(`^(?:[A-Fa-f0-9]{0,4}:){1,7}[A-Fa-f0-9]{1,4}$`)
|
||||
|
||||
const maxSampleConst = 10 // Absolute maximum number of samples regardless of period
|
||||
|
||||
|
|
@ -115,14 +115,14 @@ func (e *Endpoint) getParent(obj *objectRef, res *resourceKind) (*objectRef, boo
|
|||
|
||||
// NewEndpoint returns a new connection to a vCenter based on the URL and configuration passed
|
||||
// as parameters.
|
||||
func NewEndpoint(ctx context.Context, parent *VSphere, url *url.URL, log telegraf.Logger) (*Endpoint, error) {
|
||||
func NewEndpoint(ctx context.Context, parent *VSphere, address *url.URL, log telegraf.Logger) (*Endpoint, error) {
|
||||
e := Endpoint{
|
||||
URL: url,
|
||||
URL: address,
|
||||
Parent: parent,
|
||||
hwMarks: NewTSCache(hwMarkTTL),
|
||||
hwMarks: NewTSCache(hwMarkTTL, log),
|
||||
lun2ds: make(map[string]string),
|
||||
initialized: false,
|
||||
clientFactory: NewClientFactory(url, parent),
|
||||
clientFactory: NewClientFactory(address, parent),
|
||||
customAttrFilter: newFilterOrPanic(parent.CustomAttributeInclude, parent.CustomAttributeExclude),
|
||||
customAttrEnabled: anythingEnabled(parent.CustomAttributeExclude),
|
||||
log: log,
|
||||
|
|
@ -457,9 +457,6 @@ func (e *Endpoint) discover(ctx context.Context) error {
|
|||
SendInternalCounterWithTags("discovered_objects", e.URL.Host, map[string]string{"type": res.name}, int64(len(objects)))
|
||||
numRes += int64(len(objects))
|
||||
}
|
||||
if err != nil {
|
||||
e.log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Build lun2ds map
|
||||
|
|
@ -584,11 +581,11 @@ func (e *Endpoint) complexMetadataSelect(ctx context.Context, res *resourceKind,
|
|||
te.Wait()
|
||||
}
|
||||
|
||||
func getDatacenters(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectMap, error) {
|
||||
func getDatacenters(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (objectMap, error) {
|
||||
var resources []mo.Datacenter
|
||||
ctx1, cancel1 := context.WithTimeout(ctx, time.Duration(e.Parent.Timeout))
|
||||
defer cancel1()
|
||||
err := filter.FindAll(ctx1, &resources)
|
||||
err := resourceFilter.FindAll(ctx1, &resources)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -605,11 +602,11 @@ func getDatacenters(ctx context.Context, e *Endpoint, filter *ResourceFilter) (o
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func getClusters(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectMap, error) {
|
||||
func getClusters(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (objectMap, error) {
|
||||
var resources []mo.ClusterComputeResource
|
||||
ctx1, cancel1 := context.WithTimeout(ctx, time.Duration(e.Parent.Timeout))
|
||||
defer cancel1()
|
||||
err := filter.FindAll(ctx1, &resources)
|
||||
err := resourceFilter.FindAll(ctx1, &resources)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -657,9 +654,9 @@ func getClusters(ctx context.Context, e *Endpoint, filter *ResourceFilter) (obje
|
|||
}
|
||||
|
||||
//noinspection GoUnusedParameter
|
||||
func getHosts(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectMap, error) {
|
||||
func getHosts(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (objectMap, error) {
|
||||
var resources []mo.HostSystem
|
||||
err := filter.FindAll(ctx, &resources)
|
||||
err := resourceFilter.FindAll(ctx, &resources)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -675,11 +672,11 @@ func getHosts(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectM
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func getVMs(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectMap, error) {
|
||||
func getVMs(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (objectMap, error) {
|
||||
var resources []mo.VirtualMachine
|
||||
ctx1, cancel1 := context.WithTimeout(ctx, time.Duration(e.Parent.Timeout))
|
||||
defer cancel1()
|
||||
err := filter.FindAll(ctx1, &resources)
|
||||
err := resourceFilter.FindAll(ctx1, &resources)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -765,11 +762,11 @@ func getVMs(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectMap
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func getDatastores(ctx context.Context, e *Endpoint, filter *ResourceFilter) (objectMap, error) {
|
||||
func getDatastores(ctx context.Context, e *Endpoint, resourceFilter *ResourceFilter) (objectMap, error) {
|
||||
var resources []mo.Datastore
|
||||
ctx1, cancel1 := context.WithTimeout(ctx, time.Duration(e.Parent.Timeout))
|
||||
defer cancel1()
|
||||
err := filter.FindAll(ctx1, &resources)
|
||||
err := resourceFilter.FindAll(ctx1, &resources)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -888,7 +885,7 @@ func (e *Endpoint) chunkify(ctx context.Context, res *resourceKind, now time.Tim
|
|||
pqs := make(queryChunk, 0, e.Parent.MaxQueryObjects)
|
||||
numQs := 0
|
||||
|
||||
for _, object := range res.objects {
|
||||
for _, obj := range res.objects {
|
||||
timeBuckets := make(map[int64]*types.PerfQuerySpec)
|
||||
for metricIdx, metric := range res.metrics {
|
||||
// Determine time of last successful collection
|
||||
|
|
@ -897,7 +894,7 @@ func (e *Endpoint) chunkify(ctx context.Context, res *resourceKind, now time.Tim
|
|||
e.log.Infof("Unable to find metric name for id %d. Skipping!", metric.CounterId)
|
||||
continue
|
||||
}
|
||||
start, ok := e.hwMarks.Get(object.ref.Value, metricName)
|
||||
start, ok := e.hwMarks.Get(obj.ref.Value, metricName)
|
||||
if !ok {
|
||||
start = latest.Add(time.Duration(-res.sampling) * time.Second * (time.Duration(e.Parent.MetricLookback) - 1))
|
||||
}
|
||||
|
|
@ -907,7 +904,7 @@ func (e *Endpoint) chunkify(ctx context.Context, res *resourceKind, now time.Tim
|
|||
bucket, ok := timeBuckets[start.Unix()]
|
||||
if !ok {
|
||||
bucket = &types.PerfQuerySpec{
|
||||
Entity: object.ref,
|
||||
Entity: obj.ref,
|
||||
MaxSample: maxSampleConst,
|
||||
MetricId: make([]types.PerfMetricId, 0),
|
||||
IntervalId: res.sampling,
|
||||
|
|
@ -1272,7 +1269,7 @@ func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resou
|
|||
}
|
||||
}
|
||||
|
||||
func (e *Endpoint) makeMetricIdentifier(prefix, metric string) (string, string) {
|
||||
func (e *Endpoint) makeMetricIdentifier(prefix, metric string) (metricName string, fieldName string) {
|
||||
parts := strings.Split(metric, ".")
|
||||
if len(parts) == 1 {
|
||||
return prefix, parts[0]
|
||||
|
|
|
|||
|
|
@ -35,14 +35,14 @@ type ResourceFilter struct {
|
|||
func (f *Finder) FindAll(ctx context.Context, resType string, paths, excludePaths []string, dst interface{}) error {
|
||||
objs := make(map[string]types.ObjectContent)
|
||||
for _, p := range paths {
|
||||
if err := f.find(ctx, resType, p, objs); err != nil {
|
||||
if err := f.findResources(ctx, resType, p, objs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(excludePaths) > 0 {
|
||||
excludes := make(map[string]types.ObjectContent)
|
||||
for _, p := range excludePaths {
|
||||
if err := f.find(ctx, resType, p, excludes); err != nil {
|
||||
if err := f.findResources(ctx, resType, p, excludes); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -56,14 +56,14 @@ func (f *Finder) FindAll(ctx context.Context, resType string, paths, excludePath
|
|||
// Find returns the resources matching the specified path.
|
||||
func (f *Finder) Find(ctx context.Context, resType, path string, dst interface{}) error {
|
||||
objs := make(map[string]types.ObjectContent)
|
||||
err := f.find(ctx, resType, path, objs)
|
||||
err := f.findResources(ctx, resType, path, objs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return objectContentToTypedArray(objs, dst)
|
||||
}
|
||||
|
||||
func (f *Finder) find(ctx context.Context, resType, path string, objs map[string]types.ObjectContent) error {
|
||||
func (f *Finder) findResources(ctx context.Context, resType, path string, objs map[string]types.ObjectContent) error {
|
||||
p := strings.Split(path, "/")
|
||||
flt := make([]property.Filter, len(p)-1)
|
||||
for i := 1; i < len(p); i++ {
|
||||
|
|
@ -107,7 +107,7 @@ func (f *Finder) descend(ctx context.Context, root types.ManagedObjectReference,
|
|||
fields := []string{"name"}
|
||||
recurse := tokens[pos]["name"] == "**"
|
||||
|
||||
types := ct
|
||||
objectTypes := ct
|
||||
if isLeaf {
|
||||
if af, ok := addFields[resType]; ok {
|
||||
fields = append(fields, af...)
|
||||
|
|
@ -131,9 +131,9 @@ func (f *Finder) descend(ctx context.Context, root types.ManagedObjectReference,
|
|||
}
|
||||
return nil
|
||||
}
|
||||
types = []string{resType} // Only load wanted object type at leaf level
|
||||
objectTypes = []string{resType} // Only load wanted object type at leaf level
|
||||
}
|
||||
err = v.Retrieve(ctx, types, fields, &content)
|
||||
err = v.Retrieve(ctx, objectTypes, fields, &content)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package vsphere
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
)
|
||||
|
||||
// TSCache is a cache of timestamps used to determine the validity of datapoints
|
||||
|
|
@ -11,13 +12,15 @@ type TSCache struct {
|
|||
ttl time.Duration
|
||||
table map[string]time.Time
|
||||
mux sync.RWMutex
|
||||
log telegraf.Logger
|
||||
}
|
||||
|
||||
// NewTSCache creates a new TSCache with a specified time-to-live after which timestamps are discarded.
|
||||
func NewTSCache(ttl time.Duration) *TSCache {
|
||||
func NewTSCache(ttl time.Duration, log telegraf.Logger) *TSCache {
|
||||
return &TSCache{
|
||||
ttl: ttl,
|
||||
table: make(map[string]time.Time),
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +35,7 @@ func (t *TSCache) Purge() {
|
|||
n++
|
||||
}
|
||||
}
|
||||
log.Printf("D! [inputs.vsphere] purged timestamp cache. %d deleted with %d remaining", n, len(t.table))
|
||||
t.log.Debugf("purged timestamp cache. %d deleted with %d remaining", n, len(t.table))
|
||||
}
|
||||
|
||||
// IsNew returns true if the supplied timestamp for the supplied key is more recent than the
|
||||
|
|
@ -56,10 +59,10 @@ func (t *TSCache) Get(key string, metricName string) (time.Time, bool) {
|
|||
}
|
||||
|
||||
// Put updates the latest timestamp for the supplied key.
|
||||
func (t *TSCache) Put(key string, metricName string, time time.Time) {
|
||||
func (t *TSCache) Put(key string, metricName string, timestamp time.Time) {
|
||||
t.mux.Lock()
|
||||
defer t.mux.Unlock()
|
||||
t.table[makeKey(key, metricName)] = time
|
||||
t.table[makeKey(key, metricName)] = timestamp
|
||||
}
|
||||
|
||||
func makeKey(resource string, metric string) string {
|
||||
|
|
|
|||
|
|
@ -11,15 +11,16 @@ import (
|
|||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
itls "github.com/influxdata/telegraf/plugins/common/tls"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/influxdata/toml"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/simulator"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
itls "github.com/influxdata/telegraf/plugins/common/tls"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
var configHeader = `
|
||||
|
|
@ -229,7 +230,6 @@ func TestParseConfig(t *testing.T) {
|
|||
tab, err := toml.Parse([]byte(c))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, tab)
|
||||
|
||||
}
|
||||
|
||||
func TestConfigDurationParsing(t *testing.T) {
|
||||
|
|
@ -313,6 +313,7 @@ func TestFinder(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
c, err := NewClient(ctx, s.URL, v)
|
||||
require.NoError(t, err)
|
||||
|
||||
f := Finder{c}
|
||||
|
||||
|
|
@ -429,6 +430,7 @@ func TestFolders(t *testing.T) {
|
|||
v := defaultVSphere()
|
||||
|
||||
c, err := NewClient(ctx, s.URL, v)
|
||||
require.NoError(t, err)
|
||||
|
||||
f := Finder{c}
|
||||
|
||||
|
|
@ -449,7 +451,7 @@ func TestFolders(t *testing.T) {
|
|||
testLookupVM(ctx, t, &f, "/F0/DC1/vm/**/F*/**", 4, "")
|
||||
}
|
||||
|
||||
func TestCollection(t *testing.T) {
|
||||
func TestCollectionWithClusterMetrics(t *testing.T) {
|
||||
testCollection(t, false)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,14 +6,13 @@ package win_perf_counters
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"strings"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
||||
|
|
@ -30,15 +29,15 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
|||
|
||||
_, err = query.AddCounterToQuery("")
|
||||
require.Error(t, err, "uninitialized query must return errors")
|
||||
assert.True(t, strings.Contains(err.Error(), "uninitialized"))
|
||||
require.True(t, strings.Contains(err.Error(), "uninitialized"))
|
||||
|
||||
_, err = query.AddEnglishCounterToQuery("")
|
||||
require.Error(t, err, "uninitialized query must return errors")
|
||||
assert.True(t, strings.Contains(err.Error(), "uninitialized"))
|
||||
require.True(t, strings.Contains(err.Error(), "uninitialized"))
|
||||
|
||||
err = query.CollectData()
|
||||
require.Error(t, err, "uninitialized query must return errors")
|
||||
assert.True(t, strings.Contains(err.Error(), "uninitialized"))
|
||||
require.True(t, strings.Contains(err.Error(), "uninitialized"))
|
||||
|
||||
err = query.Open()
|
||||
require.NoError(t, err)
|
||||
|
|
@ -47,7 +46,7 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
|||
|
||||
hCounter, err = query.AddCounterToQuery(counterPath)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, 0, hCounter)
|
||||
require.NotEqual(t, 0, hCounter)
|
||||
|
||||
err = query.Close()
|
||||
require.NoError(t, err)
|
||||
|
|
@ -57,11 +56,11 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
|||
|
||||
hCounter, err = query.AddEnglishCounterToQuery(counterPath)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, 0, hCounter)
|
||||
require.NotEqual(t, 0, hCounter)
|
||||
|
||||
cp, err := query.GetCounterPath(hCounter)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(cp, counterPath))
|
||||
require.True(t, strings.HasSuffix(cp, counterPath))
|
||||
|
||||
err = query.CollectData()
|
||||
require.NoError(t, err)
|
||||
|
|
@ -76,19 +75,19 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
|||
now := time.Now()
|
||||
mtime, err := query.CollectDataWithTime()
|
||||
require.NoError(t, err)
|
||||
assert.True(t, mtime.Sub(now) < time.Second)
|
||||
require.True(t, mtime.Sub(now) < time.Second)
|
||||
|
||||
counterPath = "\\Process(*)\\% Processor Time"
|
||||
paths, err := query.ExpandWildCardPath(counterPath)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, paths)
|
||||
assert.True(t, len(paths) > 1)
|
||||
require.True(t, len(paths) > 1)
|
||||
|
||||
counterPath = "\\Process(_Total)\\*"
|
||||
paths, err = query.ExpandWildCardPath(counterPath)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, paths)
|
||||
assert.True(t, len(paths) > 1)
|
||||
require.True(t, len(paths) > 1)
|
||||
|
||||
err = query.Open()
|
||||
require.NoError(t, err)
|
||||
|
|
@ -96,7 +95,7 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
|||
counterPath = "\\Process(*)\\% Processor Time"
|
||||
hCounter, err = query.AddEnglishCounterToQuery(counterPath)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, 0, hCounter)
|
||||
require.NotEqual(t, 0, hCounter)
|
||||
|
||||
err = query.CollectData()
|
||||
require.NoError(t, err)
|
||||
|
|
@ -111,7 +110,7 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
|||
arr, err = query.GetFormattedCounterArrayDouble(hCounter)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.True(t, len(arr) > 0, "Too")
|
||||
require.True(t, len(arr) > 0, "Too")
|
||||
|
||||
err = query.Close()
|
||||
require.NoError(t, err)
|
||||
|
|
@ -566,11 +565,11 @@ func TestWinPerfcountersCollect1Integration(t *testing.T) {
|
|||
time.Sleep(2000 * time.Millisecond)
|
||||
err = m.Gather(&acc)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, acc.Metrics, 2)
|
||||
require.Len(t, acc.Metrics, 2)
|
||||
|
||||
for _, metric := range acc.Metrics {
|
||||
_, ok := metric.Fields[expectedCounter]
|
||||
assert.True(t, ok)
|
||||
require.True(t, ok)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -613,11 +612,11 @@ func TestWinPerfcountersCollect2Integration(t *testing.T) {
|
|||
err = m.Gather(&acc)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, acc.Metrics, 4)
|
||||
require.Len(t, acc.Metrics, 4)
|
||||
|
||||
for _, metric := range acc.Metrics {
|
||||
_, ok := metric.Fields[expectedCounter]
|
||||
assert.True(t, ok)
|
||||
require.True(t, ok)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type testCounter struct {
|
||||
|
|
@ -237,7 +237,7 @@ func TestCounterPathParsing(t *testing.T) {
|
|||
for path, vals := range counterPathsAndRes {
|
||||
o, i, c, err := extractCounterInfoFromCounterPath(path)
|
||||
require.NoError(t, err)
|
||||
require.True(t, assert.ObjectsAreEqual(vals, []string{o, i, c}), "arrays: %#v and %#v are not equal", vals, []string{o, i, c})
|
||||
require.Equalf(t, vals, []string{o, i, c}, "arrays: %#v and %#v are not equal", vals, []string{o, i, c})
|
||||
}
|
||||
for _, path := range invalidCounterPaths {
|
||||
_, _, _, err := extractCounterInfoFromCounterPath(path)
|
||||
|
|
@ -312,7 +312,7 @@ func TestParseConfigBasic(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = m.ParseConfig()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 4)
|
||||
require.Len(t, m.counters, 4)
|
||||
err = m.query.Close()
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -323,7 +323,7 @@ func TestParseConfigBasic(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = m.ParseConfig()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 4)
|
||||
require.Len(t, m.counters, 4)
|
||||
err = m.query.Close()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
@ -349,7 +349,7 @@ func TestParseConfigNoInstance(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = m.ParseConfig()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 2)
|
||||
require.Len(t, m.counters, 2)
|
||||
err = m.query.Close()
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -360,7 +360,7 @@ func TestParseConfigNoInstance(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = m.ParseConfig()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 2)
|
||||
require.Len(t, m.counters, 2)
|
||||
err = m.query.Close()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
@ -456,7 +456,7 @@ func TestParseConfigTotalExpansion(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = m.ParseConfig()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 4)
|
||||
require.Len(t, m.counters, 4)
|
||||
err = m.query.Close()
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -478,7 +478,7 @@ func TestParseConfigTotalExpansion(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = m.ParseConfig()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 2)
|
||||
require.Len(t, m.counters, 2)
|
||||
err = m.query.Close()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
@ -503,7 +503,7 @@ func TestParseConfigExpand(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = m.ParseConfig()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 4)
|
||||
require.Len(t, m.counters, 4)
|
||||
err = m.query.Close()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
@ -629,7 +629,7 @@ func TestSimpleGatherWithTimestamp(t *testing.T) {
|
|||
"objectname": "O",
|
||||
}
|
||||
acc1.AssertContainsTaggedFields(t, measurement, fields1, tags1)
|
||||
assert.True(t, acc1.HasTimestamp(measurement, MetricTime))
|
||||
require.True(t, acc1.HasTimestamp(measurement, MetricTime))
|
||||
}
|
||||
|
||||
func TestGatherError(t *testing.T) {
|
||||
|
|
@ -739,9 +739,9 @@ func TestGatherRefreshingWithExpansion(t *testing.T) {
|
|||
}
|
||||
var acc1 testutil.Accumulator
|
||||
err = m.Gather(&acc1)
|
||||
assert.Len(t, m.counters, 4)
|
||||
require.Len(t, m.counters, 4)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, acc1.Metrics, 2)
|
||||
require.Len(t, acc1.Metrics, 2)
|
||||
|
||||
fields1 := map[string]interface{}{
|
||||
"C1": float32(1.1),
|
||||
|
|
@ -786,8 +786,8 @@ func TestGatherRefreshingWithExpansion(t *testing.T) {
|
|||
//test before elapsing CounterRefreshRate counters are not refreshed
|
||||
err = m.Gather(&acc2)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 4)
|
||||
assert.Len(t, acc2.Metrics, 2)
|
||||
require.Len(t, m.counters, 4)
|
||||
require.Len(t, acc2.Metrics, 2)
|
||||
|
||||
acc2.AssertContainsTaggedFields(t, measurement, fields1, tags1)
|
||||
acc2.AssertContainsTaggedFields(t, measurement, fields2, tags2)
|
||||
|
|
@ -797,7 +797,7 @@ func TestGatherRefreshingWithExpansion(t *testing.T) {
|
|||
var acc3 testutil.Accumulator
|
||||
err = m.Gather(&acc3)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, acc3.Metrics, 3)
|
||||
require.Len(t, acc3.Metrics, 3)
|
||||
|
||||
acc3.AssertContainsTaggedFields(t, measurement, fields1, tags1)
|
||||
acc3.AssertContainsTaggedFields(t, measurement, fields2, tags2)
|
||||
|
|
@ -831,9 +831,9 @@ func TestGatherRefreshingWithoutExpansion(t *testing.T) {
|
|||
CountersRefreshInterval: config.Duration(time.Second * 10)}
|
||||
var acc1 testutil.Accumulator
|
||||
err = m.Gather(&acc1)
|
||||
assert.Len(t, m.counters, 2)
|
||||
require.Len(t, m.counters, 2)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, acc1.Metrics, 2)
|
||||
require.Len(t, acc1.Metrics, 2)
|
||||
|
||||
fields1 := map[string]interface{}{
|
||||
"C1": float32(1.1),
|
||||
|
|
@ -880,8 +880,8 @@ func TestGatherRefreshingWithoutExpansion(t *testing.T) {
|
|||
//test before elapsing CounterRefreshRate counters are not refreshed
|
||||
err = m.Gather(&acc2)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 2)
|
||||
assert.Len(t, acc2.Metrics, 3)
|
||||
require.Len(t, m.counters, 2)
|
||||
require.Len(t, acc2.Metrics, 3)
|
||||
|
||||
acc2.AssertContainsTaggedFields(t, measurement, fields1, tags1)
|
||||
acc2.AssertContainsTaggedFields(t, measurement, fields2, tags2)
|
||||
|
|
@ -908,7 +908,7 @@ func TestGatherRefreshingWithoutExpansion(t *testing.T) {
|
|||
var acc3 testutil.Accumulator
|
||||
err = m.Gather(&acc3)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, acc3.Metrics, 2)
|
||||
require.Len(t, acc3.Metrics, 2)
|
||||
fields4 := map[string]interface{}{
|
||||
"C1": float32(1.1),
|
||||
"C2": float32(1.2),
|
||||
|
|
@ -954,8 +954,8 @@ func TestGatherTotalNoExpansion(t *testing.T) {
|
|||
var acc1 testutil.Accumulator
|
||||
err = m.Gather(&acc1)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 2)
|
||||
assert.Len(t, acc1.Metrics, 2)
|
||||
require.Len(t, m.counters, 2)
|
||||
require.Len(t, acc1.Metrics, 2)
|
||||
fields1 := map[string]interface{}{
|
||||
"C1": float32(1.1),
|
||||
"C2": float32(1.2),
|
||||
|
|
@ -984,8 +984,8 @@ func TestGatherTotalNoExpansion(t *testing.T) {
|
|||
var acc2 testutil.Accumulator
|
||||
err = m.Gather(&acc2)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, m.counters, 2)
|
||||
assert.Len(t, acc2.Metrics, 1)
|
||||
require.Len(t, m.counters, 2)
|
||||
require.Len(t, acc2.Metrics, 1)
|
||||
|
||||
acc2.AssertContainsTaggedFields(t, measurement, fields1, tags1)
|
||||
|
||||
|
|
@ -1013,14 +1013,14 @@ var stringArraySingleItem = []string{
|
|||
|
||||
func TestUTF16ToStringArray(t *testing.T) {
|
||||
singleItem := UTF16ToStringArray(unicodeStringListSingleItem)
|
||||
assert.True(t, assert.ObjectsAreEqual(singleItem, stringArraySingleItem), "Not equal single arrays")
|
||||
require.Equal(t, singleItem, stringArraySingleItem, "Not equal single arrays")
|
||||
|
||||
noItem := UTF16ToStringArray(unicodeStringListNoItem)
|
||||
assert.Nil(t, noItem)
|
||||
require.Nil(t, noItem)
|
||||
|
||||
engStrings := UTF16ToStringArray(unicodeStringListWithEnglishChars)
|
||||
assert.True(t, assert.ObjectsAreEqual(engStrings, stringArrayWithEnglishChars), "Not equal eng arrays")
|
||||
require.Equal(t, engStrings, stringArrayWithEnglishChars, "Not equal eng arrays")
|
||||
|
||||
czechStrings := UTF16ToStringArray(unicodeStringListWithCzechChars)
|
||||
assert.True(t, assert.ObjectsAreEqual(czechStrings, stringArrayWithCzechChars), "Not equal czech arrays")
|
||||
require.Equal(t, czechStrings, stringArrayWithCzechChars, "Not equal czech arrays")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ import (
|
|||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/sys/windows/svc"
|
||||
"golang.org/x/sys/windows/svc/mgr"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
//testData is DD wrapper for unit testing of WinServices
|
||||
|
|
@ -136,8 +136,8 @@ func TestBasicInfo(t *testing.T) {
|
|||
mgrProvider: &FakeMgProvider{testErrors[0]},
|
||||
}
|
||||
winServices.Init()
|
||||
assert.NotEmpty(t, winServices.SampleConfig())
|
||||
assert.NotEmpty(t, winServices.Description())
|
||||
require.NotEmpty(t, winServices.SampleConfig())
|
||||
require.NotEmpty(t, winServices.Description())
|
||||
}
|
||||
|
||||
func TestMgrErrors(t *testing.T) {
|
||||
|
|
@ -149,7 +149,7 @@ func TestMgrErrors(t *testing.T) {
|
|||
var acc1 testutil.Accumulator
|
||||
err := winServices.Gather(&acc1)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), testErrors[0].mgrConnectError.Error())
|
||||
require.Contains(t, err.Error(), testErrors[0].mgrConnectError.Error())
|
||||
|
||||
////mgr.listServices error
|
||||
winServices = &WinServices{
|
||||
|
|
@ -159,7 +159,7 @@ func TestMgrErrors(t *testing.T) {
|
|||
var acc2 testutil.Accumulator
|
||||
err = winServices.Gather(&acc2)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), testErrors[1].mgrListServicesError.Error())
|
||||
require.Contains(t, err.Error(), testErrors[1].mgrListServicesError.Error())
|
||||
|
||||
////mgr.listServices error 2
|
||||
winServices = &WinServices{
|
||||
|
|
@ -213,7 +213,7 @@ func TestGatherContainsTag(t *testing.T) {
|
|||
winServices.Init()
|
||||
var acc1 testutil.Accumulator
|
||||
require.NoError(t, winServices.Gather(&acc1))
|
||||
assert.Len(t, acc1.Errors, 0, "There should be no errors after gather")
|
||||
require.Len(t, acc1.Errors, 0, "There should be no errors after gather")
|
||||
|
||||
for _, s := range testSimpleData[0].services {
|
||||
fields := make(map[string]interface{})
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package wireguard
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"golang.zx2c4.com/wireguard/wgctrl"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
"golang.zx2c4.com/wireguard/wgctrl"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -26,7 +26,8 @@ var (
|
|||
// Wireguard is an input that enumerates all Wireguard interfaces/devices on
|
||||
// the host, and reports gauge metrics for the device itself and its peers.
|
||||
type Wireguard struct {
|
||||
Devices []string `toml:"devices"`
|
||||
Devices []string `toml:"devices"`
|
||||
Log telegraf.Logger `toml:"-"`
|
||||
|
||||
client *wgctrl.Client
|
||||
}
|
||||
|
|
@ -81,7 +82,7 @@ func (wg *Wireguard) enumerateDevices() ([]*wgtypes.Device, error) {
|
|||
for _, name := range wg.Devices {
|
||||
dev, err := wg.client.Device(name)
|
||||
if err != nil {
|
||||
log.Printf("W! [inputs.wireguard] No Wireguard device found with name %s", name)
|
||||
wg.Log.Warnf("No Wireguard device found with name %s", name)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
func TestWireguard_gatherDeviceMetrics(t *testing.T) {
|
||||
|
|
@ -36,7 +37,7 @@ func TestWireguard_gatherDeviceMetrics(t *testing.T) {
|
|||
|
||||
wg.gatherDeviceMetrics(&acc, device)
|
||||
|
||||
assert.Equal(t, 3, acc.NFields())
|
||||
require.Equal(t, 3, acc.NFields())
|
||||
acc.AssertDoesNotContainMeasurement(t, measurementPeer)
|
||||
acc.AssertContainsTaggedFields(t, measurementDevice, expectFields, expectTags)
|
||||
acc.AssertContainsTaggedFields(t, measurementDevice, expectGauges, expectTags)
|
||||
|
|
@ -77,7 +78,7 @@ func TestWireguard_gatherDevicePeerMetrics(t *testing.T) {
|
|||
|
||||
wg.gatherDevicePeerMetrics(&acc, device, peer)
|
||||
|
||||
assert.Equal(t, 6, acc.NFields())
|
||||
require.Equal(t, 6, acc.NFields())
|
||||
acc.AssertDoesNotContainMeasurement(t, measurementDevice)
|
||||
acc.AssertContainsTaggedFields(t, measurementPeer, expectFields, expectTags)
|
||||
acc.AssertContainsTaggedFields(t, measurementPeer, expectGauges, expectTags)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ package wireless
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
|
|
@ -51,7 +50,7 @@ func (w *Wireless) Gather(acc telegraf.Accumulator) error {
|
|||
return err
|
||||
}
|
||||
|
||||
interfaces, err := loadWirelessTable(table)
|
||||
interfaces, err := w.loadWirelessTable(table)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -80,8 +79,8 @@ func (w *Wireless) Gather(acc telegraf.Accumulator) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadWirelessTable(table []byte) ([]*wirelessInterface, error) {
|
||||
var w []*wirelessInterface
|
||||
func (w *Wireless) loadWirelessTable(table []byte) ([]*wirelessInterface, error) {
|
||||
var wi []*wirelessInterface
|
||||
lines := bytes.Split(table, newLineByte)
|
||||
|
||||
// iterate over interfaces
|
||||
|
|
@ -99,10 +98,10 @@ func loadWirelessTable(table []byte) ([]*wirelessInterface, error) {
|
|||
values = append(values, v)
|
||||
}
|
||||
if len(values) != interfaceFieldLength {
|
||||
log.Printf("E! [input.wireless] invalid length of interface values")
|
||||
w.Log.Error("invalid length of interface values")
|
||||
continue
|
||||
}
|
||||
w = append(w, &wirelessInterface{
|
||||
wi = append(wi, &wirelessInterface{
|
||||
Interface: strings.Trim(fields[0], ":"),
|
||||
Status: values[0],
|
||||
Link: values[1],
|
||||
|
|
@ -116,7 +115,7 @@ func loadWirelessTable(table []byte) ([]*wirelessInterface, error) {
|
|||
Beacon: values[9],
|
||||
})
|
||||
}
|
||||
return w, nil
|
||||
return wi, nil
|
||||
}
|
||||
|
||||
// loadPath can be used to read path firstly from config
|
||||
|
|
@ -128,13 +127,13 @@ func (w *Wireless) loadPath() {
|
|||
}
|
||||
|
||||
// proc can be used to read file paths from env
|
||||
func proc(env, path string) string {
|
||||
func proc(env, defaultPath string) string {
|
||||
// try to read full file path
|
||||
if p := os.Getenv(env); p != "" {
|
||||
return p
|
||||
}
|
||||
// return default path
|
||||
return path
|
||||
return defaultPath
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ package wireless
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
var testInput = []byte(`Inter-| sta-| Quality | Discarded packets | Missed | WE
|
||||
|
|
@ -43,11 +45,13 @@ func TestLoadWirelessTable(t *testing.T) {
|
|||
Beacon: int64(0),
|
||||
},
|
||||
}
|
||||
metrics, err := loadWirelessTable(testInput)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
as := assert.New(t)
|
||||
w := Wireless{
|
||||
Log: testutil.Logger{},
|
||||
}
|
||||
metrics, err := w.loadWirelessTable(testInput)
|
||||
require.NoError(t, err)
|
||||
|
||||
as := require.New(t)
|
||||
as.Equal(metrics, expectedMetrics)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/pion/dtls/v2"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
|
|
@ -199,30 +197,28 @@ func TestTags(t *testing.T) {
|
|||
acc := testutil.Accumulator{}
|
||||
require.NoError(t, sc.Gather(&acc))
|
||||
|
||||
assert.True(t, acc.HasMeasurement("x509_cert"))
|
||||
require.True(t, acc.HasMeasurement("x509_cert"))
|
||||
|
||||
assert.True(t, acc.HasTag("x509_cert", "common_name"))
|
||||
assert.Equal(t, "server.localdomain", acc.TagValue("x509_cert", "common_name"))
|
||||
require.True(t, acc.HasTag("x509_cert", "common_name"))
|
||||
require.Equal(t, "server.localdomain", acc.TagValue("x509_cert", "common_name"))
|
||||
|
||||
assert.True(t, acc.HasTag("x509_cert", "signature_algorithm"))
|
||||
assert.Equal(t, "SHA256-RSA", acc.TagValue("x509_cert", "signature_algorithm"))
|
||||
require.True(t, acc.HasTag("x509_cert", "signature_algorithm"))
|
||||
require.Equal(t, "SHA256-RSA", acc.TagValue("x509_cert", "signature_algorithm"))
|
||||
|
||||
assert.True(t, acc.HasTag("x509_cert", "public_key_algorithm"))
|
||||
assert.Equal(t, "RSA", acc.TagValue("x509_cert", "public_key_algorithm"))
|
||||
require.True(t, acc.HasTag("x509_cert", "public_key_algorithm"))
|
||||
require.Equal(t, "RSA", acc.TagValue("x509_cert", "public_key_algorithm"))
|
||||
|
||||
assert.True(t, acc.HasTag("x509_cert", "issuer_common_name"))
|
||||
assert.Equal(t, "Telegraf Test CA", acc.TagValue("x509_cert", "issuer_common_name"))
|
||||
require.True(t, acc.HasTag("x509_cert", "issuer_common_name"))
|
||||
require.Equal(t, "Telegraf Test CA", acc.TagValue("x509_cert", "issuer_common_name"))
|
||||
|
||||
assert.True(t, acc.HasTag("x509_cert", "san"))
|
||||
assert.Equal(t, "localhost,127.0.0.1", acc.TagValue("x509_cert", "san"))
|
||||
require.True(t, acc.HasTag("x509_cert", "san"))
|
||||
require.Equal(t, "localhost,127.0.0.1", acc.TagValue("x509_cert", "san"))
|
||||
|
||||
assert.True(t, acc.HasTag("x509_cert", "serial_number"))
|
||||
require.True(t, acc.HasTag("x509_cert", "serial_number"))
|
||||
serialNumber := new(big.Int)
|
||||
_, validSerialNumber := serialNumber.SetString(acc.TagValue("x509_cert", "serial_number"), 16)
|
||||
if !validSerialNumber {
|
||||
t.Errorf("Expected a valid Hex serial number but got %s", acc.TagValue("x509_cert", "serial_number"))
|
||||
}
|
||||
assert.Equal(t, big.NewInt(1), serialNumber)
|
||||
require.Truef(t, validSerialNumber, "Expected a valid Hex serial number but got %s", acc.TagValue("x509_cert", "serial_number"))
|
||||
require.Equal(t, big.NewInt(1), serialNumber)
|
||||
}
|
||||
|
||||
func TestGatherChain(t *testing.T) {
|
||||
|
|
@ -288,8 +284,8 @@ func TestGatherUDPCert(t *testing.T) {
|
|||
var acc testutil.Accumulator
|
||||
require.NoError(t, m.Gather(&acc))
|
||||
|
||||
assert.Len(t, acc.Errors, 0)
|
||||
assert.True(t, acc.HasMeasurement("x509_cert"))
|
||||
require.Len(t, acc.Errors, 0)
|
||||
require.True(t, acc.HasMeasurement("x509_cert"))
|
||||
}
|
||||
|
||||
func TestStrings(t *testing.T) {
|
||||
|
|
@ -328,7 +324,7 @@ func TestGatherCertIntegration(t *testing.T) {
|
|||
var acc testutil.Accumulator
|
||||
require.NoError(t, m.Gather(&acc))
|
||||
|
||||
assert.True(t, acc.HasMeasurement("x509_cert"))
|
||||
require.True(t, acc.HasMeasurement("x509_cert"))
|
||||
}
|
||||
|
||||
func TestGatherCertMustNotTimeout(t *testing.T) {
|
||||
|
|
@ -345,7 +341,7 @@ func TestGatherCertMustNotTimeout(t *testing.T) {
|
|||
var acc testutil.Accumulator
|
||||
require.NoError(t, m.Gather(&acc))
|
||||
require.Empty(t, acc.Errors)
|
||||
assert.True(t, acc.HasMeasurement("x509_cert"))
|
||||
require.True(t, acc.HasMeasurement("x509_cert"))
|
||||
}
|
||||
|
||||
func TestSourcesToURLs(t *testing.T) {
|
||||
|
|
@ -354,8 +350,8 @@ func TestSourcesToURLs(t *testing.T) {
|
|||
}
|
||||
require.NoError(t, m.Init())
|
||||
|
||||
assert.Equal(t, len(m.globpaths), 2)
|
||||
assert.Equal(t, len(m.locations), 2)
|
||||
require.Equal(t, len(m.globpaths), 2)
|
||||
require.Equal(t, len(m.locations), 2)
|
||||
}
|
||||
|
||||
func TestServerName(t *testing.T) {
|
||||
|
|
@ -385,11 +381,11 @@ func TestServerName(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
actual, err := sc.serverName(u)
|
||||
if test.err {
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, test.expected, actual)
|
||||
require.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
"github.com/influxdata/telegraf/plugins/inputs/zipkin/trace"
|
||||
|
|
@ -108,8 +109,8 @@ func (z *Zipkin) Start(acc telegraf.Accumulator) error {
|
|||
z.address = ln.Addr().String()
|
||||
z.Log.Infof("Started the zipkin listener on %s", z.address)
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
|
||||
z.Listen(ln, acc)
|
||||
|
|
@ -140,7 +141,7 @@ func (z *Zipkin) Listen(ln net.Listener, acc telegraf.Accumulator) {
|
|||
// This interferes with telegraf's internal data collection,
|
||||
// by making it appear as if a serious error occurred.
|
||||
if err != http.ErrServerClosed {
|
||||
acc.AddError(fmt.Errorf("E! Error listening: %v", err))
|
||||
acc.AddError(fmt.Errorf("error listening: %v", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
|
@ -649,10 +650,12 @@ func postThriftData(datafile, address, contentType string) error {
|
|||
|
||||
req.Header.Set("Content-Type", contentType)
|
||||
client := &http.Client{}
|
||||
_, err = client.Do(req)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("HTTP POST request to zipkin endpoint %s failed %v", address, err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package zookeeper
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
func TestZookeeperGeneratesMetricsIntegration(t *testing.T) {
|
||||
|
|
@ -37,6 +37,6 @@ func TestZookeeperGeneratesMetricsIntegration(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, metric := range intMetrics {
|
||||
assert.True(t, acc.HasInt64Field("zookeeper", metric), metric)
|
||||
require.True(t, acc.HasInt64Field("zookeeper", metric), metric)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue