Skip to content

Commit

Permalink
Linter fixes for plugins/inputs/[de]* (#9379)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9a79491)
  • Loading branch information
zak-pawel authored and reimda committed Jul 7, 2021
1 parent ed412d7 commit 8331fd8
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ linters-settings:
- name: error-return
- name: error-strings
- name: errorf
- name: flag-parameter
# - name: flag-parameter #disable for now
- name: function-result-limit
arguments: [ 3 ]
- name: identical-branches
Expand Down
34 changes: 17 additions & 17 deletions plugins/inputs/dcos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (c *ClusterClient) Login(ctx context.Context, sa *ServiceAccount) (*AuthTok
return nil, err
}

loc := c.url("/acs/api/v1/auth/login")
loc := c.toURL("/acs/api/v1/auth/login")
req, err := http.NewRequest("POST", loc, bytes.NewBuffer(octets))
if err != nil {
return nil, err
Expand Down Expand Up @@ -208,7 +208,7 @@ func (c *ClusterClient) Login(ctx context.Context, sa *ServiceAccount) (*AuthTok

func (c *ClusterClient) GetSummary(ctx context.Context) (*Summary, error) {
summary := &Summary{}
err := c.doGet(ctx, c.url("/mesos/master/state-summary"), summary)
err := c.doGet(ctx, c.toURL("/mesos/master/state-summary"), summary)
if err != nil {
return nil, err
}
Expand All @@ -220,7 +220,7 @@ func (c *ClusterClient) GetContainers(ctx context.Context, node string) ([]Conta
list := []string{}

path := fmt.Sprintf("/system/v1/agent/%s/metrics/v0/containers", node)
err := c.doGet(ctx, c.url(path), &list)
err := c.doGet(ctx, c.toURL(path), &list)
if err != nil {
return nil, err
}
Expand All @@ -233,10 +233,10 @@ func (c *ClusterClient) GetContainers(ctx context.Context, node string) ([]Conta
return containers, nil
}

func (c *ClusterClient) getMetrics(ctx context.Context, url string) (*Metrics, error) {
func (c *ClusterClient) getMetrics(ctx context.Context, address string) (*Metrics, error) {
metrics := &Metrics{}

err := c.doGet(ctx, url, metrics)
err := c.doGet(ctx, address, metrics)
if err != nil {
return nil, err
}
Expand All @@ -246,21 +246,21 @@ func (c *ClusterClient) getMetrics(ctx context.Context, url string) (*Metrics, e

func (c *ClusterClient) GetNodeMetrics(ctx context.Context, node string) (*Metrics, error) {
path := fmt.Sprintf("/system/v1/agent/%s/metrics/v0/node", node)
return c.getMetrics(ctx, c.url(path))
return c.getMetrics(ctx, c.toURL(path))
}

func (c *ClusterClient) GetContainerMetrics(ctx context.Context, node, container string) (*Metrics, error) {
path := fmt.Sprintf("/system/v1/agent/%s/metrics/v0/containers/%s", node, container)
return c.getMetrics(ctx, c.url(path))
return c.getMetrics(ctx, c.toURL(path))
}

func (c *ClusterClient) GetAppMetrics(ctx context.Context, node, container string) (*Metrics, error) {
path := fmt.Sprintf("/system/v1/agent/%s/metrics/v0/containers/%s/app", node, container)
return c.getMetrics(ctx, c.url(path))
return c.getMetrics(ctx, c.toURL(path))
}

func createGetRequest(url string, token string) (*http.Request, error) {
req, err := http.NewRequest("GET", url, nil)
func createGetRequest(address string, token string) (*http.Request, error) {
req, err := http.NewRequest("GET", address, nil)
if err != nil {
return nil, err
}
Expand All @@ -273,8 +273,8 @@ func createGetRequest(url string, token string) (*http.Request, error) {
return req, nil
}

func (c *ClusterClient) doGet(ctx context.Context, url string, v interface{}) error {
req, err := createGetRequest(url, c.token)
func (c *ClusterClient) doGet(ctx context.Context, address string, v interface{}) error {
req, err := createGetRequest(address, c.token)
if err != nil {
return err
}
Expand Down Expand Up @@ -304,7 +304,7 @@ func (c *ClusterClient) doGet(ctx context.Context, url string, v interface{}) er

if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return &APIError{
URL: url,
URL: address,
StatusCode: resp.StatusCode,
Title: resp.Status,
}
Expand All @@ -318,10 +318,10 @@ func (c *ClusterClient) doGet(ctx context.Context, url string, v interface{}) er
return err
}

func (c *ClusterClient) url(path string) string {
url := *c.clusterURL
url.Path = path
return url.String()
func (c *ClusterClient) toURL(path string) string {
clusterURL := *c.clusterURL
clusterURL.Path = path
return clusterURL.String()
}

func (c *ClusterClient) createLoginToken(sa *ServiceAccount) (string, error) {
Expand Down
5 changes: 3 additions & 2 deletions plugins/inputs/dcos/dcos.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

jwt "github.com/dgrijalva/jwt-go/v4"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/filter"
Expand Down Expand Up @@ -352,13 +353,13 @@ func (d *DCOS) createClient() (Client, error) {
return nil, err
}

url, err := url.Parse(d.ClusterURL)
address, err := url.Parse(d.ClusterURL)
if err != nil {
return nil, err
}

client := NewClusterClient(
url,
address,
time.Duration(d.ResponseTimeout),
d.MaxConnections,
tlsCfg,
Expand Down
22 changes: 10 additions & 12 deletions plugins/inputs/directory_monitor/directory_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ package directory_monitor

import (
"bufio"
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"sync"
"time"

"golang.org/x/sync/semaphore"
"gopkg.in/djherbis/times.v1"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/parsers"
"github.com/influxdata/telegraf/plugins/parsers/csv"
"github.com/influxdata/telegraf/selfstat"
"golang.org/x/sync/semaphore"
"gopkg.in/djherbis/times.v1"

"compress/gzip"
"io"
"io/ioutil"
"os"
"path/filepath"
"sync"
)

const sampleConfig = `
Expand Down Expand Up @@ -263,9 +263,7 @@ func (monitor *DirectoryMonitor) parseFile(parser parsers.Parser, reader io.Read
if err != nil {
return err
}
if firstLine {
firstLine = false
}
firstLine = false

if err := monitor.sendMetrics(metrics); err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions plugins/inputs/directory_monitor/directory_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/plugins/parsers"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)

func TestCSVGZImport(t *testing.T) {
Expand Down Expand Up @@ -77,8 +78,9 @@ func TestCSVGZImport(t *testing.T) {

// File should have gone back to the test directory, as we configured.
_, err = os.Stat(filepath.Join(finishedDirectory, testCsvFile))
_, err = os.Stat(filepath.Join(finishedDirectory, testCsvGzFile))
require.NoError(t, err)

_, err = os.Stat(filepath.Join(finishedDirectory, testCsvGzFile))
require.NoError(t, err)
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type DiskStats struct {
ps system.PS

// Legacy support
Mountpoints []string `toml:"mountpoints"`
LegacyMountPoints []string `toml:"mountpoints"`

MountPoints []string `toml:"mount_points"`
IgnoreFS []string `toml:"ignore_fs"`
Expand All @@ -38,8 +38,8 @@ func (ds *DiskStats) SampleConfig() string {

func (ds *DiskStats) Gather(acc telegraf.Accumulator) error {
// Legacy support:
if len(ds.Mountpoints) != 0 {
ds.MountPoints = ds.Mountpoints
if len(ds.LegacyMountPoints) != 0 {
ds.MountPoints = ds.LegacyMountPoints
}

disks, partitions, err := ds.ps.DiskUsage(ds.MountPoints, ds.IgnoreFS)
Expand Down
Loading

0 comments on commit 8331fd8

Please sign in to comment.