Skip to content

Commit fd17889

Browse files
committed
lint & static checks fixes
1 parent 867002b commit fd17889

File tree

5 files changed

+207
-202
lines changed

5 files changed

+207
-202
lines changed

accounts.go

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
1616
package main
1717

1818
import (
19-
"io/ioutil"
20-
"os/exec"
21-
"log"
22-
"strings"
23-
"strconv"
24-
"regexp"
25-
"github.com/prometheus/client_golang/prometheus"
19+
"io/ioutil"
20+
"log"
21+
"os/exec"
22+
"regexp"
23+
"strconv"
24+
"strings"
25+
26+
"github.com/prometheus/client_golang/prometheus"
2627
)
2728

2829
func AccountsData() []byte {
29-
cmd := exec.Command("squeue","-a","-r","-h","-o %A|%a|%T|%C")
30-
stdout, err := cmd.StdoutPipe()
30+
cmd := exec.Command("squeue", "-a", "-r", "-h", "-o %A|%a|%T|%C")
31+
stdout, err := cmd.StdoutPipe()
3132
if err != nil {
3233
log.Fatal(err)
3334
}
@@ -42,80 +43,80 @@ func AccountsData() []byte {
4243
}
4344

4445
type JobMetrics struct {
45-
pending float64
46-
running float64
47-
running_cpus float64
48-
suspended float64
46+
pending float64
47+
running float64
48+
running_cpus float64
49+
suspended float64
4950
}
5051

5152
func ParseAccountsMetrics(input []byte) map[string]*JobMetrics {
52-
accounts := make(map[string]*JobMetrics)
53-
lines := strings.Split(string(input), "\n")
54-
for _, line := range lines {
55-
if strings.Contains(line,"|") {
56-
account := strings.Split(line,"|")[1]
57-
_,key := accounts[account]
58-
if !key {
59-
accounts[account] = &JobMetrics{0,0,0,0}
60-
}
61-
state := strings.Split(line,"|")[2]
62-
state = strings.ToLower(state)
63-
cpus,_ := strconv.ParseFloat(strings.Split(line,"|")[3],64)
64-
pending := regexp.MustCompile(`^pending`)
65-
running := regexp.MustCompile(`^running`)
66-
suspended := regexp.MustCompile(`^suspended`)
67-
switch {
68-
case pending.MatchString(state) == true:
69-
accounts[account].pending++
70-
case running.MatchString(state) == true:
71-
accounts[account].running++
72-
accounts[account].running_cpus += cpus
73-
case suspended.MatchString(state) == true:
74-
accounts[account].suspended++
75-
}
76-
}
77-
}
78-
return accounts
53+
accounts := make(map[string]*JobMetrics)
54+
lines := strings.Split(string(input), "\n")
55+
for _, line := range lines {
56+
if strings.Contains(line, "|") {
57+
account := strings.Split(line, "|")[1]
58+
_, key := accounts[account]
59+
if !key {
60+
accounts[account] = &JobMetrics{0, 0, 0, 0}
61+
}
62+
state := strings.Split(line, "|")[2]
63+
state = strings.ToLower(state)
64+
cpus, _ := strconv.ParseFloat(strings.Split(line, "|")[3], 64)
65+
pending := regexp.MustCompile(`^pending`)
66+
running := regexp.MustCompile(`^running`)
67+
suspended := regexp.MustCompile(`^suspended`)
68+
switch {
69+
case pending.MatchString(state):
70+
accounts[account].pending++
71+
case running.MatchString(state):
72+
accounts[account].running++
73+
accounts[account].running_cpus += cpus
74+
case suspended.MatchString(state):
75+
accounts[account].suspended++
76+
}
77+
}
78+
}
79+
return accounts
7980
}
8081

8182
type AccountsCollector struct {
82-
pending *prometheus.Desc
83-
running *prometheus.Desc
84-
running_cpus *prometheus.Desc
85-
suspended *prometheus.Desc
83+
pending *prometheus.Desc
84+
running *prometheus.Desc
85+
running_cpus *prometheus.Desc
86+
suspended *prometheus.Desc
8687
}
8788

8889
func NewAccountsCollector() *AccountsCollector {
89-
labels := []string{"account"}
90-
return &AccountsCollector{
91-
pending: prometheus.NewDesc("slurm_account_jobs_pending", "Pending jobs for account", labels, nil),
92-
running: prometheus.NewDesc("slurm_account_jobs_running", "Running jobs for account", labels, nil),
93-
running_cpus: prometheus.NewDesc("slurm_account_cpus_running", "Running cpus for account", labels, nil),
94-
suspended: prometheus.NewDesc("slurm_account_jobs_suspended", "Suspended jobs for account", labels, nil),
95-
}
90+
labels := []string{"account"}
91+
return &AccountsCollector{
92+
pending: prometheus.NewDesc("slurm_account_jobs_pending", "Pending jobs for account", labels, nil),
93+
running: prometheus.NewDesc("slurm_account_jobs_running", "Running jobs for account", labels, nil),
94+
running_cpus: prometheus.NewDesc("slurm_account_cpus_running", "Running cpus for account", labels, nil),
95+
suspended: prometheus.NewDesc("slurm_account_jobs_suspended", "Suspended jobs for account", labels, nil),
96+
}
9697
}
9798

9899
func (ac *AccountsCollector) Describe(ch chan<- *prometheus.Desc) {
99-
ch <- ac.pending
100-
ch <- ac.running
101-
ch <- ac.running_cpus
102-
ch <- ac.suspended
100+
ch <- ac.pending
101+
ch <- ac.running
102+
ch <- ac.running_cpus
103+
ch <- ac.suspended
103104
}
104105

105106
func (ac *AccountsCollector) Collect(ch chan<- prometheus.Metric) {
106-
am := ParseAccountsMetrics(AccountsData())
107-
for a := range am {
108-
if am[a].pending > 0 {
109-
ch <- prometheus.MustNewConstMetric(ac.pending, prometheus.GaugeValue, am[a].pending, a)
110-
}
111-
if am[a].running > 0 {
112-
ch <- prometheus.MustNewConstMetric(ac.running, prometheus.GaugeValue, am[a].running, a)
113-
}
114-
if am[a].running_cpus > 0 {
115-
ch <- prometheus.MustNewConstMetric(ac.running_cpus, prometheus.GaugeValue, am[a].running_cpus, a)
116-
}
117-
if am[a].suspended > 0 {
118-
ch <- prometheus.MustNewConstMetric(ac.suspended, prometheus.GaugeValue, am[a].suspended, a)
119-
}
120-
}
107+
am := ParseAccountsMetrics(AccountsData())
108+
for a := range am {
109+
if am[a].pending > 0 {
110+
ch <- prometheus.MustNewConstMetric(ac.pending, prometheus.GaugeValue, am[a].pending, a)
111+
}
112+
if am[a].running > 0 {
113+
ch <- prometheus.MustNewConstMetric(ac.running, prometheus.GaugeValue, am[a].running, a)
114+
}
115+
if am[a].running_cpus > 0 {
116+
ch <- prometheus.MustNewConstMetric(ac.running_cpus, prometheus.GaugeValue, am[a].running_cpus, a)
117+
}
118+
if am[a].suspended > 0 {
119+
ch <- prometheus.MustNewConstMetric(ac.suspended, prometheus.GaugeValue, am[a].suspended, a)
120+
}
121+
}
121122
}

nodes.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
1616
package main
1717

1818
import (
19-
"github.com/prometheus/client_golang/prometheus"
20-
"github.com/prometheus/common/log"
2119
"io/ioutil"
2220
"os/exec"
2321
"regexp"
2422
"sort"
2523
"strconv"
2624
"strings"
25+
26+
"github.com/prometheus/client_golang/prometheus"
27+
"github.com/prometheus/common/log"
2728
)
2829

2930
type NodesMetrics struct {
@@ -62,6 +63,7 @@ func RemoveDuplicates(s []string) []string {
6263
}
6364

6465
func InitFeatureSet(nm *NodesMetrics, feature_set string) {
66+
//lint:file-ignore SA4018 If the feature set exists keep, else assign nil
6567
nm.alloc[feature_set] = nm.alloc[feature_set]
6668
nm.comp[feature_set] = nm.comp[feature_set]
6769
nm.down[feature_set] = nm.down[feature_set]
@@ -98,10 +100,10 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {
98100

99101
for _, line := range lines_uniq {
100102
if strings.Contains(line, "|") {
101-
split := strings.Split(line, "|")
102-
state := split[1]
103-
count, _ := strconv.ParseFloat(strings.TrimSpace(split[0]), 64)
104-
features := strings.Split(split[2], ",")
103+
split := strings.Split(line, "|")
104+
state := split[1]
105+
count, _ := strconv.ParseFloat(strings.TrimSpace(split[0]), 64)
106+
features := strings.Split(split[2], ",")
105107
sort.Strings(features)
106108
feature_set = strings.Join(features[:], ",")
107109
if feature_set == "(null)" {
@@ -119,25 +121,25 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {
119121
mix := regexp.MustCompile(`^mix`)
120122
resv := regexp.MustCompile(`^res`)
121123
switch {
122-
case alloc.MatchString(state) == true:
124+
case alloc.MatchString(state):
123125
nm.alloc[feature_set] += count
124-
case comp.MatchString(state) == true:
126+
case comp.MatchString(state):
125127
nm.comp[feature_set] += count
126-
case down.MatchString(state) == true:
128+
case down.MatchString(state):
127129
nm.down[feature_set] += count
128-
case drain.MatchString(state) == true:
130+
case drain.MatchString(state):
129131
nm.drain[feature_set] += count
130-
case fail.MatchString(state) == true:
132+
case fail.MatchString(state):
131133
nm.fail[feature_set] += count
132-
case err.MatchString(state) == true:
134+
case err.MatchString(state):
133135
nm.err[feature_set] += count
134-
case idle.MatchString(state) == true:
136+
case idle.MatchString(state):
135137
nm.idle[feature_set] += count
136-
case maint.MatchString(state) == true:
138+
case maint.MatchString(state):
137139
nm.maint[feature_set] += count
138-
case mix.MatchString(state) == true:
140+
case mix.MatchString(state):
139141
nm.mix[feature_set] += count
140-
case resv.MatchString(state) == true:
142+
case resv.MatchString(state):
141143
nm.resv[feature_set] += count
142144
}
143145
}

queue.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
1616
package main
1717

1818
import (
19-
"github.com/prometheus/client_golang/prometheus"
2019
"io/ioutil"
2120
"log"
2221
"os/exec"
2322
"strconv"
2423
"strings"
24+
25+
"github.com/prometheus/client_golang/prometheus"
2526
)
2627

2728
type NNVal map[string]map[string]map[string]float64
@@ -68,9 +69,9 @@ func (s *NVal) Incr(user string, part string, count float64) {
6869
}
6970

7071
func (s *NNVal) Incr2(reason string, user string, part string, count float64) {
71-
child, ok := (*s)[reason]
72+
_, ok := (*s)[reason]
7273
if !ok {
73-
child = map[string]map[string]float64{}
74+
child := map[string]map[string]float64{}
7475
(*s)[reason] = child
7576
}
7677
child2, ok := (*s)[reason][user]

0 commit comments

Comments
 (0)