Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence missing netclass errors #1986

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

* [BUGFIX] Handle errors from disabled PSI subsystem #1983
* [BUGFIX] Sanitize strings from /sys/class/power_supply #1984
* [BUGFIX] Silence missing netclass errors #1986

## 1.1.1 / 2021-02-12

Expand Down
10 changes: 8 additions & 2 deletions collector/netclass_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
package collector

import (
"errors"
"fmt"
"os"
"regexp"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
"gopkg.in/alecthomas/kingpin.v2"
Expand Down Expand Up @@ -61,6 +64,10 @@ func NewNetClassCollector(logger log.Logger) (Collector, error) {
func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error {
netClass, err := c.getNetClassInfo()
if err != nil {
if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) {
level.Debug(c.logger).Log("msg", "Could not read netclass file", "err", err)
return ErrNoData
}
return fmt.Errorf("could not get net class info: %w", err)
}
for _, ifaceInfo := range netClass {
Expand Down Expand Up @@ -173,9 +180,8 @@ func pushMetric(ch chan<- prometheus.Metric, subsystem string, name string, valu

func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) {
netClass, err := c.fs.NetClass()

if err != nil {
return netClass, fmt.Errorf("error obtaining net class info: %w", err)
return netClass, err
}

for device := range netClass {
Expand Down