Skip to content

Commit

Permalink
Merge pull request k8snetworkplumbingwg#37 from zeeke/remove-version-map
Browse files Browse the repository at this point in the history
Remove driver version check
  • Loading branch information
SchSeba authored May 22, 2024
2 parents 6fe5c8f + 0cc1c86 commit e3dd690
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 294 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ The SR-IOV Network Metrics Exporter is designed with the Kubernetes SR-IOV stack
The sysfs collector for Virtual Function telemetry supports NICs with drivers that implement the SR-IOV sysfs management interface e.g. ice, i40e, mlnx_en and mlnx_ofed.

The netlink collector relies on driver support and a kernel version of 4.4 or higher.
To support netlink, we recommend these driver versions: an i40e driver of 2.11+ or higher for Intel® 700 series NICs and ice driver 1.2+ for Intel® 800 series NICs.
Also, the following minimum driver versions are required for this collector:
- `i40e` - 2.11+ for Intel® 700 series NICs
- `ice` - 1.2+ for Intel® 800 series NICs
- `mlx5_core` - 5.15+ for Mellanox NICs

To check your current driver version run: `modinfo <driver> | grep ^version` where driver is `i40e` or `ice`\
i40e drivers: [Intel Download Center](https://downloadcenter.intel.com/download/18026/), [Source Forge](https://sourceforge.net/projects/e1000/files/i40e%20stable/)\
Expand Down
8 changes: 1 addition & 7 deletions collectors/sriovdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ import (
"github.com/prometheus/client_golang/prometheus"

"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/utils"

"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/drvinfo"
)

const (
noNumaInfo = "-1"
supportedDriversDbPath = "/etc/sriov-network-metrics-exporter/drivers.yaml"
noNumaInfo = "-1"
)

var (
Expand All @@ -35,8 +32,6 @@ var (
vfStatsSubsystem = "vf"
vfStatsCollectorName = "vfstats"

supportedDrivers drvinfo.SupportedDrivers

devfs fs.FS
netfs fs.FS
)
Expand All @@ -47,7 +42,6 @@ type vfsPCIAddr map[string]string
// init runs the registration for this collector on package import
func init() {
flag.Var(&collectorPriority, "collector.vfstatspriority", "Priority of collectors")
supportedDrivers = drvinfo.NewSupportedDrivers(supportedDriversDbPath)
register(vfStatsCollectorName, enabled, createSriovDevCollector)
}

Expand Down
11 changes: 2 additions & 9 deletions collectors/sriovdev_readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strconv"
"strings"

"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/drvinfo"
"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/utils"
"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/vfstats"
)
Expand Down Expand Up @@ -49,18 +48,12 @@ func getStatsReader(pf string, priority []string) sriovStatReader {

log.Printf("%s does not support sysfs collector, directory '%s' does not exist", pf, filepath.Join(pf, "/device/sriov"))
case "netlink":
info, err := drvinfo.GetDriverInfo(pf)
if err != nil {
log.Printf("failed to get driver info error %v", err)
return nil
}

if supportedDrivers.IsDriverSupported(info) {
if vfstats.DoesPfSupportNetlink(pf) {
log.Printf("%s - using netlink collector", pf)
return netlinkReader{vfstats.VfStats(pf)}
}

log.Printf("%s does not support netlink collector, %+v driver not supported", pf, info)
log.Printf("%s does not support netlink collector", pf)
default:
log.Printf("%s - '%s' collector not supported", pf, collector)
}
Expand Down
23 changes: 12 additions & 11 deletions collectors/sriovdev_readers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ import (
"io/fs"
"testing/fstest"

"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/drvinfo"
"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/vfstats"
"github.com/vishvananda/netlink"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = DescribeTable("test getting stats reader for pf", // getStatsReader
func(pf string, priority []string, fsys fs.FS, driver *drvinfo.DriverInfo, expected sriovStatReader, logs ...string) {
func(pf string, priority []string, fsys fs.FS, link netlink.Link, expected sriovStatReader, logs ...string) {
netfs = fsys

// TODO: replace with ethtool mock
drvinfo.GetDriverInfo = func(name string) (*drvinfo.DriverInfo, error) {
return driver, nil
if link != nil {
vfstats.GetLink = func(name string) (netlink.Link, error) {
return link, nil
}
DeferCleanup(func() {
vfstats.GetLink = netlink.LinkByName
})
}

// TODO: replace with fstest.MapFS entry
supportedDrivers = drvinfo.SupportedDrivers{Drivers: drvinfo.DriversList{Drivers: []drvinfo.DriverInfo{*driver}}, DbFilePath: ""}

statsReader := getStatsReader(pf, priority)

if expected != nil {
Expand All @@ -37,22 +38,22 @@ var _ = DescribeTable("test getting stats reader for pf", // getStatsReader
"ens785f0",
[]string{"sysfs", "netlink"},
fstest.MapFS{"ens785f0/device/sriov": {Mode: fs.ModeDir}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
nil,
sysfsReader{"/sys/class/net/%s/device/sriov/%s/stats"},
"ens785f0 - using sysfs collector"),
Entry("without sysfs support",
"ens785f0",
[]string{"sysfs", "netlink"},
fstest.MapFS{},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
&netlink.Device{LinkAttrs: netlink.LinkAttrs{Vfs: []netlink.VfInfo{}}}, //nolint:govet
netlinkReader{vfstats.VfStats("ens785f0")},
"ens785f0 does not support sysfs collector",
"ens785f0 - using netlink collector"),
Entry("without any collector support",
"ens785f0",
[]string{"unsupported_collector"},
fstest.MapFS{},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
nil,
nil,
"ens785f0 - 'unsupported_collector' collector not supported"),
)
Expand Down
50 changes: 14 additions & 36 deletions collectors/sriovdev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net"
"testing/fstest"

"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/drvinfo"
"github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter/pkg/vfstats"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -21,19 +20,11 @@ var _ = AfterEach(func() {
})

var _ = DescribeTable("test vf stats collection", // Collect
func(priority []string, fsys fs.FS, driver *drvinfo.DriverInfo, link netlink.Device, expected []metric, logs ...string) {
func(priority []string, fsys fs.FS, link netlink.Device, expected []metric, logs ...string) {
devfs = fsys
netfs = fsys
collectorPriority = priority

// TODO: replace with ethtool mock
drvinfo.GetDriverInfo = func(name string) (*drvinfo.DriverInfo, error) {
return driver, nil
}

// TODO: replace with fstest.MapFS entry
supportedDrivers = drvinfo.SupportedDrivers{Drivers: drvinfo.DriversList{Drivers: []drvinfo.DriverInfo{*driver}}, DbFilePath: ""}

vfstats.GetLink = func(name string) (netlink.Link, error) {
return &link, nil
}
Expand Down Expand Up @@ -71,7 +62,6 @@ var _ = DescribeTable("test vf stats collection", // Collect
"t_ens785f0/device/sriov/0/stats/tx_packets": {Data: []byte("8")},
"t_ens785f0/device/sriov/1/stats/rx_packets": {Data: []byte("16")},
"t_ens785f0/device/sriov/1/stats/tx_packets": {Data: []byte("32")}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
nil,
[]metric{
{map[string]string{"numa_node": "0", "pciAddr": "0000:1d:01.0", "pf": "t_ens785f0", "vf": "0"}, 4},
Expand All @@ -92,7 +82,6 @@ var _ = DescribeTable("test vf stats collection", // Collect
"0000:2e:00.0/class": {Data: []byte("0x020000")},
"0000:2e:00.0/virtfn0": {Data: []byte("/sys/devices/0000:2e:01.0"), Mode: fs.ModeSymlink},
"0000:2e:00.0/virtfn1": {Data: []byte("/sys/devices/0000:2e:01.1"), Mode: fs.ModeSymlink}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
netlink.Device{LinkAttrs: netlink.LinkAttrs{Vfs: []netlink.VfInfo{
{0, net.HardwareAddr{}, 0, 0, 0, true, 0, 0, 0, 11, 12, 13, 14, 15, 16, 17, 18, 0, 0}, //nolint:govet
{1, net.HardwareAddr{}, 0, 0, 0, true, 0, 0, 0, 21, 22, 23, 24, 25, 26, 27, 28, 0, 0}}}}, //nolint:govet
Expand Down Expand Up @@ -131,7 +120,6 @@ var _ = DescribeTable("test vf stats collection", // Collect
"0000:4g:00.0/numa_node": {Data: []byte("0")},
"0000:4g:00.0/class": {Data: []byte("0x020000")},
"0000:4g:00.0/virtfn0": {Data: []byte("/sys/devices/0000:4g:01.0"), Mode: fs.ModeSymlink}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
netlink.Device{LinkAttrs: netlink.LinkAttrs{Vfs: []netlink.VfInfo{
{0, net.HardwareAddr{}, 0, 0, 0, true, 0, 0, 0, 31, 32, 33, 34, 35, 36, 37, 38, 0, 0}}}}, //nolint:govet
[]metric{
Expand Down Expand Up @@ -213,17 +201,9 @@ var _ = DescribeTable("test creating sriovDev collector", // createSriovDevColle
)

var _ = DescribeTable("test getting sriov devices from filesystem", // getSriovDevAddrs
func(fsys fs.FS, driver *drvinfo.DriverInfo, expected []string, logs ...string) {
func(fsys fs.FS, expected []string, logs ...string) {
devfs = fsys

// TODO: replace with ethtool mock
drvinfo.GetDriverInfo = func(name string) (*drvinfo.DriverInfo, error) {
return driver, nil
}

// TODO: replace with fstest.MapFS entry
supportedDrivers = drvinfo.SupportedDrivers{Drivers: drvinfo.DriversList{Drivers: []drvinfo.DriverInfo{*driver}}, DbFilePath: ""}

devs := getSriovDevAddrs()
Expect(devs).To(Equal(expected))

Expand All @@ -235,40 +215,38 @@ var _ = DescribeTable("test getting sriov devices from filesystem", // getSriovD
"0000:6f:00.1/sriov_totalvfs": {Data: []byte("64")}, "0000:6f:00.1/class": {Data: []byte("0x020000")},
"0000:7g:00.0/sriov_totalvfs": {Data: []byte("128")}, "0000:7g:00.0/class": {Data: []byte("0x020000")},
"0000:7g:00.1/sriov_totalvfs": {Data: []byte("128")}, "0000:7g:00.1/class": {Data: []byte("0x020000")}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
[]string{"0000:6f:00.0", "0000:6f:00.1", "0000:7g:00.0", "0000:7g:00.1"}),
Entry("mixed devices",
fstest.MapFS{
"0000:8h:00.0/": {Mode: fs.ModeDir},
"0000:8h:00.1/": {Mode: fs.ModeDir},
"0000:9i:00.0/sriov_totalvfs": {Data: []byte("63")}, "0000:9i:00.0/class": {Data: []byte("0x020000")},
"0000:9i:00.1/sriov_totalvfs": {Data: []byte("63")}, "0000:9i:00.1/class": {Data: []byte("0x020000")}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
[]string{"0000:9i:00.0", "0000:9i:00.1"}),
Entry("no sriov net devices",
fstest.MapFS{
"0000:1b:00.0/": {Mode: fs.ModeDir},
"0000:1b:00.1/": {Mode: fs.ModeDir},
"0000:1b:00.2/": {Mode: fs.ModeDir},
"0000:1b:00.3/": {Mode: fs.ModeDir}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
[]string{},
"no sriov net devices found"),
)

var _ = DescribeTable("test getting sriov dev details", // getSriovDev
func(dev string, priority []string, fsys fs.FS, driver *drvinfo.DriverInfo, expected sriovDev, logs ...string) {
func(dev string, priority []string, fsys fs.FS, link netlink.Link, expected sriovDev, logs ...string) {
devfs = fsys
netfs = fsys

// TODO: replace with ethtool mock
drvinfo.GetDriverInfo = func(name string) (*drvinfo.DriverInfo, error) {
return driver, nil
if link != nil {
vfstats.GetLink = func(name string) (netlink.Link, error) {
return link, nil
}
DeferCleanup(func() {
vfstats.GetLink = netlink.LinkByName
})
}

// TODO: replace with fstest.MapFS entry
supportedDrivers = drvinfo.SupportedDrivers{Drivers: drvinfo.DriversList{Drivers: []drvinfo.DriverInfo{*driver}}, DbFilePath: ""}

sriovDev := getSriovDev(dev, priority)
Expect(sriovDev).To(Equal(expected))

Expand All @@ -284,7 +262,7 @@ var _ = DescribeTable("test getting sriov dev details", // getSriovDev
"ens785f0/device/sriov": {Mode: fs.ModeDir}, // Added to enable sysfs reader
"0000:5g:00.0/net/ens801f0": {Mode: fs.ModeDir},
"0000:5g:00.0/virtfn0": {Data: []byte("/sys/devices/0000:5g:01.0"), Mode: fs.ModeSymlink}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
nil,
sriovDev{
"ens785f0",
sysfsReader{"/sys/class/net/%s/device/sriov/%s/stats"},
Expand All @@ -299,7 +277,7 @@ var _ = DescribeTable("test getting sriov dev details", // getSriovDev
"0000:6h:00.0/virtfn1": {Data: []byte("/sys/devices/0000:6h:01.1"), Mode: fs.ModeSymlink},
"0000:7i:00.0/net/ens801f0": {Mode: fs.ModeDir},
"0000:7i:00.0/virtfn0": {Data: []byte("/sys/devices/0000:7i:01.0"), Mode: fs.ModeSymlink}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
&netlink.Device{LinkAttrs: netlink.LinkAttrs{Vfs: []netlink.VfInfo{}}}, //nolint:govet
sriovDev{
"ens785f0",
netlinkReader{vfstats.VfStats("ens785f0")},
Expand All @@ -313,7 +291,7 @@ var _ = DescribeTable("test getting sriov dev details", // getSriovDev
"0000:8j:00.0/net/ens785f0": {Mode: fs.ModeDir},
"0000:8j:00.0/virtfn0": {Data: []byte("/sys/devices/0000:8j:01.0"), Mode: fs.ModeSymlink},
"0000:8j:00.0/virtfn1": {Data: []byte("/sys/devices/0000:8j:01.1"), Mode: fs.ModeSymlink}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
nil,
sriovDev{
"ens785f0",
nil,
Expand All @@ -324,7 +302,7 @@ var _ = DescribeTable("test getting sriov dev details", // getSriovDev
[]string{"sysfs"},
fstest.MapFS{
"0000:9k:00.0/net/ens785f0": {Mode: fs.ModeDir}},
&drvinfo.DriverInfo{Name: "ice", Version: "1.9.11"},
nil,
sriovDev{
"ens785f0",
nil,
Expand Down
13 changes: 0 additions & 13 deletions deployment/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: sriov-network-metrics-exporter
namespace: monitoring
data:
drivers.yaml: |-
drivers:
- name: ice
version: 1.9.11
- name: mlx5_core
version: 5.15.0-53-generic
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ module github.com/k8snetworkplumbingwg/sriov-network-metrics-exporter
go 1.18

require (
github.com/hashicorp/go-version v1.6.0
github.com/onsi/ginkgo/v2 v2.5.1
github.com/onsi/gomega v1.24.0
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_model v0.2.0
github.com/safchain/ethtool v0.2.0
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
google.golang.org/grpc v1.56.3
gopkg.in/yaml.v3 v3.0.1
k8s.io/kubelet v0.25.5
)

Expand All @@ -32,4 +29,5 @@ require (
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down Expand Up @@ -193,8 +191,6 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/safchain/ethtool v0.2.0 h1:dILxMBqDnQfX192cCAPjZr9v2IgVXeElHPy435Z/IdE=
github.com/safchain/ethtool v0.2.0/go.mod h1:WkKB1DnNtvsMlDmQ50sgwowDJV/hGbJSOvJoEXs1AJQ=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
Expand Down Expand Up @@ -338,7 +334,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
Loading

0 comments on commit e3dd690

Please sign in to comment.