diff --git a/api/prometheus/v1/api_test.go b/api/prometheus/v1/api_test.go index 9fbd29be1..009035db5 100644 --- a/api/prometheus/v1/api_test.go +++ b/api/prometheus/v1/api_test.go @@ -17,7 +17,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "io" "math" "net/http" "net/http/httptest" @@ -1680,7 +1680,7 @@ func (c *httpTestClient) Do(ctx context.Context, req *http.Request) (*http.Respo var body []byte done := make(chan struct{}) go func() { - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) close(done) }() diff --git a/prometheus/process_collector.go b/prometheus/process_collector.go index 5bfe0ff5b..1245428a7 100644 --- a/prometheus/process_collector.go +++ b/prometheus/process_collector.go @@ -16,7 +16,6 @@ package prometheus import ( "errors" "fmt" - "io/ioutil" "os" "strconv" "strings" @@ -152,7 +151,7 @@ func (c *processCollector) reportError(ch chan<- Metric, desc *Desc, err error) // It is meant to be used for the PidFn field in ProcessCollectorOpts. func NewPidFileFn(pidFilePath string) func() (int, error) { return func() (int, error) { - content, err := ioutil.ReadFile(pidFilePath) + content, err := os.ReadFile(pidFilePath) if err != nil { return 0, fmt.Errorf("can't read pid file %q: %+v", pidFilePath, err) } diff --git a/prometheus/push/push.go b/prometheus/push/push.go index 9d03d8bec..06dee376e 100644 --- a/prometheus/push/push.go +++ b/prometheus/push/push.go @@ -40,7 +40,7 @@ import ( "encoding/base64" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -245,7 +245,7 @@ func (p *Pusher) Delete() error { } defer resp.Body.Close() if resp.StatusCode != http.StatusAccepted { - body, _ := ioutil.ReadAll(resp.Body) // Ignore any further error as this is for an error message only. + body, _ := io.ReadAll(resp.Body) // Ignore any further error as this is for an error message only. return fmt.Errorf("unexpected status code %d while deleting %s: %s", resp.StatusCode, p.fullURL(), body) } return nil @@ -297,7 +297,7 @@ func (p *Pusher) push(ctx context.Context, method string) error { defer resp.Body.Close() // Depending on version and configuration of the PGW, StatusOK or StatusAccepted may be returned. if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted { - body, _ := ioutil.ReadAll(resp.Body) // Ignore any further error as this is for an error message only. + body, _ := io.ReadAll(resp.Body) // Ignore any further error as this is for an error message only. return fmt.Errorf("unexpected status code %d while pushing to %s: %s", resp.StatusCode, p.fullURL(), body) } return nil diff --git a/prometheus/push/push_test.go b/prometheus/push/push_test.go index 3367a4b56..a0e8e9a28 100644 --- a/prometheus/push/push_test.go +++ b/prometheus/push/push_test.go @@ -15,7 +15,7 @@ package push import ( "bytes" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -38,7 +38,7 @@ func TestPush(t *testing.T) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { lastMethod = r.Method var err error - lastBody, err = ioutil.ReadAll(r.Body) + lastBody, err = io.ReadAll(r.Body) if err != nil { t.Fatal(err) } diff --git a/prometheus/registry.go b/prometheus/registry.go index eda2892ed..36fd64ec5 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -16,7 +16,6 @@ package prometheus import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "runtime" @@ -563,7 +562,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) { // This is intended for use with the textfile collector of the node exporter. // Note that the node exporter expects the filename to be suffixed with ".prom". func WriteToTextfile(filename string, g Gatherer) error { - tmp, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename)) + tmp, err := os.CreateTemp(filepath.Dir(filename), filepath.Base(filename)) if err != nil { return err } diff --git a/prometheus/registry_test.go b/prometheus/registry_test.go index 0a3d746f9..9443ef3d0 100644 --- a/prometheus/registry_test.go +++ b/prometheus/registry_test.go @@ -23,7 +23,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "math/rand" "net/http" "net/http/httptest" @@ -1066,7 +1065,7 @@ test_summary_count{name="foo"} 2 gauge.With(prometheus.Labels{"name": "baz"}).Set(1.1) counter.With(prometheus.Labels{"name": "qux"}).Inc() - tmpfile, err := ioutil.TempFile("", "prom_registry_test") + tmpfile, err := os.CreateTemp("", "prom_registry_test") if err != nil { t.Fatal(err) } @@ -1076,7 +1075,7 @@ test_summary_count{name="foo"} 2 t.Fatal(err) } - fileBytes, err := ioutil.ReadFile(tmpfile.Name()) + fileBytes, err := os.ReadFile(tmpfile.Name()) if err != nil { t.Fatal(err) }