Skip to content

Commit

Permalink
Remove unused *prometheus.Desc return value from collectors `collec…
Browse files Browse the repository at this point in the history
…t()` function (#1475)
  • Loading branch information
breed808 committed May 11, 2024
1 parent b977c84 commit 9bf84fb
Show file tree
Hide file tree
Showing 42 changed files with 452 additions and 450 deletions.
6 changes: 4 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
linters:
disable-all: true
enable:
- deadcode
- errcheck
- revive
- govet
- gofmt
- ineffassign
- unconvert
- varcheck
- nilnil
- nilerr
- unparam
- loggercheck

issues:
exclude:
Expand Down
2 changes: 1 addition & 1 deletion exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func main() {
w.Header().Set("Content-Type", "application/json")
_, err := fmt.Fprintln(w, `{"status":"ok"}`)
if err != nil {
_ = level.Debug(logger).Log("Failed to write to stream", "err", err)
_ = level.Debug(logger).Log("msg", "Failed to write to stream", "err", err)
}
})
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/collector/ad/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ func (c *collector) Build() error {
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting ad metrics", "desc", desc, "err", err)
if err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting ad metrics", "err", err)
return err
}
return nil
Expand Down Expand Up @@ -649,14 +649,14 @@ type Win32_PerfRawData_DirectoryServices_DirectoryServices struct {
TransitivesuboperationsPersec uint32
}

func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collect(ch chan<- prometheus.Metric) error {
var dst []Win32_PerfRawData_DirectoryServices_DirectoryServices
q := wmi.QueryAll(&dst, c.logger)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
return err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
return errors.New("WMI query returned empty result set")
}

ch <- prometheus.MustNewConstMetric(
Expand Down Expand Up @@ -1350,5 +1350,5 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
float64(dst[0].TombstonesVisitedPersec),
)

return nil, nil
return nil
}
14 changes: 7 additions & 7 deletions pkg/collector/adcs/adcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ func (c *collector) Build() error {
}

func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collectADCSCounters(ctx, ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting ADCS metrics", "desc", desc, "err", err)
if err := c.collectADCSCounters(ctx, ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting ADCS metrics", "err", err)
return err
}
return nil
Expand All @@ -169,17 +169,17 @@ type perflibADCS struct {
SignedCertificateTimestampListProcessingTime float64 `perflib:"Signed Certificate Timestamp List processing time (ms)"`
}

func (c *collector) collectADCSCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collectADCSCounters(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
dst := make([]perflibADCS, 0)
if _, ok := ctx.PerfObjects["Certification Authority"]; !ok {
return nil, errors.New("perflib did not contain an entry for Certification Authority")
return errors.New("perflib did not contain an entry for Certification Authority")
}
err := perflib.UnmarshalObject(ctx.PerfObjects["Certification Authority"], &dst, c.logger)
if err != nil {
return nil, err
return err
}
if len(dst) == 0 {
return nil, errors.New("perflib query for Certification Authority (ADCS) returned empty result set")
return errors.New("perflib query for Certification Authority (ADCS) returned empty result set")
}

for _, d := range dst {
Expand Down Expand Up @@ -267,5 +267,5 @@ func (c *collector) collectADCSCounters(ctx *types.ScrapeContext, ch chan<- prom
)
}

return nil, nil
return nil
}
10 changes: 5 additions & 5 deletions pkg/collector/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ func (c *collector) Build() error {

// Collect implements the Collector interface
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ctx, ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting cache metrics", "desc", desc, "err", err)
if err := c.collect(ctx, ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting cache metrics", "err", err)
return err
}
return nil
Expand Down Expand Up @@ -295,10 +295,10 @@ type perflibCache struct {
SyncPinReadsTotal float64 `perflib:"Sync Pin Reads/sec"`
}

func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
var dst []perflibCache // Single-instance class, array is required but will have single entry.
if err := perflib.UnmarshalObject(ctx.PerfObjects["Cache"], &dst, c.logger); err != nil {
return nil, err
return err
}

ch <- prometheus.MustNewConstMetric(
Expand Down Expand Up @@ -475,5 +475,5 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
dst[0].SyncPinReadsTotal,
)

return nil, nil
return nil
}
16 changes: 8 additions & 8 deletions pkg/collector/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func (c *collector) Build() error {
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting collector metrics", "desc", desc, "err", err)
if err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting collector metrics", "err", err)
return err
}
return nil
Expand All @@ -208,12 +208,12 @@ func (c *collector) containerClose(container hcsshim.Container) {
}
}

func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collect(ch chan<- prometheus.Metric) error {
// Types Container is passed to get the containers compute systems only
containers, err := hcsshim.GetContainers(hcsshim.ComputeSystemQuery{Types: []string{"Container"}})
if err != nil {
_ = level.Error(c.logger).Log("msg", "Err in Getting containers", "err", err)
return nil, err
return err
}

count := len(containers)
Expand All @@ -224,7 +224,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
float64(count),
)
if count == 0 {
return nil, nil
return nil
}

containerPrefixes := make(map[string]string)
Expand Down Expand Up @@ -322,12 +322,12 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
hnsEndpoints, err := hcsshim.HNSListEndpointRequest()
if err != nil {
_ = level.Warn(c.logger).Log("msg", "Failed to collect network stats for containers")
return nil, nil
return err
}

if len(hnsEndpoints) == 0 {
_ = level.Info(c.logger).Log("msg", fmt.Sprintf("No network stats for containers to collect"))
return nil, nil
return nil
}

for _, endpoint := range hnsEndpoints {
Expand Down Expand Up @@ -386,7 +386,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
}
}

return nil, nil
return nil
}

func getContainerIdWithPrefix(containerDetails hcsshim.ContainerProperties) string {
Expand Down
12 changes: 6 additions & 6 deletions pkg/collector/cpu_info/cpu_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ type win32_Processor struct {
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting cpu_info metrics", "desc", desc, "err", err)
if err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting cpu_info metrics", "err", err)
return err
}
return nil
}

func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collect(ch chan<- prometheus.Metric) error {
var dst []win32_Processor
// We use a static query here because the provided methods in wmi.go all issue a SELECT *;
// This results in the time-consuming LoadPercentage field being read which seems to measure each CPU
// serially over a 1 second interval, so the scrape time is at least 1s * num_sockets
if err := wmi.Query(win32ProcessorQuery, &dst); err != nil {
return nil, err
return err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
return errors.New("WMI query returned empty result set")
}

// Some CPUs end up exposing trailing spaces for certain strings, so clean them up
Expand All @@ -121,5 +121,5 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
)
}

return nil, nil
return nil
}
16 changes: 8 additions & 8 deletions pkg/collector/cs/cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ func (c *collector) Build() error {
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting cs metrics", "desc", desc, "err", err)
if err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting cs metrics", "err", err)
return err
}
return nil
}

func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collect(ch chan<- prometheus.Metric) error {
// Get systeminfo for number of processors
systemInfo := sysinfoapi.GetSystemInfo()

// Get memory status for physical memory
mem, err := sysinfoapi.GlobalMemoryStatusEx()
if err != nil {
return nil, err
return err
}

ch <- prometheus.MustNewConstMetric(
Expand All @@ -108,15 +108,15 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro

hostname, err := sysinfoapi.GetComputerName(sysinfoapi.ComputerNameDNSHostname)
if err != nil {
return nil, err
return err
}
domain, err := sysinfoapi.GetComputerName(sysinfoapi.ComputerNameDNSDomain)
if err != nil {
return nil, err
return err
}
fqdn, err := sysinfoapi.GetComputerName(sysinfoapi.ComputerNameDNSFullyQualified)
if err != nil {
return nil, err
return err
}

ch <- prometheus.MustNewConstMetric(
Expand All @@ -128,5 +128,5 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
fqdn,
)

return nil, nil
return nil
}
12 changes: 6 additions & 6 deletions pkg/collector/diskdrive/diskdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,21 @@ var (

// Collect sends the metric values for each metric to the provided prometheus Metric channel.
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting disk_drive_info metrics", "desc", desc, "err", err)
if err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting disk_drive_info metrics", "err", err)
return err
}
return nil
}

func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collect(ch chan<- prometheus.Metric) error {
var dst []Win32_DiskDrive

if err := wmi.Query(win32DiskQuery, &dst); err != nil {
return nil, err
return err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
return errors.New("WMI query returned empty result set")
}

for _, disk := range dst {
Expand Down Expand Up @@ -222,5 +222,5 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
}
}

return nil, nil
return nil
}
12 changes: 6 additions & 6 deletions pkg/collector/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ func (c *collector) Build() error {
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting dns metrics", "desc", desc, "err", err)
if err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting dns metrics", "err", err)
return err
}
return nil
Expand Down Expand Up @@ -261,14 +261,14 @@ type Win32_PerfRawData_DNS_DNS struct {
ZoneTransferSOARequestSent uint32
}

func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collect(ch chan<- prometheus.Metric) error {
var dst []Win32_PerfRawData_DNS_DNS
q := wmi.QueryAll(&dst, c.logger)
if err := wmi.Query(q, &dst); err != nil {
return nil, err
return err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
return errors.New("WMI query returned empty result set")
}

ch <- prometheus.MustNewConstMetric(
Expand Down Expand Up @@ -520,5 +520,5 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
float64(dst[0].SecureUpdateReceived),
)

return nil, nil
return nil
}
10 changes: 5 additions & 5 deletions pkg/collector/fsrmquota/fsrmquota.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func (c *collector) Build() error {
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting fsrmquota metrics", "desc", desc, "err", err)
if err := c.collect(ch); err != nil {
_ = level.Error(c.logger).Log("msg", "failed collecting fsrmquota metrics", "err", err)
return err
}
return nil
Expand All @@ -142,14 +142,14 @@ type MSFT_FSRMQuota struct {
SoftLimit bool
}

func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
func (c *collector) collect(ch chan<- prometheus.Metric) error {
var dst []MSFT_FSRMQuota
q := wmi.QueryAll(&dst, c.logger)

var count int

if err := wmi.QueryNamespace(q, &dst, "root/microsoft/windows/fsrm"); err != nil {
return nil, err
return err
}

for _, quota := range dst {
Expand Down Expand Up @@ -214,5 +214,5 @@ func (c *collector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, erro
prometheus.GaugeValue,
float64(count),
)
return nil, nil
return nil
}
Loading

0 comments on commit 9bf84fb

Please sign in to comment.