Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revive fixes - part 3 #8872

Merged
merged 5 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 5 additions & 5 deletions plugins/inputs/bind/json_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type jsonMemory struct {
ContextSize int64
Lost int64
Contexts []struct {
Id string
ID string
Name string
Total int64
InUse int64
Expand Down Expand Up @@ -113,7 +113,7 @@ func (b *Bind) addStatsJSON(stats jsonStats, acc telegraf.Accumulator, urlTag st
// Detailed, per-context memory stats
if b.GatherMemoryContexts {
for _, c := range stats.Memory.Contexts {
tags := map[string]string{"url": urlTag, "id": c.Id, "name": c.Name, "source": host, "port": port}
tags := map[string]string{"url": urlTag, "id": c.ID, "name": c.Name, "source": host, "port": port}
fields := map[string]interface{}{"total": c.Total, "in_use": c.InUse}

acc.AddGauge("bind_memory_context", fields, tags)
Expand Down Expand Up @@ -153,17 +153,17 @@ func (b *Bind) readStatsJSON(addr *url.URL, acc telegraf.Accumulator) error {

// Progressively build up full jsonStats struct by parsing the individual HTTP responses
for _, suffix := range [...]string{"/server", "/net", "/mem"} {
scrapeUrl := addr.String() + suffix
scrapeURL := addr.String() + suffix

resp, err := b.client.Get(scrapeUrl)
resp, err := b.client.Get(scrapeURL)
if err != nil {
return err
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("%s returned HTTP status: %s", scrapeUrl, resp.Status)
return fmt.Errorf("%s returned HTTP status: %s", scrapeURL, resp.Status)
}

if err := json.NewDecoder(resp.Body).Decode(&stats); err != nil {
Expand Down
Loading