Fix staticcheck warnings on linux

Signed-off-by: binjip978 <pdp.eleven11@gmail.com>
This commit is contained in:
binjip978 2022-04-09 05:36:59 +00:00
parent 6a5a238da3
commit e5f384dfe6
5 changed files with 4 additions and 14 deletions

View file

@ -48,7 +48,7 @@ func bytesToString(byteArray []byte) string {
var metricNameRegex = regexp.MustCompile(`_*[^0-9A-Za-z_]+_*`) var metricNameRegex = regexp.MustCompile(`_*[^0-9A-Za-z_]+_*`)
// Sanitize the given metric name by replacing invalid characters by underscores. // SanitizeMetricName sanitize the given metric name by replacing invalid characters by underscores.
// //
// OpenMetrics and the Prometheus exposition format require the metric name // OpenMetrics and the Prometheus exposition format require the metric name
// to consist only of alphanumericals and "_", ":" and they must not start // to consist only of alphanumericals and "_", ":" and they must not start

View file

@ -49,7 +49,7 @@ func (c *lnstatCollector) Update(ch chan<- prometheus.Metric) error {
netStats, err := fs.NetStat() netStats, err := fs.NetStat()
if err != nil { if err != nil {
return fmt.Errorf("Lnstat error: %s", err) return fmt.Errorf("lnstat error: %s", err)
} }
for _, netStatFile := range netStats { for _, netStatFile := range netStats {

View file

@ -50,7 +50,7 @@ func perfTracepointFlagToTracepoints(tracepointsFlag []string) ([]*perfTracepoin
for i, tracepoint := range tracepointsFlag { for i, tracepoint := range tracepointsFlag {
split := strings.Split(tracepoint, ":") split := strings.Split(tracepoint, ":")
if len(split) != 2 { if len(split) != 2 {
return nil, fmt.Errorf("Invalid tracepoint config %v", tracepoint) return nil, fmt.Errorf("invalid tracepoint config %v", tracepoint)
} }
tracepoints[i] = &perfTracepoint{ tracepoints[i] = &perfTracepoint{
subsystem: split[0], subsystem: split[0],
@ -598,9 +598,6 @@ func (c *perfCollector) updateHardwareStats(ch chan<- prometheus.Metric) error {
if err := (*profiler).Profile(hwProfile); err != nil { if err := (*profiler).Profile(hwProfile); err != nil {
return err return err
} }
if hwProfile == nil {
continue
}
cpuid := strconv.Itoa(c.hwProfilerCPUMap[profiler]) cpuid := strconv.Itoa(c.hwProfilerCPUMap[profiler])
@ -670,9 +667,6 @@ func (c *perfCollector) updateSoftwareStats(ch chan<- prometheus.Metric) error {
if err := (*profiler).Profile(swProfile); err != nil { if err := (*profiler).Profile(swProfile); err != nil {
return err return err
} }
if swProfile == nil {
continue
}
cpuid := strconv.Itoa(c.swProfilerCPUMap[profiler]) cpuid := strconv.Itoa(c.swProfilerCPUMap[profiler])
@ -726,9 +720,6 @@ func (c *perfCollector) updateCacheStats(ch chan<- prometheus.Metric) error {
if err := (*profiler).Profile(cacheProfile); err != nil { if err := (*profiler).Profile(cacheProfile); err != nil {
return err return err
} }
if cacheProfile == nil {
continue
}
cpuid := strconv.Itoa(c.cacheProfilerCPUMap[profiler]) cpuid := strconv.Itoa(c.cacheProfilerCPUMap[profiler])

View file

@ -74,7 +74,6 @@ type systemdCollector struct {
socketCurrentConnectionsDesc *prometheus.Desc socketCurrentConnectionsDesc *prometheus.Desc
socketRefusedConnectionsDesc *prometheus.Desc socketRefusedConnectionsDesc *prometheus.Desc
systemdVersionDesc *prometheus.Desc systemdVersionDesc *prometheus.Desc
systemdVersion float64
unitIncludePattern *regexp.Regexp unitIncludePattern *regexp.Regexp
unitExcludePattern *regexp.Regexp unitExcludePattern *regexp.Regexp
logger log.Logger logger log.Logger

View file

@ -14,11 +14,11 @@
package collector package collector
import ( import (
"github.com/go-kit/log"
"regexp" "regexp"
"testing" "testing"
"github.com/coreos/go-systemd/dbus" "github.com/coreos/go-systemd/dbus"
"github.com/go-kit/log"
) )
// Creates mock UnitLists // Creates mock UnitLists