Skip to content

Commit

Permalink
Revive fixes - part 3 (#8872)
Browse files Browse the repository at this point in the history
* * Revive fixes regarding following set of rules: [rule.var-naming]
  • Loading branch information
zak-pawel authored Mar 1, 2021
1 parent 4584d69 commit 8a6907a
Show file tree
Hide file tree
Showing 154 changed files with 1,361 additions and 1,340 deletions.
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,38 @@ linters-settings:
- name: redefines-builtin-id

run:
# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
- scripts
- docs
- etc

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- plugins/parsers/influx/machine.go*

issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude:
- don't use an underscore in package name
- exported.*should have comment.*or be unexported
- comment on exported.*should be of the form

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
52 changes: 26 additions & 26 deletions plugins/aggregators/basicstats/basicstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ type BasicStats struct {
}

type configuredStats struct {
count bool
min bool
max bool
mean bool
variance bool
stdev bool
sum bool
diff bool
non_negative_diff bool
rate bool
non_negative_rate bool
interval bool
count bool
min bool
max bool
mean bool
variance bool
stdev bool
sum bool
diff bool
nonNegativeDiff bool
rate bool
nonNegativeRate bool
interval bool
}

func NewBasicStats() *BasicStats {
Expand Down Expand Up @@ -197,13 +197,13 @@ func (b *BasicStats) Push(acc telegraf.Accumulator) {
if b.statsConfig.diff {
fields[k+"_diff"] = v.diff
}
if b.statsConfig.non_negative_diff && v.diff >= 0 {
if b.statsConfig.nonNegativeDiff && v.diff >= 0 {
fields[k+"_non_negative_diff"] = v.diff
}
if b.statsConfig.rate {
fields[k+"_rate"] = v.rate
}
if b.statsConfig.non_negative_rate && v.diff >= 0 {
if b.statsConfig.nonNegativeRate && v.diff >= 0 {
fields[k+"_non_negative_rate"] = v.rate
}
if b.statsConfig.interval {
Expand Down Expand Up @@ -242,11 +242,11 @@ func (b *BasicStats) parseStats() *configuredStats {
case "diff":
parsed.diff = true
case "non_negative_diff":
parsed.non_negative_diff = true
parsed.nonNegativeDiff = true
case "rate":
parsed.rate = true
case "non_negative_rate":
parsed.non_negative_rate = true
parsed.nonNegativeRate = true
case "interval":
parsed.interval = true
default:
Expand All @@ -260,16 +260,16 @@ func (b *BasicStats) parseStats() *configuredStats {
func (b *BasicStats) getConfiguredStats() {
if b.Stats == nil {
b.statsConfig = &configuredStats{
count: true,
min: true,
max: true,
mean: true,
variance: true,
stdev: true,
sum: false,
non_negative_diff: false,
rate: false,
non_negative_rate: false,
count: true,
min: true,
max: true,
mean: true,
variance: true,
stdev: true,
sum: false,
nonNegativeDiff: false,
rate: false,
nonNegativeRate: false,
}
} else {
b.statsConfig = b.parseStats()
Expand Down
12 changes: 6 additions & 6 deletions plugins/inputs/activemq/activemq.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ type Subscribers struct {

type Subscriber struct {
XMLName xml.Name `xml:"subscriber"`
ClientId string `xml:"clientId,attr"`
ClientID string `xml:"clientId,attr"`
SubscriptionName string `xml:"subscriptionName,attr"`
ConnectionId string `xml:"connectionId,attr"`
ConnectionID string `xml:"connectionId,attr"`
DestinationName string `xml:"destinationName,attr"`
Selector string `xml:"selector,attr"`
Active string `xml:"active,attr"`
Expand Down Expand Up @@ -117,7 +117,7 @@ func (a *ActiveMQ) SampleConfig() string {
return sampleConfig
}

func (a *ActiveMQ) createHttpClient() (*http.Client, error) {
func (a *ActiveMQ) createHTTPClient() (*http.Client, error) {
tlsCfg, err := a.ClientConfig.TLSConfig()
if err != nil {
return nil, err
Expand Down Expand Up @@ -157,7 +157,7 @@ func (a *ActiveMQ) Init() error {

a.baseURL = u

a.client, err = a.createHttpClient()
a.client, err = a.createHTTPClient()
if err != nil {
return err
}
Expand Down Expand Up @@ -228,9 +228,9 @@ func (a *ActiveMQ) GatherSubscribersMetrics(acc telegraf.Accumulator, subscriber
records := make(map[string]interface{})
tags := make(map[string]string)

tags["client_id"] = subscriber.ClientId
tags["client_id"] = subscriber.ClientID
tags["subscription_name"] = subscriber.SubscriptionName
tags["connection_id"] = subscriber.ConnectionId
tags["connection_id"] = subscriber.ConnectionID
tags["destination_name"] = subscriber.DestinationName
tags["selector"] = subscriber.Selector
tags["active"] = subscriber.Active
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/apache/apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (n *Apache) Gather(acc telegraf.Accumulator) error {
}

if n.client == nil {
client, err := n.createHttpClient()
client, err := n.createHTTPClient()
if err != nil {
return err
}
Expand All @@ -84,15 +84,15 @@ func (n *Apache) Gather(acc telegraf.Accumulator) error {
wg.Add(1)
go func(addr *url.URL) {
defer wg.Done()
acc.AddError(n.gatherUrl(addr, acc))
acc.AddError(n.gatherURL(addr, acc))
}(addr)
}

wg.Wait()
return nil
}

func (n *Apache) createHttpClient() (*http.Client, error) {
func (n *Apache) createHTTPClient() (*http.Client, error) {
tlsCfg, err := n.ClientConfig.TLSConfig()
if err != nil {
return nil, err
Expand All @@ -108,7 +108,7 @@ func (n *Apache) createHttpClient() (*http.Client, error) {
return client, nil
}

func (n *Apache) gatherUrl(addr *url.URL, acc telegraf.Accumulator) error {
func (n *Apache) gatherURL(addr *url.URL, acc telegraf.Accumulator) error {
req, err := http.NewRequest("GET", addr.String(), nil)
if err != nil {
return fmt.Errorf("error on new request to %s : %s", addr.String(), err)
Expand Down
62 changes: 31 additions & 31 deletions plugins/inputs/bcache/bcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ import (
)

const (
dirty_data = "1.5G"
bypassed = "4.7T"
cache_bypass_hits = "146155333"
cache_bypass_misses = "0"
cache_hit_ratio = "90"
cache_hits = "511469583"
cache_miss_collisions = "157567"
cache_misses = "50616331"
cache_readaheads = "2"
dirtyData = "1.5G"
bypassed = "4.7T"
cacheBypassHits = "146155333"
cacheBypassMisses = "0"
cacheHitRatio = "90"
cacheHits = "511469583"
cacheMissCollisions = "157567"
cacheMisses = "50616331"
cacheReadaheads = "2"
)

var (
testBcachePath = os.TempDir() + "/telegraf/sys/fs/bcache"
testBcacheUuidPath = testBcachePath + "/663955a3-765a-4737-a9fd-8250a7a78411"
testBcacheUUIDPath = testBcachePath + "/663955a3-765a-4737-a9fd-8250a7a78411"
testBcacheDevPath = os.TempDir() + "/telegraf/sys/devices/virtual/block/bcache0"
testBcacheBackingDevPath = os.TempDir() + "/telegraf/sys/devices/virtual/block/md10"
)

func TestBcacheGeneratesMetrics(t *testing.T) {
err := os.MkdirAll(testBcacheUuidPath, 0755)
err := os.MkdirAll(testBcacheUUIDPath, 0755)
require.NoError(t, err)

err = os.MkdirAll(testBcacheDevPath, 0755)
Expand All @@ -40,49 +40,49 @@ func TestBcacheGeneratesMetrics(t *testing.T) {
err = os.MkdirAll(testBcacheBackingDevPath+"/bcache", 0755)
require.NoError(t, err)

err = os.Symlink(testBcacheBackingDevPath+"/bcache", testBcacheUuidPath+"/bdev0")
err = os.Symlink(testBcacheBackingDevPath+"/bcache", testBcacheUUIDPath+"/bdev0")
require.NoError(t, err)

err = os.Symlink(testBcacheDevPath, testBcacheUuidPath+"/bdev0/dev")
err = os.Symlink(testBcacheDevPath, testBcacheUUIDPath+"/bdev0/dev")
require.NoError(t, err)

err = os.MkdirAll(testBcacheUuidPath+"/bdev0/stats_total", 0755)
err = os.MkdirAll(testBcacheUUIDPath+"/bdev0/stats_total", 0755)
require.NoError(t, err)

err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/dirty_data",
[]byte(dirty_data), 0644)
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/dirty_data",
[]byte(dirtyData), 0644)
require.NoError(t, err)

err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/bypassed",
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/bypassed",
[]byte(bypassed), 0644)
require.NoError(t, err)

err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_bypass_hits",
[]byte(cache_bypass_hits), 0644)
err = ioutil.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",
[]byte(cache_bypass_misses), 0644)
err = ioutil.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",
[]byte(cache_hit_ratio), 0644)
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_hit_ratio",
[]byte(cacheHitRatio), 0644)
require.NoError(t, err)

err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_hits",
[]byte(cache_hits), 0644)
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_hits",
[]byte(cacheHits), 0644)
require.NoError(t, err)

err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_miss_collisions",
[]byte(cache_miss_collisions), 0644)
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_miss_collisions",
[]byte(cacheMissCollisions), 0644)
require.NoError(t, err)

err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_misses",
[]byte(cache_misses), 0644)
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_misses",
[]byte(cacheMisses), 0644)
require.NoError(t, err)

err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_readaheads",
[]byte(cache_readaheads), 0644)
err = ioutil.WriteFile(testBcacheUUIDPath+"/bdev0/stats_total/cache_readaheads",
[]byte(cacheReadaheads), 0644)
require.NoError(t, err)

fields := map[string]interface{}{
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/beanstalkd/beanstalkd.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (b *Beanstalkd) gatherServerStats(connection *textproto.Conn, acc telegraf.
},
map[string]string{
"hostname": stats.Hostname,
"id": stats.Id,
"id": stats.ID,
"server": b.Server,
"version": stats.Version,
},
Expand Down Expand Up @@ -169,13 +169,13 @@ func (b *Beanstalkd) gatherTubeStats(connection *textproto.Conn, tube string, ac
}

func runQuery(connection *textproto.Conn, cmd string, result interface{}) error {
requestId, err := connection.Cmd(cmd)
requestID, err := connection.Cmd(cmd)
if err != nil {
return err
}

connection.StartResponse(requestId)
defer connection.EndResponse(requestId)
connection.StartResponse(requestID)
defer connection.EndResponse(requestID)

status, err := connection.ReadLine()
if err != nil {
Expand Down Expand Up @@ -240,7 +240,7 @@ type statsResponse struct {
CurrentWaiting int `yaml:"current-waiting"`
CurrentWorkers int `yaml:"current-workers"`
Hostname string `yaml:"hostname"`
Id string `yaml:"id"`
ID string `yaml:"id"`
JobTimeouts int `yaml:"job-timeouts"`
MaxJobSize int `yaml:"max-job-size"`
Pid int `yaml:"pid"`
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ func (beat *Beat) Gather(accumulator telegraf.Accumulator) error {
beatStats := &BeatStats{}
beatInfo := &BeatInfo{}

infoUrl, err := url.Parse(beat.URL + suffixInfo)
infoURL, err := url.Parse(beat.URL + suffixInfo)
if err != nil {
return err
}
statsUrl, err := url.Parse(beat.URL + suffixStats)
statsURL, err := url.Parse(beat.URL + suffixStats)
if err != nil {
return err
}

err = beat.gatherJSONData(infoUrl.String(), beatInfo)
err = beat.gatherJSONData(infoURL.String(), beatInfo)
if err != nil {
return err
}
Expand All @@ -191,7 +191,7 @@ func (beat *Beat) Gather(accumulator telegraf.Accumulator) error {
"beat_version": beatInfo.Version,
}

err = beat.gatherJSONData(statsUrl.String(), beatStats)
err = beat.gatherJSONData(statsURL.String(), beatStats)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ func (b *Bind) Gather(acc telegraf.Accumulator) error {
wg.Add(1)
go func(addr *url.URL) {
defer wg.Done()
acc.AddError(b.gatherUrl(addr, acc))
acc.AddError(b.gatherURL(addr, acc))
}(addr)
}

wg.Wait()
return nil
}

func (b *Bind) gatherUrl(addr *url.URL, acc telegraf.Accumulator) error {
func (b *Bind) gatherURL(addr *url.URL, acc telegraf.Accumulator) error {
switch addr.Path {
case "":
// BIND 9.6 - 9.8
Expand Down
Loading

0 comments on commit 8a6907a

Please sign in to comment.