Skip to content

Commit

Permalink
Lint comments (prometheus#422)
Browse files Browse the repository at this point in the history
* Add `godot` linter to validate comments.
* Clenup a bunch of comments.
* Replace deprecated golint with revive.

Signed-off-by: SuperQ <superq@gmail.com>
  • Loading branch information
SuperQ committed Nov 25, 2021
1 parent d826259 commit 841d355
Show file tree
Hide file tree
Showing 44 changed files with 170 additions and 162 deletions.
10 changes: 9 additions & 1 deletion .golangci.yml
@@ -1,4 +1,12 @@
---
linters:
enable:
- golint
- godot
- revive

linter-settings:
godot:
capital: true
exclude:
# Ignore "See: URL"
- 'See:'
16 changes: 8 additions & 8 deletions arp.go
Expand Up @@ -21,19 +21,19 @@ import (
"strings"
)

// Learned from include/uapi/linux/if_arp.h
// Learned from include/uapi/linux/if_arp.h.
const (
// completed entry (ha valid)
// completed entry (ha valid).
ATFComplete = 0x02
// permanent entry
// permanent entry.
ATFPermanent = 0x04
// Publish entry
// Publish entry.
ATFPublish = 0x08
// Has requested trailers
// Has requested trailers.
ATFUseTrailers = 0x10
// Obsoleted: Want to use a netmask (only for proxy entries)
// Obsoleted: Want to use a netmask (only for proxy entries).
ATFNetmask = 0x20
// Don't answer this addresses
// Don't answer this addresses.
ATFDontPublish = 0x40
)

Expand Down Expand Up @@ -110,7 +110,7 @@ func parseARPEntry(columns []string) (ARPEntry, error) {
return entry, nil
}

// IsComplete returns true if ARP entry is marked with complete flag
// IsComplete returns true if ARP entry is marked with complete flag.
func (entry *ARPEntry) IsComplete() bool {
return entry.Flags&ATFComplete != 0
}
2 changes: 1 addition & 1 deletion bcache/bcache.go
Expand Up @@ -29,7 +29,7 @@ type Stats struct {
}

// BcacheStats contains statistics tied to a bcache ID.
type BcacheStats struct { // nolint:golint
type BcacheStats struct { // nolint:revive
AverageKeySize uint64
BtreeCacheSize uint64
CacheAvailablePercent uint64
Expand Down
4 changes: 2 additions & 2 deletions bcache/get.go
Expand Up @@ -51,8 +51,8 @@ func NewFS(mountPoint string) (FS, error) {
return FS{&fs}, nil
}

// Stats is a wrapper around stats()
// It returns full available statistics
// Stats is a wrapper around stats().
// It returns full available statistics.
func (fs FS) Stats() ([]*Stats, error) {
return fs.stats(true)
}
Expand Down
16 changes: 8 additions & 8 deletions blockdevice/stats.go
Expand Up @@ -25,17 +25,17 @@ import (
"github.com/prometheus/procfs/internal/fs"
)

// Info contains identifying information for a block device such as a disk drive
// Info contains identifying information for a block device such as a disk drive.
type Info struct {
MajorNumber uint32
MinorNumber uint32
DeviceName string
}

// IOStats models the iostats data described in the kernel documentation
// https://www.kernel.org/doc/Documentation/iostats.txt,
// https://www.kernel.org/doc/Documentation/block/stat.txt,
// and https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
// IOStats models the iostats data described in the kernel documentation.
// - https://www.kernel.org/doc/Documentation/iostats.txt,
// - https://www.kernel.org/doc/Documentation/block/stat.txt
// - https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
type IOStats struct {
// ReadIOs is the number of reads completed successfully.
ReadIOs uint64
Expand Down Expand Up @@ -76,7 +76,7 @@ type IOStats struct {
TimeSpentFlushing uint64
}

// Diskstats combines the device Info and IOStats
// Diskstats combines the device Info and IOStats.
type Diskstats struct {
Info
IOStats
Expand Down Expand Up @@ -220,7 +220,7 @@ func NewFS(procMountPoint string, sysMountPoint string) (FS, error) {
}

// ProcDiskstats reads the diskstats file and returns
// an array of Diskstats (one per line/device)
// an array of Diskstats (one per line/device).
func (fs FS) ProcDiskstats() ([]Diskstats, error) {
file, err := os.Open(fs.proc.Path(procDiskstatsPath))
if err != nil {
Expand Down Expand Up @@ -266,7 +266,7 @@ func (fs FS) ProcDiskstats() ([]Diskstats, error) {
return diskstats, scanner.Err()
}

// SysBlockDevices lists the device names from /sys/block/<dev>
// SysBlockDevices lists the device names from /sys/block/<dev>.
func (fs FS) SysBlockDevices() ([]string, error) {
deviceDirs, err := ioutil.ReadDir(fs.sys.Path(sysBlockPath))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions btrfs/get.go
Expand Up @@ -80,7 +80,7 @@ func (fs FS) Stats() ([]*Stats, error) {
return stats, nil
}

// GetStats collects all Btrfs statistics from sysfs
// GetStats collects all Btrfs statistics from sysfs.
func GetStats(uuidPath string) (*Stats, error) {
r := &reader{path: uuidPath}
s := r.readFilesystemStats()
Expand Down Expand Up @@ -162,7 +162,7 @@ func (r *reader) readAllocationStats(d string) (a *AllocationStats) {
return
}

// readLayouts reads all Btrfs layout statistics for the current path
// readLayouts reads all Btrfs layout statistics for the current path.
func (r *reader) readLayouts() map[string]*LayoutUsage {
files, err := ioutil.ReadDir(r.path)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cpuinfo.go
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/prometheus/procfs/internal/util"
)

// CPUInfo contains general information about a system CPU found in /proc/cpuinfo
// CPUInfo contains general information about a system CPU found in /proc/cpuinfo.
type CPUInfo struct {
Processor uint
VendorID string
Expand Down Expand Up @@ -469,7 +469,7 @@ func parseCPUInfoDummy(_ []byte) ([]CPUInfo, error) { // nolint:unused,deadcode
}

// firstNonEmptyLine advances the scanner to the first non-empty line
// and returns the contents of that line
// and returns the contents of that line.
func firstNonEmptyLine(scanner *bufio.Scanner) string {
for scanner.Scan() {
line := scanner.Text()
Expand Down
2 changes: 1 addition & 1 deletion internal/fs/fs.go
Expand Up @@ -26,7 +26,7 @@ const (
// DefaultSysMountPoint is the common mount point of the sys filesystem.
DefaultSysMountPoint = "/sys"

// DefaultConfigfsMountPoint is the common mount point of the configfs
// DefaultConfigfsMountPoint is the common mount point of the configfs.
DefaultConfigfsMountPoint = "/sys/kernel/config"
)

Expand Down
17 changes: 8 additions & 9 deletions iscsi/get.go
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/prometheus/procfs/internal/util"
)

// GetStats is the main iscsi status information func
// building the path and prepare info for enable iscsi
// GetStats is the main iscsi status information func for
// building the path and prepare info for enable iscsi.
func GetStats(iqnPath string) (*Stats, error) {
var istats Stats

Expand Down Expand Up @@ -58,8 +58,7 @@ func GetStats(iqnPath string) (*Stats, error) {
return &istats, nil
}

// isPathEnable is a utility function
// check if the file "enable" contain enable message
// isPathEnable checks if the file "enable" contain enable message.
func isPathEnable(path string) (bool, error) {
enableReadout, err := ioutil.ReadFile(filepath.Join(path, "enable"))
if err != nil {
Expand Down Expand Up @@ -104,7 +103,7 @@ func getLunLinkTarget(lunPath string) (lunObject LUN, err error) {
}

// ReadWriteOPS read and return the stat of read and write in megabytes,
// and total commands that send to the target
// and total commands that send to the target.
func ReadWriteOPS(iqnPath string, tpgt string, lun string) (readmb uint64,
writemb uint64, iops uint64, err error) {

Expand Down Expand Up @@ -133,7 +132,7 @@ func ReadWriteOPS(iqnPath string, tpgt string, lun string) (readmb uint64,
}

// GetFileioUdev is getting the actual info to build up
// the FILEIO data and match with the enable target
// the FILEIO data and match with the enable target.
func (fs FS) GetFileioUdev(fileioNumber string, objectName string) (*FILEIO, error) {
fileio := FILEIO{
Name: "fileio_" + fileioNumber,
Expand All @@ -155,7 +154,7 @@ func (fs FS) GetFileioUdev(fileioNumber string, objectName string) (*FILEIO, err
}

// GetIblockUdev is getting the actual info to build up
// the IBLOCK data and match with the enable target
// the IBLOCK data and match with the enable target.
func (fs FS) GetIblockUdev(iblockNumber string, objectName string) (*IBLOCK, error) {
iblock := IBLOCK{
Name: "iblock_" + iblockNumber,
Expand All @@ -177,7 +176,7 @@ func (fs FS) GetIblockUdev(iblockNumber string, objectName string) (*IBLOCK, err
}

// GetRBDMatch is getting the actual info to build up
// the RBD data and match with the enable target
// the RBD data and match with the enable target.
func (fs FS) GetRBDMatch(rbdNumber string, poolImage string) (*RBD, error) {
rbd := RBD{
Name: "rbd_" + rbdNumber,
Expand Down Expand Up @@ -222,7 +221,7 @@ func (fs FS) GetRBDMatch(rbdNumber string, poolImage string) (*RBD, error) {
return nil, nil
}

// GetRDMCPPath is getting the actual info to build up RDMCP data
// GetRDMCPPath is getting the actual info to build up RDMCP data.
func (fs FS) GetRDMCPPath(rdmcpNumber string, objectName string) (*RDMCP, error) {
rdmcp := RDMCP{
Name: "rd_mcp_" + rdmcpNumber,
Expand Down
30 changes: 14 additions & 16 deletions iscsi/iscsi.go
Expand Up @@ -23,21 +23,19 @@ import (

// iscsi target started with /sys/kernel/config/target/iscsi/iqn*
// configfs + target/iscsi/iqn*
// iqnGlob is representing all the possible IQN
// iqnGlob is representing all the possible IQN.
const iqnGlob = "target/iscsi/iqn*"

// targetCore static path /sys/kernel/config/target/core for node_exporter
// reading runtime status
// reading runtime status.
const targetCore = "target/core"

// devicePath static path /sys/devices/rbd/[0-9]* for rbd devices to
// read at runtime status
// read at runtime status.
const devicePath = "devices/rbd"

// FS represents the pseudo-filesystem configfs, which provides an interface to
// iscsi kernel data structures in
// sysfs as /sys
// configfs as /sys/kernel/config
// iscsi kernel data structures in sysfs as /sys and configfs as /sys/kernel/config.
type FS struct {
sysfs *fs.FS
configfs *fs.FS
Expand All @@ -46,7 +44,7 @@ type FS struct {
// NewFS returns a new configfs mounted under the given mount point. It will
// error and return empty FS if the mount point can't be read. For the ease of
// use, an empty string parameter configfsMountPoint will call internal fs for
// the default sys path as /sys/kernel/config
// the default sys path as /sys/kernel/config.
func NewFS(sysfsPath string, configfsMountPoint string) (FS, error) {
if strings.TrimSpace(sysfsPath) == "" {
sysfsPath = fs.DefaultSysMountPoint
Expand All @@ -65,12 +63,12 @@ func NewFS(sysfsPath string, configfsMountPoint string) (FS, error) {
return FS{&sysfs, &configfs}, nil
}

// helper function to get configfs path
// Path is a helper function to get configfs path.
func (fs FS) Path(p ...string) string {
return fs.configfs.Path(p...)
}

// ISCSIStats getting iscsi runtime information
// ISCSIStats getting iscsi runtime information.
func (fs FS) ISCSIStats() ([]*Stats, error) {
matches, err := filepath.Glob(fs.configfs.Path(iqnGlob))
if err != nil {
Expand All @@ -90,15 +88,15 @@ func (fs FS) ISCSIStats() ([]*Stats, error) {
return stats, nil
}

// TPGT struct for sys target portal group tag info
// TPGT struct for sys target portal group tag info.
type TPGT struct {
Name string // name of the tpgt group
TpgtPath string // file path of tpgt
IsEnable bool // is the tpgt enable
Luns []LUN // the Luns that tpgt has
}

// LUN struct for sys logical unit number info
// LUN struct for sys logical unit number info.
type LUN struct {
Name string // name of the lun
LunPath string // file path of the lun
Expand All @@ -107,37 +105,37 @@ type LUN struct {
TypeNumber string // place holder for number of the device
}

// FILEIO struct for backstore info
// FILEIO struct for backstore info.
type FILEIO struct {
Name string // name of the fileio
Fnumber string // number related to the backstore
ObjectName string // place holder for object in iscsi object
Filename string // link to the actual file being export
}

// IBLOCK struct for backstore info
// IBLOCK struct for backstore info.
type IBLOCK struct {
Name string // name of the iblock
Bnumber string // number related to the backstore
ObjectName string // place holder for object in iscsi object
Iblock string // link to the actual block being export
}

// RBD struct for backstore info
// RBD struct for backstore info.
type RBD struct {
Name string // name of the rbd
Rnumber string // number related to the backstore
Pool string // place holder for the rbd pool
Image string // place holder for the rbd image
}

// RDMCP struct for backstore info
// RDMCP struct for backstore info.
type RDMCP struct {
Name string // name of the rdm_cp
ObjectName string // place holder for object name
}

// Stats struct for all targets info
// Stats struct for all targets info.
type Stats struct {
Name string
Tpgt []TPGT
Expand Down
2 changes: 1 addition & 1 deletion loadavg.go
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/prometheus/procfs/internal/util"
)

// LoadAvg represents an entry in /proc/loadavg
// LoadAvg represents an entry in /proc/loadavg.
type LoadAvg struct {
Load1 float64
Load5 float64
Expand Down

0 comments on commit 841d355

Please sign in to comment.