chore: Fix linter findings for nolintlint (part2) (#12430)
Co-authored-by: Pawel Zak <Pawel Zak>
This commit is contained in:
parent
d3809956a4
commit
00347033ab
|
|
@ -204,9 +204,7 @@ func (k *KafkaConsumer) Start(acc telegraf.Accumulator) error {
|
||||||
err := k.consumer.Consume(ctx, k.Topics, handler)
|
err := k.consumer.Consume(ctx, k.Topics, handler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(fmt.Errorf("consume: %w", err))
|
acc.AddError(fmt.Errorf("consume: %w", err))
|
||||||
// Ignore returned error as we cannot do anything about it anyway
|
internal.SleepContext(ctx, reconnectDelay) //nolint:errcheck // ignore returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
internal.SleepContext(ctx, reconnectDelay)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = k.consumer.Close()
|
err = k.consumer.Close()
|
||||||
|
|
|
||||||
|
|
@ -203,12 +203,10 @@ func (l *LeoFS) gatherServer(
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
defer internal.WaitTimeout(cmd, time.Second*5) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
defer internal.WaitTimeout(cmd, time.Second*5)
|
|
||||||
scanner := bufio.NewScanner(stdout)
|
scanner := bufio.NewScanner(stdout)
|
||||||
if !scanner.Scan() {
|
if !scanner.Scan() {
|
||||||
return fmt.Errorf("Unable to retrieve the node name")
|
return fmt.Errorf("unable to retrieve the node name")
|
||||||
}
|
}
|
||||||
nodeName, err := retrieveTokenAfterColon(scanner.Text())
|
nodeName, err := retrieveTokenAfterColon(scanner.Text())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -514,9 +514,7 @@ func (m *Mesos) gatherMainMetrics(u *url.URL, role Role, acc telegraf.Accumulato
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := io.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
// Ignore the returned error to not shadow the initial one
|
resp.Body.Close() //nolint:revive // ignore the returned error to not shadow the initial one
|
||||||
//nolint:errcheck,revive
|
|
||||||
resp.Body.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -288,9 +288,7 @@ func TestMain(m *testing.M) {
|
||||||
masterRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
masterRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
json.NewEncoder(w).Encode(masterMetrics) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
json.NewEncoder(w).Encode(masterMetrics)
|
|
||||||
})
|
})
|
||||||
masterTestServer = httptest.NewServer(masterRouter)
|
masterTestServer = httptest.NewServer(masterRouter)
|
||||||
|
|
||||||
|
|
@ -298,9 +296,7 @@ func TestMain(m *testing.M) {
|
||||||
slaveRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
slaveRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
json.NewEncoder(w).Encode(slaveMetrics) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
json.NewEncoder(w).Encode(slaveMetrics)
|
|
||||||
})
|
})
|
||||||
slaveTestServer = httptest.NewServer(slaveRouter)
|
slaveTestServer = httptest.NewServer(slaveRouter)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,15 @@ func (m *MongoDB) Init() error {
|
||||||
// Start runs after init and setup mongodb connections
|
// Start runs after init and setup mongodb connections
|
||||||
func (m *MongoDB) Start(telegraf.Accumulator) error {
|
func (m *MongoDB) Start(telegraf.Accumulator) error {
|
||||||
for _, connURL := range m.Servers {
|
for _, connURL := range m.Servers {
|
||||||
|
if err := m.setupConnection(connURL); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MongoDB) setupConnection(connURL string) error {
|
||||||
if !strings.HasPrefix(connURL, "mongodb://") && !strings.HasPrefix(connURL, "mongodb+srv://") {
|
if !strings.HasPrefix(connURL, "mongodb://") && !strings.HasPrefix(connURL, "mongodb+srv://") {
|
||||||
// Preserve backwards compatibility for hostnames without a
|
// Preserve backwards compatibility for hostnames without a
|
||||||
// scheme, broken in go 1.8. Remove in Telegraf 2.0
|
// scheme, broken in go 1.8. Remove in Telegraf 2.0
|
||||||
|
|
@ -109,7 +118,7 @@ func (m *MongoDB) Start(telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel() //nolint:revive
|
defer cancel()
|
||||||
|
|
||||||
opts := options.Client().ApplyURI(connURL)
|
opts := options.Client().ApplyURI(connURL)
|
||||||
if m.tlsConfig != nil {
|
if m.tlsConfig != nil {
|
||||||
|
|
@ -139,8 +148,6 @@ func (m *MongoDB) Start(telegraf.Accumulator) error {
|
||||||
Log: m.Log,
|
Log: m.Log,
|
||||||
}
|
}
|
||||||
m.clients = append(m.clients, server)
|
m.clients = append(m.clients, server)
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,18 +119,14 @@ func (n *NetResponse) UDPGather() (map[string]string, map[string]interface{}, er
|
||||||
// Handle error
|
// Handle error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setResult(ConnectionFailed, fields, tags, n.Expect)
|
setResult(ConnectionFailed, fields, tags, n.Expect)
|
||||||
// Error encoded in result
|
return tags, fields, nil //nolint:nilerr // error encoded in result
|
||||||
//nolint:nilerr
|
|
||||||
return tags, fields, nil
|
|
||||||
}
|
}
|
||||||
// Connecting
|
// Connecting
|
||||||
conn, err := net.DialUDP("udp", nil, udpAddr)
|
conn, err := net.DialUDP("udp", nil, udpAddr)
|
||||||
// Handle error
|
// Handle error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setResult(ConnectionFailed, fields, tags, n.Expect)
|
setResult(ConnectionFailed, fields, tags, n.Expect)
|
||||||
// Error encoded in result
|
return tags, fields, nil //nolint:nilerr // error encoded in result
|
||||||
//nolint:nilerr
|
|
||||||
return tags, fields, nil
|
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
// Send string
|
// Send string
|
||||||
|
|
@ -151,9 +147,7 @@ func (n *NetResponse) UDPGather() (map[string]string, map[string]interface{}, er
|
||||||
// Handle error
|
// Handle error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setResult(ReadFailed, fields, tags, n.Expect)
|
setResult(ReadFailed, fields, tags, n.Expect)
|
||||||
// Error encoded in result
|
return tags, fields, nil //nolint:nilerr // error encoded in result
|
||||||
//nolint:nilerr
|
|
||||||
return tags, fields, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looking for string in answer
|
// Looking for string in answer
|
||||||
|
|
|
||||||
|
|
@ -220,11 +220,8 @@ func (n *mockNSQD) handle(conn net.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
n.tcpListener.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
conn.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
n.tcpListener.Close()
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
conn.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func framedResponse(frameType int32, data []byte) ([]byte, error) {
|
func framedResponse(frameType int32, data []byte) ([]byte, error) {
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,7 @@ func fakePassengerStatus(stat string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func teardown(tempFilePath string) {
|
func teardown(tempFilePath string) {
|
||||||
// Ignore the returned error as we want to remove the file and ignore missing file errors
|
os.Remove(tempFilePath) //nolint:revive // ignore the returned error as we want to remove the file and ignore missing file errors
|
||||||
//nolint:errcheck,revive
|
|
||||||
os.Remove(tempFilePath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Invalid_Passenger_Status_Cli(t *testing.T) {
|
func Test_Invalid_Passenger_Status_Cli(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -276,9 +276,7 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
|
||||||
httpReq.Body = body
|
httpReq.Body = body
|
||||||
c.handler.ServeHTTP(r, httpReq)
|
c.handler.ServeHTTP(r, httpReq)
|
||||||
}
|
}
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
r.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
r.Close()
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
delete(c.requests, req.reqID)
|
delete(c.requests, req.reqID)
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
@ -293,15 +291,11 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
|
||||||
// some sort of abort request to the host, so the host
|
// some sort of abort request to the host, so the host
|
||||||
// can properly cut off the client sending all the data.
|
// can properly cut off the client sending all the data.
|
||||||
// For now just bound it a little and
|
// For now just bound it a little and
|
||||||
//nolint:errcheck,revive
|
io.CopyN(io.Discard, body, 100<<20) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
io.CopyN(io.Discard, body, 100<<20)
|
body.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
body.Close()
|
|
||||||
|
|
||||||
if !req.keepConn {
|
if !req.keepConn {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
c.conn.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
c.conn.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -312,9 +306,7 @@ func (c *child) cleanUp() {
|
||||||
if req.pw != nil {
|
if req.pw != nil {
|
||||||
// race with call to Close in c.serveRequest doesn't matter because
|
// race with call to Close in c.serveRequest doesn't matter because
|
||||||
// Pipe(Reader|Writer).Close are idempotent
|
// Pipe(Reader|Writer).Close are idempotent
|
||||||
// Ignore the returned error as we continue in the loop anyway
|
req.pw.CloseWithError(ErrConnClosed) //nolint:revive // Ignore the returned error as we continue in the loop anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
req.pw.CloseWithError(ErrConnClosed)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,9 +229,7 @@ type bufWriter struct {
|
||||||
|
|
||||||
func (w *bufWriter) Close() error {
|
func (w *bufWriter) Close() error {
|
||||||
if err := w.Writer.Flush(); err != nil {
|
if err := w.Writer.Flush(); err != nil {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
w.closer.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
w.closer.Close()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return w.closer.Close()
|
return w.closer.Close()
|
||||||
|
|
|
||||||
|
|
@ -79,8 +79,7 @@ func TestPhpFpmGeneratesMetrics_From_Fcgi(t *testing.T) {
|
||||||
defer tcp.Close()
|
defer tcp.Close()
|
||||||
|
|
||||||
s := statServer{}
|
s := statServer{}
|
||||||
//nolint:errcheck,revive
|
go fcgi.Serve(tcp, s) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
go fcgi.Serve(tcp, s)
|
|
||||||
|
|
||||||
//Now we tested again above server
|
//Now we tested again above server
|
||||||
r := &phpfpm{
|
r := &phpfpm{
|
||||||
|
|
@ -125,8 +124,7 @@ func TestPhpFpmGeneratesMetrics_From_Socket(t *testing.T) {
|
||||||
|
|
||||||
defer tcp.Close()
|
defer tcp.Close()
|
||||||
s := statServer{}
|
s := statServer{}
|
||||||
//nolint:errcheck,revive
|
go fcgi.Serve(tcp, s) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
go fcgi.Serve(tcp, s)
|
|
||||||
|
|
||||||
r := &phpfpm{
|
r := &phpfpm{
|
||||||
Urls: []string{tcp.Addr().String()},
|
Urls: []string{tcp.Addr().String()},
|
||||||
|
|
@ -178,10 +176,8 @@ func TestPhpFpmGeneratesMetrics_From_Multiple_Sockets_With_Glob(t *testing.T) {
|
||||||
defer tcp2.Close()
|
defer tcp2.Close()
|
||||||
|
|
||||||
s := statServer{}
|
s := statServer{}
|
||||||
//nolint:errcheck,revive
|
go fcgi.Serve(tcp1, s) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
go fcgi.Serve(tcp1, s)
|
go fcgi.Serve(tcp2, s) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
go fcgi.Serve(tcp2, s)
|
|
||||||
|
|
||||||
r := &phpfpm{
|
r := &phpfpm{
|
||||||
Urls: []string{"/tmp/test-fpm[\\-0-9]*.sock"},
|
Urls: []string{"/tmp/test-fpm[\\-0-9]*.sock"},
|
||||||
|
|
@ -234,8 +230,7 @@ func TestPhpFpmGeneratesMetrics_From_Socket_Custom_Status_Path(t *testing.T) {
|
||||||
|
|
||||||
defer tcp.Close()
|
defer tcp.Close()
|
||||||
s := statServer{}
|
s := statServer{}
|
||||||
//nolint:errcheck,revive
|
go fcgi.Serve(tcp, s) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
go fcgi.Serve(tcp, s)
|
|
||||||
|
|
||||||
r := &phpfpm{
|
r := &phpfpm{
|
||||||
Urls: []string{tcp.Addr().String() + ":custom-status-path"},
|
Urls: []string{tcp.Addr().String() + ":custom-status-path"},
|
||||||
|
|
|
||||||
|
|
@ -143,9 +143,7 @@ func (p *Service) Start(telegraf.Accumulator) (err error) {
|
||||||
|
|
||||||
// Stop stops the services and closes any necessary channels and connections
|
// Stop stops the services and closes any necessary channels and connections
|
||||||
func (p *Service) Stop() {
|
func (p *Service) Stop() {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
p.DB.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
p.DB.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var kvMatcher, _ = regexp.Compile(`(password|sslcert|sslkey|sslmode|sslrootcert)=\S+ ?`)
|
var kvMatcher, _ = regexp.Compile(`(password|sslcert|sslkey|sslmode|sslrootcert)=\S+ ?`)
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,8 @@ func (s statServer) serverSocket(l net.Listener) {
|
||||||
|
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
if string(data) == "show * \n" {
|
if string(data) == "show * \n" {
|
||||||
// Ignore the returned error as we need to close the socket anyway
|
c.Write([]byte(metrics)) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
||||||
//nolint:errcheck,revive
|
c.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
c.Write([]byte(metrics))
|
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
c.Close()
|
|
||||||
}
|
}
|
||||||
}(conn)
|
}(conn)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,13 +112,8 @@ func TestV1PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
// Ignore the returned error as we need to remove the socket file anyway
|
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway
|
||||||
//nolint:errcheck,revive
|
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors
|
||||||
socket.Close()
|
|
||||||
// Ignore the returned error as we want to remove the file and ignore
|
|
||||||
// no-such-file errors
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
os.Remove(controlSocket)
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -126,20 +121,14 @@ func TestV1PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
n, remote, err := socket.ReadFromUnix(buf)
|
n, remote, err := socket.ReadFromUnix(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
socket.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
if string(data) == "get-all\n" {
|
if string(data) == "get-all\n" {
|
||||||
// Ignore the returned error as we need to close the socket anyway
|
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
||||||
//nolint:errcheck,revive
|
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
socket.WriteToUnix([]byte(metrics), remote)
|
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
socket.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
@ -178,13 +167,8 @@ func TestV2PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
// Ignore the returned error as we need to remove the socket file anyway
|
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway
|
||||||
//nolint:errcheck,revive
|
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors
|
||||||
socket.Close()
|
|
||||||
// Ignore the returned error as we want to remove the file and ignore
|
|
||||||
// no-such-file errors
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
os.Remove(controlSocket)
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -192,31 +176,22 @@ func TestV2PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
status := make([]byte, 4)
|
status := make([]byte, 4)
|
||||||
n, _, err := socket.ReadFromUnix(status)
|
n, _, err := socket.ReadFromUnix(status)
|
||||||
if err != nil || n != 4 {
|
if err != nil || n != 4 {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
socket.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
n, remote, err := socket.ReadFromUnix(buf)
|
n, remote, err := socket.ReadFromUnix(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
socket.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := buf[:n]
|
data := buf[:n]
|
||||||
if string(data) == "get-all" {
|
if string(data) == "get-all" {
|
||||||
// Ignore the returned error as we need to close the socket anyway
|
socket.WriteToUnix([]byte{0, 0, 0, 0}, remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
||||||
//nolint:errcheck,revive
|
socket.WriteToUnix([]byte(metrics), remote) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
||||||
socket.WriteToUnix([]byte{0, 0, 0, 0}, remote)
|
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
socket.WriteToUnix([]byte(metrics), remote)
|
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
socket.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
@ -254,13 +229,8 @@ func TestV3PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
// Ignore the returned error as we need to remove the socket file anyway
|
socket.Close() //nolint:revive // ignore the returned error as we need to remove the socket file anyway
|
||||||
//nolint:errcheck,revive
|
os.Remove(controlSocket) //nolint:revive // ignore the returned error as we want to remove the file and ignore no-such-file errors
|
||||||
socket.Close()
|
|
||||||
// Ignore the returned error as we want to remove the file and ignore
|
|
||||||
// no-such-file errors
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
os.Remove(controlSocket)
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -288,21 +258,11 @@ func TestV3PowerdnsRecursorGeneratesMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(buf) == "get-all" {
|
if string(buf) == "get-all" {
|
||||||
// Ignore the returned error as we need to close the socket anyway
|
conn.Write([]byte{0, 0, 0, 0}) //nolint:errcheck,revive // ignore the returned error as we need to close the socket anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
conn.Write([]byte{0, 0, 0, 0})
|
|
||||||
|
|
||||||
metrics := []byte(metrics)
|
metrics := []byte(metrics)
|
||||||
|
writeNativeUIntToConn(conn, uint(len(metrics))) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
conn.Write(metrics) //nolint:errcheck,revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
writeNativeUIntToConn(conn, uint(len(metrics)))
|
socket.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
conn.Write(metrics)
|
|
||||||
|
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
|
||||||
//nolint:errcheck,revive
|
|
||||||
socket.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/shirou/gopsutil/v3/process"
|
"github.com/shirou/gopsutil/v3/process"
|
||||||
)
|
)
|
||||||
|
|
||||||
// nolint:interfacebloat // conditionally allow to contain more methods
|
//nolint:interfacebloat // conditionally allow to contain more methods
|
||||||
type Process interface {
|
type Process interface {
|
||||||
PID() PID
|
PID() PID
|
||||||
Tags() map[string]string
|
Tags() map[string]string
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,7 @@ func (s *SFlow) Gather(_ telegraf.Accumulator) error {
|
||||||
|
|
||||||
func (s *SFlow) Stop() {
|
func (s *SFlow) Stop() {
|
||||||
if s.closer != nil {
|
if s.closer != nil {
|
||||||
// Ignore the returned error as we cannot do anything about it anyway
|
s.closer.Close() //nolint:revive // ignore the returned error as we cannot do anything about it anyway
|
||||||
//nolint:errcheck,revive
|
|
||||||
s.closer.Close()
|
|
||||||
}
|
}
|
||||||
s.wg.Wait()
|
s.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -567,7 +567,7 @@ func (m *Smart) getVendorNVMeAttributes(acc telegraf.Accumulator, devices []stri
|
||||||
|
|
||||||
for _, device := range nvmeDevices {
|
for _, device := range nvmeDevices {
|
||||||
if contains(m.EnableExtensions, "auto-on") {
|
if contains(m.EnableExtensions, "auto-on") {
|
||||||
// nolint:revive // one case switch on purpose to demonstrate potential extensions
|
//nolint:revive // one case switch on purpose to demonstrate potential extensions
|
||||||
switch device.vendorID {
|
switch device.vendorID {
|
||||||
case intelVID:
|
case intelVID:
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,13 @@ type gosmiSnmpTranslateCache struct {
|
||||||
var gosmiSnmpTranslateCachesLock sync.Mutex
|
var gosmiSnmpTranslateCachesLock sync.Mutex
|
||||||
var gosmiSnmpTranslateCaches map[string]gosmiSnmpTranslateCache
|
var gosmiSnmpTranslateCaches map[string]gosmiSnmpTranslateCache
|
||||||
|
|
||||||
//nolint:revive
|
//nolint:revive //function-result-limit conditionally 5 return results allowed
|
||||||
func (g *gosmiTranslator) SnmpTranslate(oid string) (string, string, string, string, error) {
|
func (g *gosmiTranslator) SnmpTranslate(oid string) (mibName string, oidNum string, oidText string, conversion string, err error) {
|
||||||
a, b, c, d, _, e := g.SnmpTranslateFull(oid)
|
mibName, oidNum, oidText, conversion, _, err = g.SnmpTranslateFull(oid)
|
||||||
return a, b, c, d, e
|
return mibName, oidNum, oidText, conversion, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:revive
|
//nolint:revive //function-result-limit conditionally 6 return results allowed
|
||||||
func (g *gosmiTranslator) SnmpTranslateFull(oid string) (
|
func (g *gosmiTranslator) SnmpTranslateFull(oid string) (
|
||||||
mibName string, oidNum string, oidText string,
|
mibName string, oidNum string, oidText string,
|
||||||
conversion string,
|
conversion string,
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ var snmpTableCachesLock sync.Mutex
|
||||||
// snmpTable resolves the given OID as a table, providing information about the
|
// snmpTable resolves the given OID as a table, providing information about the
|
||||||
// table and fields within.
|
// table and fields within.
|
||||||
//
|
//
|
||||||
//nolint:revive
|
//nolint:revive //function-result-limit conditionally 5 return results allowed
|
||||||
func (n *netsnmpTranslator) SnmpTable(oid string) (
|
func (n *netsnmpTranslator) SnmpTable(oid string) (
|
||||||
mibName string, oidNum string, oidText string,
|
mibName string, oidNum string, oidText string,
|
||||||
fields []Field,
|
fields []Field,
|
||||||
|
|
@ -81,7 +81,7 @@ func (n *netsnmpTranslator) SnmpTable(oid string) (
|
||||||
return stc.mibName, stc.oidNum, stc.oidText, stc.fields, stc.err
|
return stc.mibName, stc.oidNum, stc.oidText, stc.fields, stc.err
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:revive
|
//nolint:revive //function-result-limit conditionally 5 return results allowed
|
||||||
func (n *netsnmpTranslator) snmpTableCall(oid string) (
|
func (n *netsnmpTranslator) snmpTableCall(oid string) (
|
||||||
mibName string, oidNum string, oidText string,
|
mibName string, oidNum string, oidText string,
|
||||||
fields []Field,
|
fields []Field,
|
||||||
|
|
@ -157,7 +157,7 @@ var snmpTranslateCaches map[string]snmpTranslateCache
|
||||||
|
|
||||||
// snmpTranslate resolves the given OID.
|
// snmpTranslate resolves the given OID.
|
||||||
//
|
//
|
||||||
//nolint:revive
|
//nolint:revive //function-result-limit conditionally 5 return results allowed
|
||||||
func (n *netsnmpTranslator) SnmpTranslate(oid string) (
|
func (n *netsnmpTranslator) SnmpTranslate(oid string) (
|
||||||
mibName string, oidNum string, oidText string,
|
mibName string, oidNum string, oidText string,
|
||||||
conversion string,
|
conversion string,
|
||||||
|
|
@ -187,7 +187,7 @@ func (n *netsnmpTranslator) SnmpTranslate(oid string) (
|
||||||
return stc.mibName, stc.oidNum, stc.oidText, stc.conversion, stc.err
|
return stc.mibName, stc.oidNum, stc.oidText, stc.conversion, stc.err
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:revive
|
//nolint:revive //function-result-limit conditionally 5 return results allowed
|
||||||
func snmpTranslateCall(oid string) (mibName string, oidNum string, oidText string, conversion string, err error) {
|
func snmpTranslateCall(oid string) (mibName string, oidNum string, oidText string, conversion string, err error) {
|
||||||
var out []byte
|
var out []byte
|
||||||
if strings.ContainsAny(oid, ":abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
|
if strings.ContainsAny(oid, ":abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ type SnmpTrap struct {
|
||||||
|
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
||||||
translator translator //nolint:revive
|
transl translator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*SnmpTrap) SampleConfig() string {
|
func (*SnmpTrap) SampleConfig() string {
|
||||||
|
|
@ -84,12 +84,12 @@ func (s *SnmpTrap) Init() error {
|
||||||
var err error
|
var err error
|
||||||
switch s.Translator {
|
switch s.Translator {
|
||||||
case "gosmi":
|
case "gosmi":
|
||||||
s.translator, err = newGosmiTranslator(s.Path, s.Log)
|
s.transl, err = newGosmiTranslator(s.Path, s.Log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case "netsnmp":
|
case "netsnmp":
|
||||||
s.translator = newNetsnmpTranslator(s.Timeout)
|
s.transl = newNetsnmpTranslator(s.Timeout)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid translator value")
|
return fmt.Errorf("invalid translator value")
|
||||||
}
|
}
|
||||||
|
|
@ -268,7 +268,7 @@ func makeTrapHandler(s *SnmpTrap) gosnmp.TrapHandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
if trapOid != "" {
|
if trapOid != "" {
|
||||||
e, err := s.translator.lookup(trapOid)
|
e, err := s.transl.lookup(trapOid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Log.Errorf("Error resolving V1 OID, oid=%s, source=%s: %v", trapOid, tags["source"], err)
|
s.Log.Errorf("Error resolving V1 OID, oid=%s, source=%s: %v", trapOid, tags["source"], err)
|
||||||
return
|
return
|
||||||
|
|
@ -306,7 +306,7 @@ func makeTrapHandler(s *SnmpTrap) gosnmp.TrapHandlerFunc {
|
||||||
|
|
||||||
var e snmp.MibEntry
|
var e snmp.MibEntry
|
||||||
var err error
|
var err error
|
||||||
e, err = s.translator.lookup(val)
|
e, err = s.transl.lookup(val)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
s.Log.Errorf("Error resolving value OID, oid=%s, source=%s: %v", val, tags["source"], err)
|
s.Log.Errorf("Error resolving value OID, oid=%s, source=%s: %v", val, tags["source"], err)
|
||||||
return
|
return
|
||||||
|
|
@ -324,7 +324,7 @@ func makeTrapHandler(s *SnmpTrap) gosnmp.TrapHandlerFunc {
|
||||||
value = v.Value
|
value = v.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
e, err := s.translator.lookup(v.Name)
|
e, err := s.transl.lookup(v.Name)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
s.Log.Errorf("Error resolving OID oid=%s, source=%s: %v", v.Name, tags["source"], err)
|
s.Log.Errorf("Error resolving OID oid=%s, source=%s: %v", v.Name, tags["source"], err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1287,7 +1287,7 @@ func TestReceiveTrap(t *testing.T) {
|
||||||
require.NoError(t, s.Init())
|
require.NoError(t, s.Init())
|
||||||
|
|
||||||
//inject test translator
|
//inject test translator
|
||||||
s.translator = newTestTranslator(tt.entries)
|
s.transl = newTestTranslator(tt.entries)
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
require.NoError(t, s.Start(&acc))
|
require.NoError(t, s.Start(&acc))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue