Skip to content

Commit df1c424

Browse files
committed
metrics: rename SmbStatus --> SMBStatus
Style: follow Go language naming conventions and use 'SMBStatus'. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 02f7b49 commit df1c424

File tree

4 files changed

+77
-77
lines changed

4 files changed

+77
-77
lines changed

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ func main() {
3333

3434
log.Info("Self", "PodID", metrics.GetSelfPodID())
3535

36-
loc, err := metrics.LocateSmbStatus()
36+
loc, err := metrics.LocateSMBStatus()
3737
if err != nil {
3838
log.Error(err, "Failed to locate smbstatus")
3939
os.Exit(1)
4040
}
41-
ver, err := metrics.RunSmbStatusVersion()
41+
ver, err := metrics.RunSMBStatusVersion()
4242
if err != nil {
4343
log.Error(err, "Failed to run smbstatus")
4444
os.Exit(1)

internal/metrics/collectors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type smbSharesCollector struct {
8585

8686
func (col *smbSharesCollector) Collect(ch chan<- prometheus.Metric) {
8787
sharesTotal := 0
88-
sharesMap, _ := SmbStatusSharesByMachine()
88+
sharesMap, _ := SMBStatusSharesByMachine()
8989
for machine, share := range sharesMap {
9090
sharesCount := len(share)
9191
ch <- prometheus.MustNewConstMetric(col.dsc[0],
@@ -119,7 +119,7 @@ type smbLocksCollector struct {
119119
}
120120

121121
func (col *smbLocksCollector) Collect(ch chan<- prometheus.Metric) {
122-
locks, _ := RunSmbStatusLocks()
122+
locks, _ := RunSMBStatusLocks()
123123
ch <- prometheus.MustNewConstMetric(col.dsc[0],
124124
prometheus.GaugeValue, float64(len(locks)))
125125
}

internal/metrics/smbstatus.go

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,42 @@ import (
1010
"strings"
1111
)
1212

13-
// SmbStatusServerID represents a server_id output field
14-
type SmbStatusServerID struct {
13+
// SMBStatusServerID represents a server_id output field
14+
type SMBStatusServerID struct {
1515
PID string `json:"pid"`
1616
TaskID string `json:"task_id"`
1717
VNN string `json:"vnn"`
1818
UniqueID string `json:"unique_id"`
1919
}
2020

21-
// SmbStatusEncryption represents a encryption output field
22-
type SmbStatusEncryption struct {
21+
// SMBStatusEncryption represents a encryption output field
22+
type SMBStatusEncryption struct {
2323
Cipher string `json:"cipher"`
2424
Degree string `json:"degree"`
2525
}
2626

27-
// SmbStatusSigning represents a signing output field
28-
type SmbStatusSigning struct {
27+
// SMBStatusSigning represents a signing output field
28+
type SMBStatusSigning struct {
2929
Cipher string `json:"cipher"`
3030
Degree string `json:"degree"`
3131
}
3232

33-
// SmbStatusTreeCon represents a 'tcon' output field
34-
type SmbStatusTreeCon struct {
33+
// SMBStatusTreeCon represents a 'tcon' output field
34+
type SMBStatusTreeCon struct {
3535
Service string `json:"service"`
36-
ServerID SmbStatusServerID `json:"server_id"`
36+
ServerID SMBStatusServerID `json:"server_id"`
3737
TConID string `json:"tcon_id"`
3838
SessionID string `json:"session_id"`
3939
Machine string `json:"machine"`
4040
ConnectedAt string `json:"connected_at"`
41-
Encryption SmbStatusEncryption `json:"encryption"`
42-
Signing SmbStatusSigning `json:"signing"`
41+
Encryption SMBStatusEncryption `json:"encryption"`
42+
Signing SMBStatusSigning `json:"signing"`
4343
}
4444

45-
// SmbStatusSession represents a session output field
46-
type SmbStatusSession struct {
45+
// SMBStatusSession represents a session output field
46+
type SMBStatusSession struct {
4747
SessionID string `json:"session_id"`
48-
ServerID SmbStatusServerID `json:"server_id"`
48+
ServerID SMBStatusServerID `json:"server_id"`
4949
UID int `json:"uid"`
5050
GID int `json:"gid"`
5151
Username string `json:"username"`
@@ -57,45 +57,45 @@ type SmbStatusSession struct {
5757
Hostname string `json:"hostname"`
5858
SessionDialect string `json:"session_dialect"`
5959
ClientGUID string `json:"client_guid"`
60-
Encryption SmbStatusEncryption `json:"encryption"`
61-
Signing SmbStatusSigning `json:"signing"`
60+
Encryption SMBStatusEncryption `json:"encryption"`
61+
Signing SMBStatusSigning `json:"signing"`
6262
}
6363

64-
// SmbStatusFileID represents a fileid output field
65-
type SmbStatusFileID struct {
64+
// SMBStatusFileID represents a fileid output field
65+
type SMBStatusFileID struct {
6666
DevID int64 `json:"devid"`
6767
Inode int64 `json:"inode"`
6868
Extid int32 `json:"extid"`
6969
}
7070

71-
// SmbStatusLockedFile represents a locked-file output field
72-
type SmbStatusLockedFile struct {
71+
// SMBStatusLockedFile represents a locked-file output field
72+
type SMBStatusLockedFile struct {
7373
ServicePath string `json:"service_path"`
7474
Filename string `json:"filename"`
75-
FileID SmbStatusFileID `json:"fileid"`
75+
FileID SMBStatusFileID `json:"fileid"`
7676
NumPendingDeletes int `json:"num_pending_deletes"`
7777
}
7878

79-
// SmbStatus represents output of 'smbstatus --json'
80-
type SmbStatus struct {
79+
// SMBStatus represents output of 'smbstatus --json'
80+
type SMBStatus struct {
8181
Timestamp string `json:"timestamp"`
8282
Version string `json:"version"`
8383
SmbConf string `json:"smb_conf"`
84-
Sessions map[string]SmbStatusSession `json:"sessions"`
85-
TCons map[string]SmbStatusTreeCon `json:"tcons"`
86-
LockedFiles map[string]SmbStatusLockedFile `json:"locked_files"`
84+
Sessions map[string]SMBStatusSession `json:"sessions"`
85+
TCons map[string]SMBStatusTreeCon `json:"tcons"`
86+
LockedFiles map[string]SMBStatusLockedFile `json:"locked_files"`
8787
}
8888

89-
// SmbStatusLocks represents output of 'smbstatus -L --json'
90-
type SmbStatusLocks struct {
89+
// SMBStatusLocks represents output of 'smbstatus -L --json'
90+
type SMBStatusLocks struct {
9191
Timestamp string `json:"timestamp"`
9292
Version string `json:"version"`
9393
SmbConf string `json:"smb_conf"`
94-
OpenFiles map[string]SmbStatusLockedFile `json:"open_files"`
94+
OpenFiles map[string]SMBStatusLockedFile `json:"open_files"`
9595
}
9696

97-
// LocateSmbStatus finds the local executable of 'smbstatus' on host.
98-
func LocateSmbStatus() (string, error) {
97+
// LocateSMBStatus finds the local executable of 'smbstatus' on host.
98+
func LocateSMBStatus() (string, error) {
9999
knowns := []string{
100100
"/usr/bin/smbstatus",
101101
}
@@ -115,27 +115,27 @@ func LocateSmbStatus() (string, error) {
115115
return "", errors.New("failed to locate smbstatus")
116116
}
117117

118-
// RunSmbStatusVersion executes 'smbstatus --version' on host container
119-
func RunSmbStatusVersion() (string, error) {
120-
ver, err := executeSmbStatusCommand("--version")
118+
// RunSMBStatusVersion executes 'smbstatus --version' on host container
119+
func RunSMBStatusVersion() (string, error) {
120+
ver, err := executeSMBStatusCommand("--version")
121121
if err != nil {
122122
return "", err
123123
}
124124
return ver, nil
125125
}
126126

127-
// RunSmbStatusShares executes 'smbstatus --shares --json' on host
128-
func RunSmbStatusShares() ([]SmbStatusTreeCon, error) {
129-
dat, err := executeSmbStatusCommand("--shares --json")
127+
// RunSMBStatusShares executes 'smbstatus --shares --json' on host
128+
func RunSMBStatusShares() ([]SMBStatusTreeCon, error) {
129+
dat, err := executeSMBStatusCommand("--shares --json")
130130
if err != nil {
131-
return []SmbStatusTreeCon{}, err
131+
return []SMBStatusTreeCon{}, err
132132
}
133-
return parseSmbStatusTreeCons(dat)
133+
return parseSMBStatusTreeCons(dat)
134134
}
135135

136-
func parseSmbStatusTreeCons(dat string) ([]SmbStatusTreeCon, error) {
137-
tcons := []SmbStatusTreeCon{}
138-
res, err := parseSmbStatus(dat)
136+
func parseSMBStatusTreeCons(dat string) ([]SMBStatusTreeCon, error) {
137+
tcons := []SMBStatusTreeCon{}
138+
res, err := parseSMBStatus(dat)
139139
if err != nil {
140140
return tcons, err
141141
}
@@ -145,18 +145,18 @@ func parseSmbStatusTreeCons(dat string) ([]SmbStatusTreeCon, error) {
145145
return tcons, nil
146146
}
147147

148-
// RunSmbStatusLocks executes 'smbstatus --locks --json' on host
149-
func RunSmbStatusLocks() ([]SmbStatusLockedFile, error) {
150-
dat, err := executeSmbStatusCommand("--locks --json")
148+
// RunSMBStatusLocks executes 'smbstatus --locks --json' on host
149+
func RunSMBStatusLocks() ([]SMBStatusLockedFile, error) {
150+
dat, err := executeSMBStatusCommand("--locks --json")
151151
if err != nil {
152-
return []SmbStatusLockedFile{}, err
152+
return []SMBStatusLockedFile{}, err
153153
}
154-
return parseSmbStatusLockedFiles(dat)
154+
return parseSMBStatusLockedFiles(dat)
155155
}
156156

157-
func parseSmbStatusLockedFiles(dat string) ([]SmbStatusLockedFile, error) {
158-
lockedFiles := []SmbStatusLockedFile{}
159-
res, err := parseSmbStatusLocks(dat)
157+
func parseSMBStatusLockedFiles(dat string) ([]SMBStatusLockedFile, error) {
158+
lockedFiles := []SMBStatusLockedFile{}
159+
res, err := parseSMBStatusLocks(dat)
160160
if err != nil {
161161
return lockedFiles, err
162162
}
@@ -166,26 +166,26 @@ func parseSmbStatusLockedFiles(dat string) ([]SmbStatusLockedFile, error) {
166166
return lockedFiles, nil
167167
}
168168

169-
// SmbStatusSharesByMachine converts the output of RunSmbStatusShares into map
169+
// SMBStatusSharesByMachine converts the output of RunSMBStatusShares into map
170170
// indexed by machine's host
171-
func SmbStatusSharesByMachine() (map[string][]SmbStatusTreeCon, error) {
172-
tcons, err := RunSmbStatusShares()
171+
func SMBStatusSharesByMachine() (map[string][]SMBStatusTreeCon, error) {
172+
tcons, err := RunSMBStatusShares()
173173
if err != nil {
174-
return map[string][]SmbStatusTreeCon{}, err
174+
return map[string][]SMBStatusTreeCon{}, err
175175
}
176176
return makeSmbSharesMap(tcons), nil
177177
}
178178

179-
func makeSmbSharesMap(tcons []SmbStatusTreeCon) map[string][]SmbStatusTreeCon {
180-
ret := map[string][]SmbStatusTreeCon{}
179+
func makeSmbSharesMap(tcons []SMBStatusTreeCon) map[string][]SMBStatusTreeCon {
180+
ret := map[string][]SMBStatusTreeCon{}
181181
for _, share := range tcons {
182182
ret[share.Machine] = append(ret[share.Machine], share)
183183
}
184184
return ret
185185
}
186186

187-
func executeSmbStatusCommand(args ...string) (string, error) {
188-
loc, err := LocateSmbStatus()
187+
func executeSMBStatusCommand(args ...string) (string, error) {
188+
loc, err := LocateSMBStatus()
189189
if err != nil {
190190
return "", err
191191
}
@@ -202,18 +202,18 @@ func executeCommand(command string, arg ...string) (string, error) {
202202
return res, nil
203203
}
204204

205-
// parseSmbStatus parses to output of 'smbstatus --json' into internal
205+
// parseSMBStatus parses to output of 'smbstatus --json' into internal
206206
// representation.
207-
func parseSmbStatus(data string) (*SmbStatus, error) {
208-
res := SmbStatus{}
207+
func parseSMBStatus(data string) (*SMBStatus, error) {
208+
res := SMBStatus{}
209209
err := json.Unmarshal([]byte(data), &res)
210210
return &res, err
211211
}
212212

213-
// parseSmbStatusLocks parses to output of 'smbstatus --locks --json' into
213+
// parseSMBStatusLocks parses to output of 'smbstatus --locks --json' into
214214
// internal representation.
215-
func parseSmbStatusLocks(data string) (*SmbStatusLocks, error) {
216-
res := SmbStatusLocks{}
215+
func parseSMBStatusLocks(data string) (*SMBStatusLocks, error) {
216+
res := SMBStatusLocks{}
217217
err := json.Unmarshal([]byte(data), &res)
218218
return &res, err
219219
}

internal/metrics/smbstatus_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,16 +553,16 @@ var (
553553

554554
//revive:enable line-length-limit
555555

556-
func TestParseSmbStatusTCons(t *testing.T) {
557-
dat, err := parseSmbStatus(smbstatusOutput1)
556+
func TestParseSMBStatusTCons(t *testing.T) {
557+
dat, err := parseSMBStatus(smbstatusOutput1)
558558
assert.NoError(t, err)
559559
assert.Equal(t, len(dat.TCons), 2)
560560

561-
dat, err = parseSmbStatus(smbstatusOutput2)
561+
dat, err = parseSMBStatus(smbstatusOutput2)
562562
assert.NoError(t, err)
563563
assert.Equal(t, len(dat.TCons), 1)
564564

565-
shares, err := parseSmbStatusTreeCons(smbstatusOutput2)
565+
shares, err := parseSMBStatusTreeCons(smbstatusOutput2)
566566
assert.NoError(t, err)
567567
assert.Equal(t, len(shares), 1)
568568
share1 := shares[0]
@@ -579,20 +579,20 @@ func TestParseSmbStatusTCons(t *testing.T) {
579579
}
580580
}
581581

582-
func TestParseSmbStatusAll(t *testing.T) {
583-
dat, err := parseSmbStatus(smbstatusOutput3)
582+
func TestParseSMBStatusAll(t *testing.T) {
583+
dat, err := parseSMBStatus(smbstatusOutput3)
584584
assert.NoError(t, err)
585585
assert.Equal(t, len(dat.Sessions), 1)
586586
assert.Equal(t, len(dat.TCons), 1)
587587
assert.Equal(t, len(dat.LockedFiles), 1)
588588

589-
dat2, err := parseSmbStatus(smbstatusOutput4)
589+
dat2, err := parseSMBStatus(smbstatusOutput4)
590590
assert.NoError(t, err)
591591
assert.Equal(t, len(dat2.LockedFiles), 2)
592592
}
593593

594-
func TestParseSmbStatusLocks(t *testing.T) {
595-
locks, err := parseSmbStatusLockedFiles(smbstatusLocksOutput)
594+
func TestParseSMBStatusLocks(t *testing.T) {
595+
locks, err := parseSMBStatusLockedFiles(smbstatusLocksOutput)
596596
assert.NoError(t, err)
597597
assert.Equal(t, len(locks), 2)
598598
lock1 := locks[0]

0 commit comments

Comments
 (0)