refactor: move from io/ioutil to io and os package (#9811)
This commit is contained in:
parent
c4d2ad85f0
commit
6a3b27126a
|
|
@ -3,7 +3,7 @@ package config
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -933,7 +933,7 @@ func loadConfig(config string) ([]byte, error) {
|
|||
}
|
||||
|
||||
// If it isn't a https scheme, try it as a file
|
||||
return ioutil.ReadFile(config)
|
||||
return os.ReadFile(config)
|
||||
}
|
||||
|
||||
func fetchConfig(u *url.URL) ([]byte, error) {
|
||||
|
|
@ -964,7 +964,7 @@ func fetchConfig(u *url.URL) ([]byte, error) {
|
|||
return nil, fmt.Errorf("Retry %d of %d failed to retrieve remote config: %s", i, retries, resp.Status)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return ioutil.ReadAll(resp.Body)
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package internal
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -68,7 +68,7 @@ func TestStreamIdentityDecode(t *testing.T) {
|
|||
dec, err := NewStreamContentDecoder("identity", &r)
|
||||
require.NoError(t, err)
|
||||
|
||||
data, err := ioutil.ReadAll(dec)
|
||||
data, err := io.ReadAll(dec)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, []byte("howdy"), data)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"compress/gzip"
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
|
|
@ -182,7 +181,7 @@ func TestCompressWithGzip(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
defer gzipReader.Close()
|
||||
|
||||
output, err := ioutil.ReadAll(gzipReader)
|
||||
output, err := io.ReadAll(gzipReader)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, testData, string(output))
|
||||
|
|
@ -203,7 +202,7 @@ func TestCompressWithGzipEarlyClose(t *testing.T) {
|
|||
rc, err := CompressWithGzip(mr)
|
||||
assert.NoError(t, err)
|
||||
|
||||
n, err := io.CopyN(ioutil.Discard, rc, 10000)
|
||||
n, err := io.CopyN(io.Discard, rc, 10000)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(10000), n)
|
||||
|
||||
|
|
@ -211,7 +210,7 @@ func TestCompressWithGzipEarlyClose(t *testing.T) {
|
|||
err = rc.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
n, err = io.CopyN(ioutil.Discard, rc, 10000)
|
||||
n, err = io.CopyN(io.Discard, rc, 10000)
|
||||
assert.Error(t, io.EOF, err)
|
||||
assert.Equal(t, int64(0), n)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
|
@ -187,5 +186,5 @@ func isQuitting(ctx context.Context) bool {
|
|||
}
|
||||
|
||||
func defaultReadPipe(r io.Reader) {
|
||||
io.Copy(ioutil.Discard, r)
|
||||
_, _ = io.Copy(io.Discard, r)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package rotate
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
|
@ -12,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestFileWriter_NoRotation(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "RotationNo")
|
||||
tempDir, err := os.MkdirTemp("", "RotationNo")
|
||||
require.NoError(t, err)
|
||||
writer, err := NewFileWriter(filepath.Join(tempDir, "test"), 0, 0, 0)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -22,12 +21,12 @@ func TestFileWriter_NoRotation(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
_, err = writer.Write([]byte("Hello World 2"))
|
||||
require.NoError(t, err)
|
||||
files, _ := ioutil.ReadDir(tempDir)
|
||||
files, _ := os.ReadDir(tempDir)
|
||||
assert.Equal(t, 1, len(files))
|
||||
}
|
||||
|
||||
func TestFileWriter_TimeRotation(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "RotationTime")
|
||||
tempDir, err := os.MkdirTemp("", "RotationTime")
|
||||
require.NoError(t, err)
|
||||
interval, _ := time.ParseDuration("1s")
|
||||
writer, err := NewFileWriter(filepath.Join(tempDir, "test"), interval, 0, -1)
|
||||
|
|
@ -39,28 +38,28 @@ func TestFileWriter_TimeRotation(t *testing.T) {
|
|||
time.Sleep(1 * time.Second)
|
||||
_, err = writer.Write([]byte("Hello World 2"))
|
||||
require.NoError(t, err)
|
||||
files, _ := ioutil.ReadDir(tempDir)
|
||||
files, _ := os.ReadDir(tempDir)
|
||||
assert.Equal(t, 2, len(files))
|
||||
}
|
||||
|
||||
func TestFileWriter_ReopenTimeRotation(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "RotationTime")
|
||||
tempDir, err := os.MkdirTemp("", "RotationTime")
|
||||
require.NoError(t, err)
|
||||
interval, _ := time.ParseDuration("1s")
|
||||
filePath := filepath.Join(tempDir, "test.log")
|
||||
err = ioutil.WriteFile(filePath, []byte("Hello World"), 0644)
|
||||
err = os.WriteFile(filePath, []byte("Hello World"), 0644)
|
||||
time.Sleep(1 * time.Second)
|
||||
assert.NoError(t, err)
|
||||
writer, err := NewFileWriter(filepath.Join(tempDir, "test.log"), interval, 0, -1)
|
||||
require.NoError(t, err)
|
||||
defer func() { writer.Close(); os.RemoveAll(tempDir) }()
|
||||
|
||||
files, _ := ioutil.ReadDir(tempDir)
|
||||
files, _ := os.ReadDir(tempDir)
|
||||
assert.Equal(t, 2, len(files))
|
||||
}
|
||||
|
||||
func TestFileWriter_SizeRotation(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "RotationSize")
|
||||
tempDir, err := os.MkdirTemp("", "RotationSize")
|
||||
require.NoError(t, err)
|
||||
maxSize := int64(9)
|
||||
writer, err := NewFileWriter(filepath.Join(tempDir, "test.log"), 0, maxSize, -1)
|
||||
|
|
@ -71,16 +70,16 @@ func TestFileWriter_SizeRotation(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
_, err = writer.Write([]byte("World 2"))
|
||||
require.NoError(t, err)
|
||||
files, _ := ioutil.ReadDir(tempDir)
|
||||
files, _ := os.ReadDir(tempDir)
|
||||
assert.Equal(t, 2, len(files))
|
||||
}
|
||||
|
||||
func TestFileWriter_ReopenSizeRotation(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "RotationSize")
|
||||
tempDir, err := os.MkdirTemp("", "RotationSize")
|
||||
require.NoError(t, err)
|
||||
maxSize := int64(12)
|
||||
filePath := filepath.Join(tempDir, "test.log")
|
||||
err = ioutil.WriteFile(filePath, []byte("Hello World"), 0644)
|
||||
err = os.WriteFile(filePath, []byte("Hello World"), 0644)
|
||||
assert.NoError(t, err)
|
||||
writer, err := NewFileWriter(filepath.Join(tempDir, "test.log"), 0, maxSize, -1)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -88,12 +87,12 @@ func TestFileWriter_ReopenSizeRotation(t *testing.T) {
|
|||
|
||||
_, err = writer.Write([]byte("Hello World Again"))
|
||||
require.NoError(t, err)
|
||||
files, _ := ioutil.ReadDir(tempDir)
|
||||
files, _ := os.ReadDir(tempDir)
|
||||
assert.Equal(t, 2, len(files))
|
||||
}
|
||||
|
||||
func TestFileWriter_DeleteArchives(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "RotationDeleteArchives")
|
||||
tempDir, err := os.MkdirTemp("", "RotationDeleteArchives")
|
||||
require.NoError(t, err)
|
||||
maxSize := int64(5)
|
||||
writer, err := NewFileWriter(filepath.Join(tempDir, "test.log"), 0, maxSize, 2)
|
||||
|
|
@ -112,14 +111,14 @@ func TestFileWriter_DeleteArchives(t *testing.T) {
|
|||
_, err = writer.Write([]byte("Third file"))
|
||||
require.NoError(t, err)
|
||||
|
||||
files, _ := ioutil.ReadDir(tempDir)
|
||||
files, _ := os.ReadDir(tempDir)
|
||||
assert.Equal(t, 3, len(files))
|
||||
|
||||
for _, tempFile := range files {
|
||||
var bytes []byte
|
||||
var err error
|
||||
path := filepath.Join(tempDir, tempFile.Name())
|
||||
if bytes, err = ioutil.ReadFile(path); err != nil {
|
||||
if bytes, err = os.ReadFile(path); err != nil {
|
||||
t.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
|
@ -133,7 +132,7 @@ func TestFileWriter_DeleteArchives(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileWriter_CloseRotates(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "RotationClose")
|
||||
tempDir, err := os.MkdirTemp("", "RotationClose")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
maxSize := int64(9)
|
||||
|
|
@ -142,7 +141,7 @@ func TestFileWriter_CloseRotates(t *testing.T) {
|
|||
|
||||
writer.Close()
|
||||
|
||||
files, _ := ioutil.ReadDir(tempDir)
|
||||
files, _ := os.ReadDir(tempDir)
|
||||
assert.Equal(t, 1, len(files))
|
||||
assert.Regexp(t, "^test\\.[^\\.]+\\.log$", files[0].Name())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package logger
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -15,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestWriteLogToFile(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "")
|
||||
tmpfile, err := os.CreateTemp("", "")
|
||||
assert.NoError(t, err)
|
||||
defer func() { os.Remove(tmpfile.Name()) }()
|
||||
|
||||
|
|
@ -24,13 +23,13 @@ func TestWriteLogToFile(t *testing.T) {
|
|||
log.Printf("I! TEST")
|
||||
log.Printf("D! TEST") // <- should be ignored
|
||||
|
||||
f, err := ioutil.ReadFile(tmpfile.Name())
|
||||
f, err := os.ReadFile(tmpfile.Name())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, f[19:], []byte("Z I! TEST\n"))
|
||||
}
|
||||
|
||||
func TestDebugWriteLogToFile(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "")
|
||||
tmpfile, err := os.CreateTemp("", "")
|
||||
assert.NoError(t, err)
|
||||
defer func() { os.Remove(tmpfile.Name()) }()
|
||||
config := createBasicLogConfig(tmpfile.Name())
|
||||
|
|
@ -38,13 +37,13 @@ func TestDebugWriteLogToFile(t *testing.T) {
|
|||
SetupLogging(config)
|
||||
log.Printf("D! TEST")
|
||||
|
||||
f, err := ioutil.ReadFile(tmpfile.Name())
|
||||
f, err := os.ReadFile(tmpfile.Name())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, f[19:], []byte("Z D! TEST\n"))
|
||||
}
|
||||
|
||||
func TestErrorWriteLogToFile(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "")
|
||||
tmpfile, err := os.CreateTemp("", "")
|
||||
assert.NoError(t, err)
|
||||
defer func() { os.Remove(tmpfile.Name()) }()
|
||||
config := createBasicLogConfig(tmpfile.Name())
|
||||
|
|
@ -53,13 +52,13 @@ func TestErrorWriteLogToFile(t *testing.T) {
|
|||
log.Printf("E! TEST")
|
||||
log.Printf("I! TEST") // <- should be ignored
|
||||
|
||||
f, err := ioutil.ReadFile(tmpfile.Name())
|
||||
f, err := os.ReadFile(tmpfile.Name())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, f[19:], []byte("Z E! TEST\n"))
|
||||
}
|
||||
|
||||
func TestAddDefaultLogLevel(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "")
|
||||
tmpfile, err := os.CreateTemp("", "")
|
||||
assert.NoError(t, err)
|
||||
defer func() { os.Remove(tmpfile.Name()) }()
|
||||
config := createBasicLogConfig(tmpfile.Name())
|
||||
|
|
@ -67,13 +66,13 @@ func TestAddDefaultLogLevel(t *testing.T) {
|
|||
SetupLogging(config)
|
||||
log.Printf("TEST")
|
||||
|
||||
f, err := ioutil.ReadFile(tmpfile.Name())
|
||||
f, err := os.ReadFile(tmpfile.Name())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, f[19:], []byte("Z I! TEST\n"))
|
||||
}
|
||||
|
||||
func TestWriteToTruncatedFile(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "")
|
||||
tmpfile, err := os.CreateTemp("", "")
|
||||
assert.NoError(t, err)
|
||||
defer func() { os.Remove(tmpfile.Name()) }()
|
||||
config := createBasicLogConfig(tmpfile.Name())
|
||||
|
|
@ -81,7 +80,7 @@ func TestWriteToTruncatedFile(t *testing.T) {
|
|||
SetupLogging(config)
|
||||
log.Printf("TEST")
|
||||
|
||||
f, err := ioutil.ReadFile(tmpfile.Name())
|
||||
f, err := os.ReadFile(tmpfile.Name())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, f[19:], []byte("Z I! TEST\n"))
|
||||
|
||||
|
|
@ -91,13 +90,13 @@ func TestWriteToTruncatedFile(t *testing.T) {
|
|||
|
||||
log.Printf("SHOULD BE FIRST")
|
||||
|
||||
f, err = ioutil.ReadFile(tmpfile.Name())
|
||||
f, err = os.ReadFile(tmpfile.Name())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, f[19:], []byte("Z I! SHOULD BE FIRST\n"))
|
||||
}
|
||||
|
||||
func TestWriteToFileInRotation(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "LogRotation")
|
||||
tempDir, err := os.MkdirTemp("", "LogRotation")
|
||||
require.NoError(t, err)
|
||||
cfg := createBasicLogConfig(filepath.Join(tempDir, "test.log"))
|
||||
cfg.LogTarget = LogTargetFile
|
||||
|
|
@ -110,7 +109,7 @@ func TestWriteToFileInRotation(t *testing.T) {
|
|||
|
||||
log.Printf("I! TEST 1") // Writes 31 bytes, will rotate
|
||||
log.Printf("I! TEST") // Writes 29 byes, no rotation expected
|
||||
files, _ := ioutil.ReadDir(tempDir)
|
||||
files, _ := os.ReadDir(tempDir)
|
||||
assert.Equal(t, 2, len(files))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"strings"
|
||||
|
|
@ -78,7 +77,7 @@ func (c *CookieAuthConfig) authRenewal(ctx context.Context, ticker *clockutil.Ti
|
|||
func (c *CookieAuthConfig) auth() error {
|
||||
var body io.ReadCloser
|
||||
if c.Body != "" {
|
||||
body = ioutil.NopCloser(strings.NewReader(c.Body))
|
||||
body = io.NopCloser(strings.NewReader(c.Body))
|
||||
defer body.Close()
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +96,7 @@ func (c *CookieAuthConfig) auth() error {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if _, err = io.Copy(ioutil.Discard, resp.Body); err != nil {
|
||||
if _, err = io.Copy(io.Discard, resp.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package cookie
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync/atomic"
|
||||
|
|
@ -50,7 +50,7 @@ func newFakeServer(t *testing.T) fakeServer {
|
|||
case authEndpointNoCreds:
|
||||
authed()
|
||||
case authEndpointWithBody:
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
if !cmp.Equal([]byte(reqBody), body) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package encoding
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -66,7 +66,7 @@ func TestDecoder(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
buf := bytes.NewBuffer(tt.input)
|
||||
r := decoder.Reader(buf)
|
||||
actual, err := ioutil.ReadAll(r)
|
||||
actual, err := io.ReadAll(r)
|
||||
if tt.expectedErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package logrus
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -19,7 +19,7 @@ type LogHook struct {
|
|||
// that directly log to the logrus system without providing an override method.
|
||||
func InstallHook() {
|
||||
once.Do(func() {
|
||||
logrus.SetOutput(ioutil.Discard)
|
||||
logrus.SetOutput(io.Discard)
|
||||
logrus.AddHook(&LogHook{})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package shim
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
|
|
@ -53,7 +52,7 @@ func LoadConfig(filePath *string) (loaded loadedConfig, err error) {
|
|||
var data string
|
||||
conf := config{}
|
||||
if filePath != nil && *filePath != "" {
|
||||
b, err := ioutil.ReadFile(*filePath)
|
||||
b, err := os.ReadFile(*filePath)
|
||||
if err != nil {
|
||||
return loadedConfig{}, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package shim
|
|||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -45,7 +44,9 @@ func TestInputShimStdinSignalingWorks(t *testing.T) {
|
|||
require.Equal(t, "measurement,tag=tag field=1i 1234000005678\n", out)
|
||||
|
||||
stdinWriter.Close()
|
||||
go ioutil.ReadAll(r)
|
||||
go func() {
|
||||
_, _ = io.ReadAll(r)
|
||||
}()
|
||||
// check that it exits cleanly
|
||||
<-exited
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package shim
|
|||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
|
|
@ -84,7 +83,9 @@ func testSendAndRecieve(t *testing.T, fieldKey string, fieldValue string) {
|
|||
val2, ok := mOut.Fields()[fieldKey]
|
||||
require.True(t, ok)
|
||||
require.Equal(t, fieldValue, val2)
|
||||
go ioutil.ReadAll(r)
|
||||
go func() {
|
||||
_, _ = io.ReadAll(r)
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ func (c *ServerConfig) TLSConfig() (*tls.Config, error) {
|
|||
func makeCertPool(certFiles []string) (*x509.CertPool, error) {
|
||||
pool := x509.NewCertPool()
|
||||
for _, certFile := range certFiles {
|
||||
pem, err := ioutil.ReadFile(certFile)
|
||||
pem, err := os.ReadFile(certFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"could not read certificate %q: %v", certFile, err)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package activemq
|
|||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
|
@ -184,7 +184,7 @@ func (a *ActiveMQ) GetMetrics(u string) ([]byte, error) {
|
|||
return nil, fmt.Errorf("GET %s returned status %q", u, resp.Status)
|
||||
}
|
||||
|
||||
return ioutil.ReadAll(resp.Body)
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
func (a *ActiveMQ) GatherQueuesMetrics(acc telegraf.Accumulator, queues Queues) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package aliyuncms
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -132,7 +132,7 @@ func TestPluginInitialize(t *testing.T) {
|
|||
|
||||
httpResp := &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: ioutil.NopCloser(bytes.NewBufferString(
|
||||
Body: io.NopCloser(bytes.NewBufferString(
|
||||
`{
|
||||
"LoadBalancers":
|
||||
{
|
||||
|
|
@ -359,7 +359,7 @@ func TestGetDiscoveryDataAcrossRegions(t *testing.T) {
|
|||
region: "cn-hongkong",
|
||||
httpResp: &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: ioutil.NopCloser(bytes.NewBufferString(`{}`)),
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{}`)),
|
||||
},
|
||||
totalCount: 0,
|
||||
pageSize: 0,
|
||||
|
|
@ -372,7 +372,7 @@ func TestGetDiscoveryDataAcrossRegions(t *testing.T) {
|
|||
region: "cn-hongkong",
|
||||
httpResp: &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: ioutil.NopCloser(bytes.NewBufferString(
|
||||
Body: io.NopCloser(bytes.NewBufferString(
|
||||
`{
|
||||
"LoadBalancers":
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package amd_rocm_smi
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -78,7 +78,7 @@ func TestGatherValidJSON(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
octets, err := ioutil.ReadFile(filepath.Join("testdata", tt.filename))
|
||||
octets, err := os.ReadFile(filepath.Join("testdata", tt.filename))
|
||||
require.NoError(t, err)
|
||||
|
||||
err = gatherROCmSMI(octets, &acc)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ package bcache
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
|
@ -85,7 +84,7 @@ func (b *Bcache) gatherBcache(bdev string, acc telegraf.Accumulator) error {
|
|||
if len(metrics) == 0 {
|
||||
return errors.New("can't read any stats file")
|
||||
}
|
||||
file, err := ioutil.ReadFile(bdev + "/dirty_data")
|
||||
file, err := os.ReadFile(bdev + "/dirty_data")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -97,7 +96,7 @@ func (b *Bcache) gatherBcache(bdev string, acc telegraf.Accumulator) error {
|
|||
|
||||
for _, path := range metrics {
|
||||
key := filepath.Base(path)
|
||||
file, err := ioutil.ReadFile(path)
|
||||
file, err := os.ReadFile(path)
|
||||
rawValue := strings.TrimSpace(string(file))
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package bcache
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -50,39 +49,39 @@ func TestBcacheGeneratesMetrics(t *testing.T) {
|
|||
err = os.MkdirAll(testBcacheUUIDPath+"/bdev0/stats_total", 0755)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/dirty_data",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/dirty_data",
|
||||
[]byte(dirtyData), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/bypassed",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/bypassed",
|
||||
[]byte(bypassed), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_bypass_hits",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_bypass_hits",
|
||||
[]byte(cacheBypassHits), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_bypass_misses",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_bypass_misses",
|
||||
[]byte(cacheBypassMisses), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_hit_ratio",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_hit_ratio",
|
||||
[]byte(cacheHitRatio), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_hits",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_hits",
|
||||
[]byte(cacheHits), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_miss_collisions",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_miss_collisions",
|
||||
[]byte(cacheMissCollisions), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_misses",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_misses",
|
||||
[]byte(cacheMisses), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_readaheads",
|
||||
err = os.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_readaheads",
|
||||
[]byte(cacheReadaheads), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package beat
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
|
|
@ -31,7 +31,7 @@ func Test_BeatStats(t *testing.T) {
|
|||
require.FailNow(t, "cannot handle request")
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(jsonFilePath)
|
||||
data, err := os.ReadFile(jsonFilePath)
|
||||
require.NoErrorf(t, err, "could not read from data file %s", jsonFilePath)
|
||||
_, err = w.Write(data)
|
||||
require.NoError(t, err, "could not write data")
|
||||
|
|
@ -175,7 +175,7 @@ func Test_BeatRequest(t *testing.T) {
|
|||
require.FailNow(t, "cannot handle request")
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(jsonFilePath)
|
||||
data, err := os.ReadFile(jsonFilePath)
|
||||
require.NoErrorf(t, err, "could not read from data file %s", jsonFilePath)
|
||||
require.Equal(t, request.Host, "beat.test.local")
|
||||
require.Equal(t, request.Method, "POST")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package bond
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
|
@ -53,7 +52,7 @@ func (bond *Bond) Gather(acc telegraf.Accumulator) error {
|
|||
}
|
||||
for _, bondName := range bondNames {
|
||||
bondAbsPath := bond.HostProc + "/net/bonding/" + bondName
|
||||
file, err := ioutil.ReadFile(bondAbsPath)
|
||||
file, err := os.ReadFile(bondAbsPath)
|
||||
if err != nil {
|
||||
acc.AddError(fmt.Errorf("error inspecting '%s' interface: %v", bondAbsPath, err))
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package burrow
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
|
@ -28,7 +27,7 @@ func getResponseJSON(requestURI string) ([]byte, int) {
|
|||
}
|
||||
|
||||
// respond with file
|
||||
b, _ := ioutil.ReadFile(jsonFile)
|
||||
b, _ := os.ReadFile(jsonFile)
|
||||
return b, code
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
|
@ -217,7 +217,7 @@ func (c *Cassandra) getAttr(requestURL *url.URL) (map[string]interface{}, error)
|
|||
}
|
||||
|
||||
// read body
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package cassandra
|
|||
|
||||
import (
|
||||
_ "fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -109,7 +109,7 @@ type jolokiaClientStub struct {
|
|||
func (c jolokiaClientStub) MakeRequest(_ *http.Request) (*http.Response, error) {
|
||||
resp := http.Response{}
|
||||
resp.StatusCode = c.statusCode
|
||||
resp.Body = ioutil.NopCloser(strings.NewReader(c.responseBody))
|
||||
resp.Body = io.NopCloser(strings.NewReader(c.responseBody))
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -206,7 +206,7 @@ var perfDump = func(binary string, socket *socket) (string, error) {
|
|||
}
|
||||
|
||||
var findSockets = func(c *Ceph) ([]*socket, error) {
|
||||
listing, err := ioutil.ReadDir(c.SocketDir)
|
||||
listing, err := os.ReadDir(c.SocketDir)
|
||||
if err != nil {
|
||||
return []*socket{}, fmt.Errorf("Failed to read socket directory '%s': %v", c.SocketDir, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package ceph
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
|
@ -113,7 +112,7 @@ func TestGather(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindSockets(t *testing.T) {
|
||||
tmpdir, err := ioutil.TempDir("", "socktest")
|
||||
tmpdir, err := os.MkdirTemp("", "socktest")
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
err := os.Remove(tmpdir)
|
||||
|
|
@ -189,7 +188,7 @@ func createTestFiles(dir string, st *SockTest) error {
|
|||
writeFile := func(prefix string, i int) error {
|
||||
f := sockFile(prefix, i)
|
||||
fpath := filepath.Join(dir, f)
|
||||
return ioutil.WriteFile(fpath, []byte(""), 0777)
|
||||
return os.WriteFile(fpath, []byte(""), 0777)
|
||||
}
|
||||
return tstFileApply(st, writeFile)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ package cgroup
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
|
@ -46,7 +45,7 @@ func (g *CGroup) gatherDir(acc telegraf.Accumulator, dir string) error {
|
|||
return file.err
|
||||
}
|
||||
|
||||
raw, err := ioutil.ReadFile(file.path)
|
||||
raw, err := os.ReadFile(file.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -590,7 +589,7 @@ func (ch *ClickHouse) execQuery(address *url.URL, query string, i interface{}) e
|
|||
}
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
if resp.StatusCode >= 300 {
|
||||
body, _ := ioutil.ReadAll(io.LimitReader(resp.Body, 200))
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 200))
|
||||
return &clickhouseError{
|
||||
StatusCode: resp.StatusCode,
|
||||
body: body,
|
||||
|
|
@ -606,7 +605,7 @@ func (ch *ClickHouse) execQuery(address *url.URL, query string, i interface{}) e
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
|
||||
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"crypto/subtle"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -222,7 +222,7 @@ func (p *PubSubPush) serveWrite(res http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
body := http.MaxBytesReader(res, req.Body, int64(p.MaxBodySize))
|
||||
bytes, err := ioutil.ReadAll(body)
|
||||
bytes, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
res.WriteHeader(http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ package conntrack
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Conntrack struct {
|
||||
|
|
@ -91,7 +91,7 @@ func (c *Conntrack) Gather(acc telegraf.Accumulator) error {
|
|||
continue
|
||||
}
|
||||
|
||||
contents, err := ioutil.ReadFile(fName)
|
||||
contents, err := os.ReadFile(fName)
|
||||
if err != nil {
|
||||
acc.AddError(fmt.Errorf("E! failed to read file '%s': %v", fName, err))
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package conntrack
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
|
|
@ -35,11 +34,11 @@ func TestNoFilesFound(t *testing.T) {
|
|||
|
||||
func TestDefaultsUsed(t *testing.T) {
|
||||
defer restoreDflts(dfltFiles, dfltDirs)
|
||||
tmpdir, err := ioutil.TempDir("", "tmp1")
|
||||
tmpdir, err := os.MkdirTemp("", "tmp1")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(tmpdir)
|
||||
|
||||
tmpFile, err := ioutil.TempFile(tmpdir, "ip_conntrack_count")
|
||||
tmpFile, err := os.CreateTemp(tmpdir, "ip_conntrack_count")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(tmpFile.Name())
|
||||
|
||||
|
|
@ -48,7 +47,7 @@ func TestDefaultsUsed(t *testing.T) {
|
|||
dfltFiles = []string{fname}
|
||||
|
||||
count := 1234321
|
||||
require.NoError(t, ioutil.WriteFile(tmpFile.Name(), []byte(strconv.Itoa(count)), 0660))
|
||||
require.NoError(t, os.WriteFile(tmpFile.Name(), []byte(strconv.Itoa(count)), 0660))
|
||||
c := &Conntrack{}
|
||||
acc := &testutil.Accumulator{}
|
||||
|
||||
|
|
@ -59,13 +58,13 @@ func TestDefaultsUsed(t *testing.T) {
|
|||
|
||||
func TestConfigsUsed(t *testing.T) {
|
||||
defer restoreDflts(dfltFiles, dfltDirs)
|
||||
tmpdir, err := ioutil.TempDir("", "tmp1")
|
||||
tmpdir, err := os.MkdirTemp("", "tmp1")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(tmpdir)
|
||||
|
||||
cntFile, err := ioutil.TempFile(tmpdir, "nf_conntrack_count")
|
||||
cntFile, err := os.CreateTemp(tmpdir, "nf_conntrack_count")
|
||||
require.NoError(t, err)
|
||||
maxFile, err := ioutil.TempFile(tmpdir, "nf_conntrack_max")
|
||||
maxFile, err := os.CreateTemp(tmpdir, "nf_conntrack_max")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(cntFile.Name())
|
||||
defer os.Remove(maxFile.Name())
|
||||
|
|
@ -77,8 +76,8 @@ func TestConfigsUsed(t *testing.T) {
|
|||
|
||||
count := 1234321
|
||||
max := 9999999
|
||||
require.NoError(t, ioutil.WriteFile(cntFile.Name(), []byte(strconv.Itoa(count)), 0660))
|
||||
require.NoError(t, ioutil.WriteFile(maxFile.Name(), []byte(strconv.Itoa(max)), 0660))
|
||||
require.NoError(t, os.WriteFile(cntFile.Name(), []byte(strconv.Itoa(count)), 0660))
|
||||
require.NoError(t, os.WriteFile(maxFile.Name(), []byte(strconv.Itoa(max)), 0660))
|
||||
c := &Conntrack{}
|
||||
acc := &testutil.Accumulator{}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"crypto/rsa"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
|
@ -48,7 +48,7 @@ func (c *ServiceAccount) IsExpired() bool {
|
|||
}
|
||||
|
||||
func (c *TokenCreds) Token(_ context.Context, _ Client) (string, error) {
|
||||
octets, err := ioutil.ReadFile(c.Path)
|
||||
octets, err := os.ReadFile(c.Path)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error reading token file %q: %s", c.Path, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package dcos
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -370,7 +370,7 @@ func (d *DCOS) createClient() (Client, error) {
|
|||
|
||||
func (d *DCOS) createCredentials() (Credentials, error) {
|
||||
if d.ServiceAccountID != "" && d.ServiceAccountPrivateKey != "" {
|
||||
bs, err := ioutil.ReadFile(d.ServiceAccountPrivateKey)
|
||||
bs, err := os.ReadFile(d.ServiceAccountPrivateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
|
@ -108,7 +107,7 @@ func (monitor *DirectoryMonitor) Description() string {
|
|||
|
||||
func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
|
||||
// Get all files sitting in the directory.
|
||||
files, err := ioutil.ReadDir(monitor.Directory)
|
||||
files, err := os.ReadDir(monitor.Directory)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to monitor the targeted directory: %w", err)
|
||||
}
|
||||
|
|
@ -183,7 +182,7 @@ func (monitor *DirectoryMonitor) Monitor() {
|
|||
}
|
||||
}
|
||||
|
||||
func (monitor *DirectoryMonitor) processFile(file os.FileInfo) {
|
||||
func (monitor *DirectoryMonitor) processFile(file os.DirEntry) {
|
||||
if file.IsDir() {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package directory_monitor
|
|||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
|
@ -20,9 +19,9 @@ func TestCSVGZImport(t *testing.T) {
|
|||
testCsvGzFile := "test.csv.gz"
|
||||
|
||||
// Establish process directory and finished directory.
|
||||
finishedDirectory, err := ioutil.TempDir("", "finished")
|
||||
finishedDirectory, err := os.MkdirTemp("", "finished")
|
||||
require.NoError(t, err)
|
||||
processDirectory, err := ioutil.TempDir("", "test")
|
||||
processDirectory, err := os.MkdirTemp("", "test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(processDirectory)
|
||||
defer os.RemoveAll(finishedDirectory)
|
||||
|
|
@ -62,7 +61,7 @@ func TestCSVGZImport(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
err = w.Close()
|
||||
require.NoError(t, err)
|
||||
err = ioutil.WriteFile(filepath.Join(processDirectory, testCsvGzFile), b.Bytes(), 0666)
|
||||
err = os.WriteFile(filepath.Join(processDirectory, testCsvGzFile), b.Bytes(), 0666)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Start plugin before adding file.
|
||||
|
|
@ -89,9 +88,9 @@ func TestMultipleJSONFileImports(t *testing.T) {
|
|||
testJSONFile := "test.json"
|
||||
|
||||
// Establish process directory and finished directory.
|
||||
finishedDirectory, err := ioutil.TempDir("", "finished")
|
||||
finishedDirectory, err := os.MkdirTemp("", "finished")
|
||||
require.NoError(t, err)
|
||||
processDirectory, err := ioutil.TempDir("", "test")
|
||||
processDirectory, err := os.MkdirTemp("", "test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(processDirectory)
|
||||
defer os.RemoveAll(finishedDirectory)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package diskio
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -20,7 +19,7 @@ S:foo/bar/devlink1
|
|||
|
||||
// setupNullDisk sets up fake udev info as if /dev/null were a disk.
|
||||
func setupNullDisk(t *testing.T, s *DiskIO, devName string) func() {
|
||||
td, err := ioutil.TempFile("", ".telegraf.DiskInfoTest")
|
||||
td, err := os.CreateTemp("", ".telegraf.DiskInfoTest")
|
||||
require.NoError(t, err)
|
||||
|
||||
if s.infoCache == nil {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package docker
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
|
@ -1060,7 +1060,7 @@ func TestContainerName(t *testing.T) {
|
|||
}
|
||||
client.ContainerStatsF = func(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
|
||||
return types.ContainerStats{
|
||||
Body: ioutil.NopCloser(strings.NewReader(`{"name": "logspout"}`)),
|
||||
Body: io.NopCloser(strings.NewReader(`{"name": "logspout"}`)),
|
||||
}, nil
|
||||
}
|
||||
return &client, nil
|
||||
|
|
@ -1080,7 +1080,7 @@ func TestContainerName(t *testing.T) {
|
|||
}
|
||||
client.ContainerStatsF = func(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
|
||||
return types.ContainerStats{
|
||||
Body: ioutil.NopCloser(strings.NewReader(`{}`)),
|
||||
Body: io.NopCloser(strings.NewReader(`{}`)),
|
||||
}, nil
|
||||
}
|
||||
return &client, nil
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package docker
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -344,7 +344,7 @@ func containerStats(s string) types.ContainerStats {
|
|||
},
|
||||
"read": "2016-02-24T11:42:27.472459608-05:00"
|
||||
}`, name)
|
||||
stat.Body = ioutil.NopCloser(strings.NewReader(jsonStat))
|
||||
stat.Body = io.NopCloser(strings.NewReader(jsonStat))
|
||||
return stat
|
||||
}
|
||||
|
||||
|
|
@ -488,7 +488,7 @@ func containerStatsWindows() types.ContainerStats {
|
|||
},
|
||||
"name":"/gt_test_iis",
|
||||
}`
|
||||
stat.Body = ioutil.NopCloser(strings.NewReader(jsonStat))
|
||||
stat.Body = io.NopCloser(strings.NewReader(jsonStat))
|
||||
return stat
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package ecs
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
|
@ -113,7 +112,7 @@ func (c *EcsClient) Task() (*Task, error) {
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
// ignore the err here; LimitReader returns io.EOF and we're not interested in read errors.
|
||||
body, _ := ioutil.ReadAll(io.LimitReader(resp.Body, 200))
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 200))
|
||||
return nil, fmt.Errorf("%s returned HTTP status %s: %q", c.taskURL, resp.Status, body)
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +136,7 @@ func (c *EcsClient) ContainerStats() (map[string]types.StatsJSON, error) {
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
// ignore the err here; LimitReader returns io.EOF and we're not interested in read errors.
|
||||
body, _ := ioutil.ReadAll(io.LimitReader(resp.Body, 200))
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 200))
|
||||
return nil, fmt.Errorf("%s returned HTTP status %s: %q", c.statsURL, resp.Status, body)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ecs
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
|
@ -108,7 +108,7 @@ func TestEcsClient_Task(t *testing.T) {
|
|||
do: func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(rc),
|
||||
Body: io.NopCloser(rc),
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
|
|
@ -129,7 +129,7 @@ func TestEcsClient_Task(t *testing.T) {
|
|||
do: func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
|
|
@ -141,7 +141,7 @@ func TestEcsClient_Task(t *testing.T) {
|
|||
do: func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
|
|
@ -179,7 +179,7 @@ func TestEcsClient_ContainerStats(t *testing.T) {
|
|||
do: func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(rc),
|
||||
Body: io.NopCloser(rc),
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
|
|
@ -201,7 +201,7 @@ func TestEcsClient_ContainerStats(t *testing.T) {
|
|||
do: func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
|
|
@ -214,7 +214,7 @@ func TestEcsClient_ContainerStats(t *testing.T) {
|
|||
do: func(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package elasticsearch
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
|
|
@ -702,7 +702,7 @@ func (e *Elasticsearch) getCatMaster(url string) (string, error) {
|
|||
// future calls.
|
||||
return "", fmt.Errorf("elasticsearch: Unable to retrieve master node information. API responded with status-code %d, expected %d", r.StatusCode, http.StatusOK)
|
||||
}
|
||||
response, err := ioutil.ReadAll(r.Body)
|
||||
response, err := io.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package elasticsearch
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -44,7 +44,7 @@ func (t *transportMock) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||
StatusCode: t.statusCode,
|
||||
}
|
||||
res.Header.Set("Content-Type", "application/json")
|
||||
res.Body = ioutil.NopCloser(strings.NewReader(t.body))
|
||||
res.Body = io.NopCloser(strings.NewReader(t.body))
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
|
|
@ -274,7 +273,7 @@ func LoadConfig(filePath *string) ([]telegraf.Input, error) {
|
|||
return DefaultImportedPlugins()
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadFile(*filePath)
|
||||
b, err := os.ReadFile(*filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package file
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ func (f *File) readMetric(filename string) ([]telegraf.Metric, error) {
|
|||
defer file.Close()
|
||||
|
||||
r, _ := utfbom.Skip(f.decoder.Reader(file))
|
||||
fileContents, err := ioutil.ReadAll(r)
|
||||
fileContents, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("E! Error file: %v could not be read, %s", filename, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package fluentd
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
|
@ -104,7 +104,7 @@ func (h *Fluentd) Gather(acc telegraf.Accumulator) error {
|
|||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read the HTTP body \"%s\": %v", string(body), err)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -264,7 +264,7 @@ func (h *GrayLog) sendRequest(serverURL string) (string, float64, error) {
|
|||
defer resp.Body.Close()
|
||||
responseTime := time.Since(start).Seconds()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return string(body), responseTime, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package graylog
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -115,7 +115,7 @@ func (c *mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error)
|
|||
resp.StatusCode = 405 // Method not allowed
|
||||
}
|
||||
|
||||
resp.Body = ioutil.NopCloser(strings.NewReader(c.responseBody))
|
||||
resp.Body = io.NopCloser(strings.NewReader(c.responseBody))
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ func (h *HTTP) gatherURL(
|
|||
}
|
||||
|
||||
if h.BearerToken != "" {
|
||||
token, err := ioutil.ReadFile(h.BearerToken)
|
||||
token, err := os.ReadFile(h.BearerToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -225,7 +225,7 @@ func (h *HTTP) gatherURL(
|
|||
h.SuccessStatusCodes)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -254,7 +254,7 @@ func makeRequestBodyReader(contentEncoding, body string) (io.ReadCloser, error)
|
|||
}
|
||||
return rc, nil
|
||||
}
|
||||
return ioutil.NopCloser(reader), nil
|
||||
return io.NopCloser(reader), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package http_test
|
|||
import (
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
|
|
@ -183,7 +183,7 @@ func TestBodyAndContentEncoding(t *testing.T) {
|
|||
URLs: []string{url},
|
||||
},
|
||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []byte(""), body)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
@ -197,7 +197,7 @@ func TestBodyAndContentEncoding(t *testing.T) {
|
|||
Body: "test",
|
||||
},
|
||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []byte("test"), body)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
@ -211,7 +211,7 @@ func TestBodyAndContentEncoding(t *testing.T) {
|
|||
Body: "test",
|
||||
},
|
||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []byte("test"), body)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
@ -230,7 +230,7 @@ func TestBodyAndContentEncoding(t *testing.T) {
|
|||
|
||||
gr, err := gzip.NewReader(r.Body)
|
||||
require.NoError(t, err)
|
||||
body, err := ioutil.ReadAll(gr)
|
||||
body, err := io.ReadAll(gr)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []byte("test"), body)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"compress/gzip"
|
||||
"crypto/subtle"
|
||||
"crypto/tls"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -292,7 +292,7 @@ func (h *HTTPListenerV2) collectBody(res http.ResponseWriter, req *http.Request)
|
|||
}
|
||||
defer r.Close()
|
||||
maxReader := http.MaxBytesReader(res, r, int64(h.MaxBodySize))
|
||||
bytes, err := ioutil.ReadAll(maxReader)
|
||||
bytes, err := io.ReadAll(maxReader)
|
||||
if err != nil {
|
||||
if err := tooLarge(res); err != nil {
|
||||
h.Log.Debugf("error in too-large: %v", err)
|
||||
|
|
@ -302,7 +302,7 @@ func (h *HTTPListenerV2) collectBody(res http.ResponseWriter, req *http.Request)
|
|||
return bytes, true
|
||||
case "snappy":
|
||||
defer req.Body.Close()
|
||||
bytes, err := ioutil.ReadAll(req.Body)
|
||||
bytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
h.Log.Debug(err.Error())
|
||||
if err := badRequest(res); err != nil {
|
||||
|
|
@ -322,7 +322,7 @@ func (h *HTTPListenerV2) collectBody(res http.ResponseWriter, req *http.Request)
|
|||
return bytes, true
|
||||
default:
|
||||
defer req.Body.Close()
|
||||
bytes, err := ioutil.ReadAll(req.Body)
|
||||
bytes, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
h.Log.Debug(err.Error())
|
||||
if err := badRequest(res); err != nil {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import (
|
|||
"bytes"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
|
@ -361,7 +361,7 @@ func TestWriteHTTPGzippedData(t *testing.T) {
|
|||
require.NoError(t, listener.Start(acc))
|
||||
defer listener.Stop()
|
||||
|
||||
data, err := ioutil.ReadFile("./testdata/testmsgs.gz")
|
||||
data, err := os.ReadFile("./testdata/testmsgs.gz")
|
||||
require.NoError(t, err)
|
||||
|
||||
req, err := http.NewRequest("POST", createURL(listener, "http", "/write", ""), bytes.NewBuffer(data))
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -277,7 +277,7 @@ func (h *HTTPResponse) httpGather(u string) (map[string]interface{}, map[string]
|
|||
}
|
||||
|
||||
if h.BearerToken != "" {
|
||||
token, err := ioutil.ReadFile(h.BearerToken)
|
||||
token, err := os.ReadFile(h.BearerToken)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
@ -339,7 +339,7 @@ func (h *HTTPResponse) httpGather(u string) (map[string]interface{}, map[string]
|
|||
if h.ResponseBodyMaxSize == 0 {
|
||||
h.ResponseBodyMaxSize = config.Size(defaultResponseBodyMaxSize)
|
||||
}
|
||||
bodyBytes, err := ioutil.ReadAll(io.LimitReader(resp.Body, int64(h.ResponseBodyMaxSize)+1))
|
||||
bodyBytes, err := io.ReadAll(io.LimitReader(resp.Body, int64(h.ResponseBodyMaxSize)+1))
|
||||
// Check first if the response body size exceeds the limit.
|
||||
if err == nil && int64(len(bodyBytes)) > int64(h.ResponseBodyMaxSize) {
|
||||
h.setBodyReadError("The body of the HTTP Response is too large", bodyBytes, fields, tags)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ package http_response
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -123,7 +123,7 @@ func setUpTestMux() http.Handler {
|
|||
fmt.Fprintf(w, "used post correctly!")
|
||||
})
|
||||
mux.HandleFunc("/musthaveabody", func(w http.ResponseWriter, req *http.Request) {
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
//nolint:errcheck,revive
|
||||
req.Body.Close()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package httpjson
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
|
@ -263,7 +263,7 @@ func (h *HTTPJSON) sendRequest(serverURL string) (string, float64, error) {
|
|||
defer resp.Body.Close()
|
||||
responseTime := time.Since(start).Seconds()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return string(body), responseTime, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package httpjson
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
|
|
@ -143,7 +143,7 @@ func (c *mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error)
|
|||
resp.StatusCode = 405 // Method not allowed
|
||||
}
|
||||
|
||||
resp.Body = ioutil.NopCloser(strings.NewReader(c.responseBody))
|
||||
resp.Body = io.NopCloser(strings.NewReader(c.responseBody))
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
|
@ -377,7 +377,7 @@ func TestHttpJsonPOST(t *testing.T) {
|
|||
"api_key": "mykey",
|
||||
}
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "api_key=mykey", string(body))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import (
|
|||
"bytes"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
|
@ -406,7 +406,7 @@ func TestWriteGzippedData(t *testing.T) {
|
|||
require.NoError(t, listener.Start(acc))
|
||||
defer listener.Stop()
|
||||
|
||||
data, err := ioutil.ReadFile("./testdata/testmsgs.gz")
|
||||
data, err := os.ReadFile("./testdata/testmsgs.gz")
|
||||
require.NoError(t, err)
|
||||
|
||||
req, err := http.NewRequest("POST", createURL(listener, "http", "/write", ""), bytes.NewBuffer(data))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
|
@ -256,7 +256,7 @@ func (h *InfluxDBV2Listener) handleWrite() http.HandlerFunc {
|
|||
var readErr error
|
||||
var bytes []byte
|
||||
//body = http.MaxBytesReader(res, req.Body, 1000000) //p.MaxBodySize.Size)
|
||||
bytes, readErr = ioutil.ReadAll(body)
|
||||
bytes, readErr = io.ReadAll(body)
|
||||
if readErr != nil {
|
||||
h.Log.Debugf("Error parsing the request body: %v", readErr.Error())
|
||||
if err := badRequest(res, InternalError, readErr.Error()); err != nil {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ import (
|
|||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
|
@ -363,7 +364,7 @@ func TestWriteGzippedData(t *testing.T) {
|
|||
require.NoError(t, listener.Start(acc))
|
||||
defer listener.Stop()
|
||||
|
||||
data, err := ioutil.ReadFile("./testdata/testmsgs.gz")
|
||||
data, err := os.ReadFile("./testdata/testmsgs.gz")
|
||||
require.NoError(t, err)
|
||||
|
||||
req, err := http.NewRequest("POST", createURL(listener, "http", "/api/v2/write", "bucket=mybucket"), bytes.NewBuffer(data))
|
||||
|
|
@ -485,7 +486,7 @@ func TestReady(t *testing.T) {
|
|||
resp, err := http.Get(createURL(listener, "http", "/api/v2/ready", ""))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "application/json", resp.Header["Content-Type"][0])
|
||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, string(bodyBytes), "\"status\":\"ready\"")
|
||||
require.NoError(t, resp.Body.Close())
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
|
@ -107,7 +106,7 @@ func (fs *fileServiceImpl) getStringsMatchingPatternOnPath(path string) ([]strin
|
|||
|
||||
// readFile reads file on path and return string content.
|
||||
func (fs *fileServiceImpl) readFile(path string) ([]byte, error) {
|
||||
out, err := ioutil.ReadFile(path)
|
||||
out, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return make([]byte, 0), err
|
||||
}
|
||||
|
|
@ -116,7 +115,7 @@ func (fs *fileServiceImpl) readFile(path string) ([]byte, error) {
|
|||
|
||||
// readFileToFloat64 reads file on path and tries to parse content to float64.
|
||||
func (fs *fileServiceImpl) readFileToFloat64(reader io.Reader) (float64, int64, error) {
|
||||
read, err := ioutil.ReadAll(reader)
|
||||
read, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
|
@ -153,7 +153,7 @@ func (j *Jolokia) doRequest(req *http.Request) ([]map[string]interface{}, error)
|
|||
}
|
||||
|
||||
// read body
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package jolokia
|
|||
|
||||
import (
|
||||
_ "fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -116,7 +116,7 @@ type jolokiaClientStub struct {
|
|||
func (c jolokiaClientStub) MakeRequest(_ *http.Request) (*http.Response, error) {
|
||||
resp := http.Response{}
|
||||
resp.StatusCode = c.statusCode
|
||||
resp.Body = ioutil.NopCloser(strings.NewReader(c.responseBody))
|
||||
resp.Body = io.NopCloser(strings.NewReader(c.responseBody))
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
|
@ -149,7 +149,7 @@ func (c *Client) read(requests []ReadRequest) ([]ReadResponse, error) {
|
|||
c.URL, resp.StatusCode, http.StatusText(resp.StatusCode), http.StatusOK, http.StatusText(http.StatusOK))
|
||||
}
|
||||
|
||||
responseBody, err := ioutil.ReadAll(resp.Body)
|
||||
responseBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package jolokia2
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
|
@ -20,7 +20,7 @@ func TestJolokia2_ClientAuthRequest(t *testing.T) {
|
|||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
username, password, _ = r.BasicAuth()
|
||||
|
||||
body, _ := ioutil.ReadAll(r.Body)
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
require.NoError(t, json.Unmarshal(body, &requests))
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
@ -56,7 +56,7 @@ func TestJolokia2_ClientProxyAuthRequest(t *testing.T) {
|
|||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
username, password, _ = r.BasicAuth()
|
||||
|
||||
body, _ := ioutil.ReadAll(r.Body)
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
require.NoError(t, json.Unmarshal(body, &requests))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err := fmt.Fprintf(w, "[]")
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ package kernel
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -41,7 +40,7 @@ func (k *Kernel) Gather(acc telegraf.Accumulator) error {
|
|||
return err
|
||||
}
|
||||
|
||||
entropyData, err := ioutil.ReadFile(k.entropyStatFile)
|
||||
entropyData, err := os.ReadFile(k.entropyStatFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -109,7 +108,7 @@ func (k *Kernel) getProcStat() ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(k.statFile)
|
||||
data, err := os.ReadFile(k.statFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package kernel
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -169,7 +168,7 @@ const entropyStatFilePartial = `1024`
|
|||
const entropyStatFileInvalid = ``
|
||||
|
||||
func makeFakeStatFile(t *testing.T, content []byte) string {
|
||||
tmpfile, err := ioutil.TempFile("", "kernel_test")
|
||||
tmpfile, err := os.CreateTemp("", "kernel_test")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = tmpfile.Write(content)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ package kernel_vmstat
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
|
|
@ -61,7 +60,7 @@ func (k *KernelVmstat) getProcVmstat() ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(k.statFile)
|
||||
data, err := os.ReadFile(k.statFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package kernel_vmstat
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -300,7 +299,7 @@ thp_collapse_alloc_failed 102214
|
|||
thp_split abcd`
|
||||
|
||||
func makeFakeVMStatFile(t *testing.T, content []byte) string {
|
||||
tmpfile, err := ioutil.TempFile("", "kernel_vmstat_test")
|
||||
tmpfile, err := os.CreateTemp("", "kernel_vmstat_test")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = tmpfile.Write(content)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -253,7 +252,7 @@ func (k *Kibana) gatherJSONData(url string, v interface{}) (host string, err err
|
|||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
// ignore the err here; LimitReader returns io.EOF and we're not interested in read errors.
|
||||
body, _ := ioutil.ReadAll(io.LimitReader(response.Body, 200))
|
||||
body, _ := io.ReadAll(io.LimitReader(response.Body, 200))
|
||||
return request.Host, fmt.Errorf("%s returned HTTP status %s: %q", url, response.Status, body)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package kibana
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -46,7 +46,7 @@ func (t *transportMock) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||
StatusCode: t.statusCode,
|
||||
}
|
||||
res.Header.Set("Content-Type", "application/json")
|
||||
res.Body = ioutil.NopCloser(strings.NewReader(t.body))
|
||||
res.Body = io.NopCloser(strings.NewReader(t.body))
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"compress/zlib"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"math/big"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -349,7 +349,7 @@ func processGzip(data []byte) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
defer zipData.Close()
|
||||
return ioutil.ReadAll(zipData)
|
||||
return io.ReadAll(zipData)
|
||||
}
|
||||
|
||||
func processZlib(data []byte) ([]byte, error) {
|
||||
|
|
@ -358,7 +358,7 @@ func processZlib(data []byte) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
defer zlibData.Close()
|
||||
return ioutil.ReadAll(zlibData)
|
||||
return io.ReadAll(zlibData)
|
||||
}
|
||||
|
||||
func processNoOp(data []byte) ([]byte, error) {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package kube_inventory
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -101,7 +101,7 @@ func (ki *KubernetesInventory) Init() error {
|
|||
}
|
||||
|
||||
if ki.BearerToken != "" {
|
||||
token, err := ioutil.ReadFile(ki.BearerToken)
|
||||
token, err := os.ReadFile(ki.BearerToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package kubernetes
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ func (k *Kubernetes) Init() error {
|
|||
}
|
||||
|
||||
if k.BearerToken != "" {
|
||||
token, err := ioutil.ReadFile(k.BearerToken)
|
||||
token, err := os.ReadFile(k.BearerToken)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package leofs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
|
@ -132,7 +131,7 @@ func testMain(t *testing.T, code string, endpoint string, serverType ServerType)
|
|||
|
||||
// Build the fake snmpwalk for test
|
||||
src := os.TempDir() + "/test.go"
|
||||
require.NoError(t, ioutil.WriteFile(src, []byte(code), 0600))
|
||||
require.NoError(t, os.WriteFile(src, []byte(code), 0600))
|
||||
defer os.Remove(src)
|
||||
|
||||
require.NoError(t, exec.Command("go", "build", "-o", executable, src).Run())
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package linux_sysctl_fs
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
|
|
@ -29,7 +28,7 @@ func (sfs SysctlFS) SampleConfig() string {
|
|||
}
|
||||
|
||||
func (sfs *SysctlFS) gatherList(file string, fields map[string]interface{}, fieldNames ...string) error {
|
||||
bs, err := ioutil.ReadFile(sfs.path + "/" + file)
|
||||
bs, err := os.ReadFile(sfs.path + "/" + file)
|
||||
if err != nil {
|
||||
// Ignore non-existing entries
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
|
|
@ -58,7 +57,7 @@ func (sfs *SysctlFS) gatherList(file string, fields map[string]interface{}, fiel
|
|||
}
|
||||
|
||||
func (sfs *SysctlFS) gatherOne(name string, fields map[string]interface{}) error {
|
||||
bs, err := ioutil.ReadFile(sfs.path + "/" + name)
|
||||
bs, err := os.ReadFile(sfs.path + "/" + name)
|
||||
if err != nil {
|
||||
// Ignore non-existing entries
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package linux_sysctl_fs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -10,16 +9,16 @@ import (
|
|||
)
|
||||
|
||||
func TestSysctlFSGather(t *testing.T) {
|
||||
td, err := ioutil.TempDir("", "")
|
||||
td, err := os.MkdirTemp("", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
require.NoError(t, ioutil.WriteFile(td+"/aio-nr", []byte("100\n"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(td+"/aio-max-nr", []byte("101\n"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(td+"/super-nr", []byte("102\n"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(td+"/super-max", []byte("103\n"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(td+"/file-nr", []byte("104\t0\t106\n"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(td+"/inode-state", []byte("107\t108\t109\t0\t0\t0\t0\n"), 0644))
|
||||
require.NoError(t, os.WriteFile(td+"/aio-nr", []byte("100\n"), 0644))
|
||||
require.NoError(t, os.WriteFile(td+"/aio-max-nr", []byte("101\n"), 0644))
|
||||
require.NoError(t, os.WriteFile(td+"/super-nr", []byte("102\n"), 0644))
|
||||
require.NoError(t, os.WriteFile(td+"/super-max", []byte("103\n"), 0644))
|
||||
require.NoError(t, os.WriteFile(td+"/file-nr", []byte("104\t0\t106\n"), 0644))
|
||||
require.NoError(t, os.WriteFile(td+"/inode-state", []byte("107\t108\t109\t0\t0\t0\t0\n"), 0644))
|
||||
|
||||
sfs := &SysctlFS{
|
||||
path: td,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package logparser
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
|
@ -111,7 +110,7 @@ func TestGrokParseLogFiles(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGrokParseLogFilesAppearLater(t *testing.T) {
|
||||
emptydir, err := ioutil.TempDir("", "TestGrokParseLogFilesAppearLater")
|
||||
emptydir, err := os.MkdirTemp("", "TestGrokParseLogFilesAppearLater")
|
||||
defer os.RemoveAll(emptydir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
@ -131,10 +130,10 @@ func TestGrokParseLogFilesAppearLater(t *testing.T) {
|
|||
|
||||
assert.Equal(t, acc.NFields(), 0)
|
||||
|
||||
input, err := ioutil.ReadFile(filepath.Join(testdataDir, "test_a.log"))
|
||||
input, err := os.ReadFile(filepath.Join(testdataDir, "test_a.log"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(emptydir, "test_a.log"), input, 0644)
|
||||
err = os.WriteFile(filepath.Join(emptydir, "test_a.log"), input, 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, acc.GatherError(logparser.Gather))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
|
@ -206,7 +205,7 @@ func (logstash *Logstash) gatherJSONData(url string, value interface{}) error {
|
|||
defer response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
// ignore the err here; LimitReader returns io.EOF and we're not interested in read errors.
|
||||
body, _ := ioutil.ReadAll(io.LimitReader(response.Body, 200))
|
||||
body, _ := io.ReadAll(io.LimitReader(response.Body, 200))
|
||||
return fmt.Errorf("%s returned HTTP status %s: %q", url, response.Status, body)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
package lustre2
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
|
@ -374,7 +374,7 @@ func (l *Lustre2) GetLustreProcStats(fileglob string, wantedFields []*mapping) e
|
|||
name := path[len(path)-2]
|
||||
|
||||
//lines, err := internal.ReadLines(file)
|
||||
wholeFile, err := ioutil.ReadFile(file)
|
||||
wholeFile, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package lustre2
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -149,13 +148,13 @@ func TestLustre2GeneratesMetrics(t *testing.T) {
|
|||
err = os.MkdirAll(obddir+"/"+ostName, 0755)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(mdtdir+"/"+ostName+"/md_stats", []byte(mdtProcContents), 0644)
|
||||
err = os.WriteFile(mdtdir+"/"+ostName+"/md_stats", []byte(mdtProcContents), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(osddir+"/"+ostName+"/stats", []byte(osdldiskfsProcContents), 0644)
|
||||
err = os.WriteFile(osddir+"/"+ostName+"/stats", []byte(osdldiskfsProcContents), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(obddir+"/"+ostName+"/stats", []byte(obdfilterProcContents), 0644)
|
||||
err = os.WriteFile(obddir+"/"+ostName+"/stats", []byte(obdfilterProcContents), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Begin by testing standard Lustre stats
|
||||
|
|
@ -218,10 +217,10 @@ func TestLustre2GeneratesJobstatsMetrics(t *testing.T) {
|
|||
err = os.MkdirAll(obddir+"/"+ostName, 0755)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(mdtdir+"/"+ostName+"/job_stats", []byte(mdtJobStatsContents), 0644)
|
||||
err = os.WriteFile(mdtdir+"/"+ostName+"/job_stats", []byte(mdtJobStatsContents), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(obddir+"/"+ostName+"/job_stats", []byte(obdfilterJobStatsContents), 0644)
|
||||
err = os.WriteFile(obddir+"/"+ostName+"/job_stats", []byte(obdfilterJobStatsContents), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test Lustre Jobstats
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -148,11 +147,11 @@ func runChimp(api *ChimpAPI, params ReportsParams) ([]byte, error) {
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
// ignore the err here; LimitReader returns io.EOF and we're not interested in read errors.
|
||||
body, _ := ioutil.ReadAll(io.LimitReader(resp.Body, 200))
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 200))
|
||||
return nil, fmt.Errorf("%s returned HTTP status %s: %q", api.url.String(), resp.Status, body)
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package mdstat
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
|
|
@ -291,7 +290,7 @@ func (k *MdstatConf) getProcMdstat() ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(mdStatFile)
|
||||
data, err := os.ReadFile(mdStatFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package mdstat
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -134,7 +133,7 @@ unused devices: <none>
|
|||
`
|
||||
|
||||
func makeFakeMDStatFile(content []byte) (filename string) {
|
||||
fileobj, err := ioutil.TempFile("", "mdstat")
|
||||
fileobj, err := os.CreateTemp("", "mdstat")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package mesos
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -558,7 +558,7 @@ func (m *Mesos) gatherMainMetrics(u *url.URL, role Role, acc telegraf.Accumulato
|
|||
return err
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
// Ignore the returned error to not shadow the initial one
|
||||
//nolint:errcheck,revive
|
||||
resp.Body.Close()
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package multifile
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
|
@ -84,7 +84,7 @@ func (m *MultiFile) Gather(acc telegraf.Accumulator) error {
|
|||
tags := make(map[string]string)
|
||||
|
||||
for _, file := range m.Files {
|
||||
fileContents, err := ioutil.ReadFile(file.Name)
|
||||
fileContents, err := os.ReadFile(file.Name)
|
||||
|
||||
if err != nil {
|
||||
if m.FailEarly {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ package nats
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
|
@ -56,7 +56,7 @@ func (n *Nats) Gather(acc telegraf.Accumulator) error {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bytes, err := ioutil.ReadAll(resp.Body)
|
||||
bytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ package neptuneapex
|
|||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
|
@ -276,7 +276,7 @@ func (n *NeptuneApex) sendRequest(server string) ([]byte, error) {
|
|||
url, resp.StatusCode, http.StatusText(resp.StatusCode),
|
||||
http.StatusOK, http.StatusText(http.StatusOK))
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read output from %q: %v", url, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -70,7 +70,7 @@ func (n *NginxPlusAPI) gatherURL(addr *url.URL, path string) ([]byte, error) {
|
|||
contentType := strings.Split(resp.Header.Get("Content-Type"), ";")[0]
|
||||
switch contentType {
|
||||
case "application/json":
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
|
@ -153,7 +152,7 @@ func (check *NginxUpstreamCheck) gatherJSONData(url string, value interface{}) e
|
|||
defer response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
// ignore the err here; LimitReader returns io.EOF and we're not interested in read errors.
|
||||
body, _ := ioutil.ReadAll(io.LimitReader(response.Body, 200))
|
||||
body, _ := io.ReadAll(io.LimitReader(response.Body, 200))
|
||||
return fmt.Errorf("%s returned HTTP status %s: %q", url, response.Status, body)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ package nsq
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
|
@ -131,7 +131,7 @@ func (n *NSQ) gatherEndpoint(e string, acc telegraf.Accumulator) error {
|
|||
return fmt.Errorf("%s returned HTTP status %s", u.String(), r.Status)
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf(`error reading body: %s`, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package nstat
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
|
|
@ -62,7 +61,7 @@ func (ns *Nstat) Gather(acc telegraf.Accumulator) error {
|
|||
// load paths, get from env if config values are empty
|
||||
ns.loadPaths()
|
||||
|
||||
netstat, err := ioutil.ReadFile(ns.ProcNetNetstat)
|
||||
netstat, err := os.ReadFile(ns.ProcNetNetstat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -71,14 +70,14 @@ func (ns *Nstat) Gather(acc telegraf.Accumulator) error {
|
|||
ns.gatherNetstat(netstat, acc)
|
||||
|
||||
// collect SNMP data
|
||||
snmp, err := ioutil.ReadFile(ns.ProcNetSNMP)
|
||||
snmp, err := os.ReadFile(ns.ProcNetSNMP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ns.gatherSNMP(snmp, acc)
|
||||
|
||||
// collect SNMP6 data, if SNMP6 directory exists (IPv6 enabled)
|
||||
snmp6, err := ioutil.ReadFile(ns.ProcNetSNMP6)
|
||||
snmp6, err := os.ReadFile(ns.ProcNetSNMP6)
|
||||
if err == nil {
|
||||
ns.gatherSNMP6(snmp6, acc)
|
||||
} else if !os.IsNotExist(err) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package nvidia_smi
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -139,7 +139,7 @@ func TestGatherValidXML(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
|
||||
octets, err := ioutil.ReadFile(filepath.Join("testdata", tt.filename))
|
||||
octets, err := os.ReadFile(filepath.Join("testdata", tt.filename))
|
||||
require.NoError(t, err)
|
||||
|
||||
err = gatherNvidiaSMI(octets, &acc)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"crypto/x509/pkix"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/big"
|
||||
"net"
|
||||
|
|
@ -27,7 +26,7 @@ import (
|
|||
// SELF SIGNED CERT FUNCTIONS
|
||||
|
||||
func newTempDir() (string, error) {
|
||||
dir, err := ioutil.TempDir("", "ssc")
|
||||
dir, err := os.MkdirTemp("", "ssc")
|
||||
return dir, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package passenger
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
|
@ -28,7 +27,7 @@ func fakePassengerStatus(stat string) (string, error) {
|
|||
}
|
||||
|
||||
tempFilePath := filepath.Join(os.TempDir(), "passenger-status"+fileExtension)
|
||||
if err := ioutil.WriteFile(tempFilePath, []byte(content), 0700); err != nil {
|
||||
if err := os.WriteFile(tempFilePath, []byte(content), 0700); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/cgi"
|
||||
|
|
@ -161,7 +160,7 @@ func (c *child) serve() {
|
|||
|
||||
var errCloseConn = errors.New("fcgi: connection should be closed")
|
||||
|
||||
var emptyBody = ioutil.NopCloser(strings.NewReader(""))
|
||||
var emptyBody = io.NopCloser(strings.NewReader(""))
|
||||
|
||||
// ErrRequestAborted is returned by Read when a handler attempts to read the
|
||||
// body of a request that has been aborted by the web server.
|
||||
|
|
@ -295,7 +294,7 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
|
|||
// can properly cut off the client sending all the data.
|
||||
// For now just bound it a little and
|
||||
//nolint:errcheck,revive
|
||||
io.CopyN(ioutil.Discard, body, 100<<20)
|
||||
io.CopyN(io.Discard, body, 100<<20)
|
||||
//nolint:errcheck,revive
|
||||
body.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -242,7 +241,7 @@ func TestChildServeCleansUp(t *testing.T) {
|
|||
r *http.Request,
|
||||
) {
|
||||
// block on reading body of request
|
||||
_, err := io.Copy(ioutil.Discard, r.Body)
|
||||
_, err := io.Copy(io.Discard, r.Body)
|
||||
if err != tt.err {
|
||||
t.Errorf("Expected %#v, got %#v", tt.err, err)
|
||||
}
|
||||
|
|
@ -274,7 +273,7 @@ func TestMalformedParams(_ *testing.T) {
|
|||
// end of params
|
||||
1, 4, 0, 1, 0, 0, 0, 0,
|
||||
}
|
||||
rw := rwNopCloser{bytes.NewReader(input), ioutil.Discard}
|
||||
rw := rwNopCloser{bytes.NewReader(input), io.Discard}
|
||||
c := newChild(rw, http.DefaultServeMux)
|
||||
c.serve()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package postfix
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
|
@ -15,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGather(t *testing.T) {
|
||||
td, err := ioutil.TempDir("", "")
|
||||
td, err := os.MkdirTemp("", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
|
|
@ -23,12 +22,12 @@ func TestGather(t *testing.T) {
|
|||
require.NoError(t, os.MkdirAll(filepath.FromSlash(td+"/"+q), 0755))
|
||||
}
|
||||
|
||||
require.NoError(t, ioutil.WriteFile(filepath.FromSlash(td+"/active/01"), []byte("abc"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.FromSlash(td+"/active/02"), []byte("defg"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.FromSlash(td+"/hold/01"), []byte("abc"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.FromSlash(td+"/incoming/01"), []byte("abcd"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.FromSlash(td+"/deferred/0/0/01"), []byte("abc"), 0644))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.FromSlash(td+"/deferred/F/F/F1"), []byte("abc"), 0644))
|
||||
require.NoError(t, os.WriteFile(filepath.FromSlash(td+"/active/01"), []byte("abc"), 0644))
|
||||
require.NoError(t, os.WriteFile(filepath.FromSlash(td+"/active/02"), []byte("defg"), 0644))
|
||||
require.NoError(t, os.WriteFile(filepath.FromSlash(td+"/hold/01"), []byte("abc"), 0644))
|
||||
require.NoError(t, os.WriteFile(filepath.FromSlash(td+"/incoming/01"), []byte("abcd"), 0644))
|
||||
require.NoError(t, os.WriteFile(filepath.FromSlash(td+"/deferred/0/0/01"), []byte("abc"), 0644))
|
||||
require.NoError(t, os.WriteFile(filepath.FromSlash(td+"/deferred/F/F/F1"), []byte("abc"), 0644))
|
||||
|
||||
p := Postfix{
|
||||
QueueDirectory: td,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package postgresql_extensible
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -147,7 +147,7 @@ func ReadQueryFromFile(filePath string) (string, error) {
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
query, err := ioutil.ReadAll(file)
|
||||
query, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ package processes
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
|
@ -192,7 +191,7 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
|
|||
}
|
||||
|
||||
func readProcFile(filename string) ([]byte, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package procstat
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -43,7 +43,7 @@ func (pg *NativeFinder) UID(user string) ([]PID, error) {
|
|||
//PidFile returns the pid from the pid file given.
|
||||
func (pg *NativeFinder) PidFile(path string) ([]PID, error) {
|
||||
var pids []PID
|
||||
pidString, err := ioutil.ReadFile(path)
|
||||
pidString, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return pids, fmt.Errorf("Failed to read pidfile '%s'. Error: '%s'",
|
||||
path, err)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package procstat
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -25,7 +25,7 @@ func NewPgrep() (PIDFinder, error) {
|
|||
|
||||
func (pg *Pgrep) PidFile(path string) ([]PID, error) {
|
||||
var pids []PID
|
||||
pidString, err := ioutil.ReadFile(path)
|
||||
pidString, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return pids, fmt.Errorf("Failed to read pidfile '%s'. Error: '%s'",
|
||||
path, err)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue