Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
  • Loading branch information
aknuds1 committed Aug 8, 2022
1 parent 2fc3cf3 commit b7fbda4
Show file tree
Hide file tree
Showing 79 changed files with 293 additions and 316 deletions.
6 changes: 3 additions & 3 deletions cmd/mimir/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"crypto/sha256"
"flag"
"fmt"
"io/ioutil"
"io"
"math/rand"
"os"
"runtime"
Expand Down Expand Up @@ -219,7 +219,7 @@ func main() {
func parseConfigFileParameter(args []string) (configFile string, expandEnv bool) {
// ignore errors and any output here. Any flag errors will be reported by main flag.Parse() call.
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.SetOutput(ioutil.Discard)
fs.SetOutput(io.Discard)

// usage not used in these functions.
fs.StringVar(&configFile, configFileOption, "", "")
Expand All @@ -238,7 +238,7 @@ func parseConfigFileParameter(args []string) (configFile string, expandEnv bool)

// LoadConfig read YAML-formatted config from filename into cfg.
func LoadConfig(filename string, expandEnv bool, cfg *mimir.Config) error {
buf, err := ioutil.ReadFile(filename)
buf, err := os.ReadFile(filename)
if err != nil {
return errors.Wrap(err, "Error reading config file")
}
Expand Down
4 changes: 2 additions & 2 deletions integration/api_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package integration

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -74,7 +74,7 @@ func TestConfigAPIEndpoint(t *testing.T) {
require.NoError(t, err)

defer runutil.ExhaustCloseWithErrCapture(&err, res.Body, "config API response")
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
require.NoError(t, err)
require.Equal(t, http.StatusOK, res.StatusCode)

Expand Down
9 changes: 4 additions & 5 deletions integration/e2emimir/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -316,7 +315,7 @@ func (c *Client) GetPrometheusRules() ([]*ruler.RuleGroup, error) {
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -360,7 +359,7 @@ func (c *Client) GetRuleGroups() (map[string][]rulefmt.RuleGroup, error) {
defer res.Body.Close()
rgs := map[string][]rulefmt.RuleGroup{}

data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -494,7 +493,7 @@ func (c *Client) getRawPage(ctx context.Context, url string) ([]byte, error) {
}
defer resp.Body.Close()

content, err := ioutil.ReadAll(resp.Body)
content, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1010,7 +1009,7 @@ func (c *Client) DoGetBody(url string) (*http.Response, []byte, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions integration/querier_remote_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"math/rand"
"net/http"
"testing"
Expand Down Expand Up @@ -111,7 +110,7 @@ func TestQuerierRemoteRead(t *testing.T) {
require.NoError(t, err)
require.Equal(t, http.StatusOK, httpResp.StatusCode)

compressed, err = ioutil.ReadAll(httpResp.Body)
compressed, err = io.ReadAll(httpResp.Body)
require.NoError(t, err)

uncompressed, err := snappy.Decode(nil, compressed)
Expand Down
4 changes: 2 additions & 2 deletions integration/single_binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package integration

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestMimirCanParseIntZeroAsZeroDuration(t *testing.T) {
const singleProcessConfigFile = "docs/configurations/single-process-config-blocks.yaml"

// Use an example single process config file.
config, err := ioutil.ReadFile(filepath.Join(getMimirProjectDir(), singleProcessConfigFile))
config, err := os.ReadFile(filepath.Join(getMimirProjectDir(), singleProcessConfigFile))
require.NoError(t, err, "unable to read config file")

// Ensure that there's `server:` to replace in the config, otherwise we're testing nothing.
Expand Down
5 changes: 2 additions & 3 deletions integration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package integration

import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -49,14 +48,14 @@ func writeFileToSharedDir(s *e2e.Scenario, dst string, content []byte) error {
return err
}

return ioutil.WriteFile(
return os.WriteFile(
dst,
content,
os.ModePerm)
}

func copyFileToSharedDir(s *e2e.Scenario, src, dst string) error {
content, err := ioutil.ReadFile(filepath.Join(getMimirProjectDir(), src))
content, err := os.ReadFile(filepath.Join(getMimirProjectDir(), src))
if err != nil {
return errors.Wrapf(err, "unable to read local file %s", src)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/alertmanager/alertmanager_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package alertmanager

import (
"io/ioutil"
"io"
"net/http/httptest"
"testing"

Expand All @@ -27,7 +27,7 @@ func TestMultitenantAlertmanager_GetStatusHandler(t *testing.T) {

resp := w.Result()
require.Equal(t, 200, w.Code)
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
content := string(body)
require.Contains(t, content, "Alertmanager Status: Running")
}
4 changes: 2 additions & 2 deletions pkg/alertmanager/alertstore/bucketclient/bucket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package bucketclient
import (
"bytes"
"context"
"io/ioutil"
"io"
"strings"
"sync"

Expand Down Expand Up @@ -191,7 +191,7 @@ func (s *BucketAlertStore) get(ctx context.Context, bkt objstore.Bucket, name st

defer runutil.CloseWithLogOnErr(s.logger, readCloser, "close bucket reader")

buf, err := ioutil.ReadAll(readCloser)
buf, err := io.ReadAll(readCloser)
if err != nil {
return errors.Wrapf(err, "failed to read alertmanager config for user %s", name)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/alertmanager/alertstore/local/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package local
import (
"context"
"flag"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -146,7 +145,7 @@ func (f *Store) reloadConfigs() (map[string]alertspb.AlertConfigDesc, error) {
}

// Load the file to be returned by the store.
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return errors.Wrapf(err, "unable to read alertmanager config %s", path)
}
Expand Down
15 changes: 7 additions & 8 deletions pkg/alertmanager/alertstore/local/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package local
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -34,11 +33,11 @@ func TestStore_ListAllUsers(t *testing.T) {
{
user1Cfg := prepareAlertmanagerConfig("user-1")
user2Cfg := prepareAlertmanagerConfig("user-2")
require.NoError(t, ioutil.WriteFile(filepath.Join(storeDir, "user-1.yaml"), []byte(user1Cfg), os.ModePerm))
require.NoError(t, ioutil.WriteFile(filepath.Join(storeDir, "user-2.yaml"), []byte(user2Cfg), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(storeDir, "user-1.yaml"), []byte(user1Cfg), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(storeDir, "user-2.yaml"), []byte(user2Cfg), os.ModePerm))

// The following file is expected to be skipped.
require.NoError(t, ioutil.WriteFile(filepath.Join(storeDir, "user-3.unsupported-extension"), []byte{}, os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(storeDir, "user-3.unsupported-extension"), []byte{}, os.ModePerm))

users, err := store.ListAllUsers(ctx)
require.NoError(t, err)
Expand All @@ -60,8 +59,8 @@ func TestStore_GetAlertConfig(t *testing.T) {
{
user1Cfg := prepareAlertmanagerConfig("user-1")
user2Cfg := prepareAlertmanagerConfig("user-2")
require.NoError(t, ioutil.WriteFile(filepath.Join(storeDir, "user-1.yaml"), []byte(user1Cfg), os.ModePerm))
require.NoError(t, ioutil.WriteFile(filepath.Join(storeDir, "user-2.yaml"), []byte(user2Cfg), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(storeDir, "user-1.yaml"), []byte(user1Cfg), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(storeDir, "user-2.yaml"), []byte(user2Cfg), os.ModePerm))

config, err := store.GetAlertConfig(ctx, "user-1")
require.NoError(t, err)
Expand All @@ -87,7 +86,7 @@ func TestStore_GetAlertConfigs(t *testing.T) {
// The storage contains some configs.
{
user1Cfg := prepareAlertmanagerConfig("user-1")
require.NoError(t, ioutil.WriteFile(filepath.Join(storeDir, "user-1.yaml"), []byte(user1Cfg), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(storeDir, "user-1.yaml"), []byte(user1Cfg), os.ModePerm))

configs, err := store.GetAlertConfigs(ctx, []string{"user-1", "user-2"})
require.NoError(t, err)
Expand All @@ -97,7 +96,7 @@ func TestStore_GetAlertConfigs(t *testing.T) {

// Add another user config.
user2Cfg := prepareAlertmanagerConfig("user-2")
require.NoError(t, ioutil.WriteFile(filepath.Join(storeDir, "user-2.yaml"), []byte(user2Cfg), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(storeDir, "user-2.yaml"), []byte(user2Cfg), os.ModePerm))

configs, err = store.GetAlertConfigs(ctx, []string{"user-1", "user-2"})
require.NoError(t, err)
Expand Down
5 changes: 2 additions & 3 deletions pkg/alertmanager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -119,7 +118,7 @@ func (am *MultitenantAlertmanager) SetUserConfig(w http.ResponseWriter, r *http.
input = r.Body
}

payload, err := ioutil.ReadAll(input)
payload, err := io.ReadAll(input)
if err != nil {
level.Error(logger).Log("msg", errReadingConfiguration, "err", err.Error())
http.Error(w, fmt.Sprintf("%s: %s", errReadingConfiguration, err.Error()), http.StatusBadRequest)
Expand Down Expand Up @@ -231,7 +230,7 @@ func validateUserConfig(logger log.Logger, cfg alertspb.AlertConfigDesc, limits
// not to configured data dir, and on the flipside, it'll fail if we can't write
// to tmpDir. Ignoring both cases for now as they're ultra rare but will revisit if
// we see this in the wild.
userTempDir, err := ioutil.TempDir("", "validate-config-"+cfg.User)
userTempDir, err := os.MkdirTemp("", "validate-config-"+cfg.User)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/alertmanager/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -645,7 +645,7 @@ template_files:
am.SetUserConfig(w, req.WithContext(ctx))
resp := w.Result()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)

if tc.err == nil {
Expand Down Expand Up @@ -777,7 +777,7 @@ receivers:
resp := w.Result()
require.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, "application/yaml", resp.Header.Get("Content-Type"))
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)

expectedYaml := `user1:
Expand Down
6 changes: 3 additions & 3 deletions pkg/alertmanager/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package alertmanager
import (
"context"
"hash/fnv"
"io/ioutil"
"io"
"math/rand"
"net/http"
"path"
Expand Down Expand Up @@ -157,7 +157,7 @@ func (d *Distributor) doQuorum(userID string, w http.ResponseWriter, r *http.Req
var body []byte
var err error
if r.Body != nil {
body, err = ioutil.ReadAll(http.MaxBytesReader(w, r.Body, d.maxRecvMsgSize))
body, err = io.ReadAll(http.MaxBytesReader(w, r.Body, d.maxRecvMsgSize))
if err != nil {
if util.IsRequestBodyTooLarge(err) {
http.Error(w, "Request body too large", http.StatusRequestEntityTooLarge)
Expand Down Expand Up @@ -226,7 +226,7 @@ func (d *Distributor) doUnary(userID string, w http.ResponseWriter, r *http.Requ
return
}

body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, d.maxRecvMsgSize))
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, d.maxRecvMsgSize))
if err != nil {
if util.IsRequestBodyTooLarge(err) {
http.Error(w, "Request body too large", http.StatusRequestEntityTooLarge)
Expand Down
11 changes: 5 additions & 6 deletions pkg/alertmanager/multitenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -286,7 +285,7 @@ func NewMultitenantAlertmanager(cfg *MultitenantAlertmanagerConfig, store alerts

var fallbackConfig []byte
if cfg.FallbackConfigFile != "" {
fallbackConfig, err = ioutil.ReadFile(cfg.FallbackConfigFile)
fallbackConfig, err = os.ReadFile(cfg.FallbackConfigFile)
if err != nil {
return nil, fmt.Errorf("unable to read fallback config %q: %s", cfg.FallbackConfigFile, err)
}
Expand Down Expand Up @@ -634,7 +633,7 @@ func (am *MultitenantAlertmanager) setConfig(cfg alertspb.AlertConfigDesc) error
var pathsToRemove = make(map[string]struct{})

// List existing files to keep track the ones to be removed
if oldTemplateFiles, err := ioutil.ReadDir(userTemplateDir); err == nil {
if oldTemplateFiles, err := os.ReadDir(userTemplateDir); err == nil {
for _, file := range oldTemplateFiles {
pathsToRemove[filepath.Join(userTemplateDir, file.Name())] = struct{}{}
}
Expand Down Expand Up @@ -1066,7 +1065,7 @@ func (am *MultitenantAlertmanager) deleteUnusedLocalUserState() {
// getPerUserDirectories returns map of users to their directories (full path). Only users with local
// directory are returned.
func (am *MultitenantAlertmanager) getPerUserDirectories() map[string]string {
files, err := ioutil.ReadDir(am.cfg.DataDir)
files, err := os.ReadDir(am.cfg.DataDir)
if err != nil {
level.Warn(am.logger).Log("msg", "failed to list local dir", "dir", am.cfg.DataDir, "err", err)
return nil
Expand Down Expand Up @@ -1183,13 +1182,13 @@ func storeTemplateFile(templateFilepath, content string) (bool, error) {
}

// Check if the template file already exists and if it has changed
if tmpl, err := ioutil.ReadFile(templateFilepath); err == nil && string(tmpl) == content {
if tmpl, err := os.ReadFile(templateFilepath); err == nil && string(tmpl) == content {
return false, nil
} else if err != nil && !os.IsNotExist(err) {
return false, err
}

if err := ioutil.WriteFile(templateFilepath, []byte(content), 0644); err != nil {
if err := os.WriteFile(templateFilepath, []byte(content), 0644); err != nil {
return false, fmt.Errorf("unable to create Alertmanager template file %q: %s", templateFilepath, err)
}

Expand Down
Loading

0 comments on commit b7fbda4

Please sign in to comment.