ethtool: Remove end-to-end testing.

Signed-off-by: W. Andrew Denton <git@flying-snail.net>
This commit is contained in:
W. Andrew Denton 2021-05-03 09:35:49 -07:00
parent 596ff45f8f
commit 807f3c3af3
4 changed files with 56 additions and 105 deletions

View File

@ -20,29 +20,22 @@
package collector package collector
import ( import (
"bufio"
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path/filepath"
"regexp" "regexp"
"sort" "sort"
"strconv"
"strings"
"syscall"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level" "github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs" "github.com/prometheus/procfs/sysfs"
"github.com/safchain/ethtool" "github.com/safchain/ethtool"
"gopkg.in/alecthomas/kingpin.v2"
) )
var ( var (
receivedRegex = regexp.MustCompile(`_rx_`) receivedRegex = regexp.MustCompile(`_rx_`)
transmittedRegex = regexp.MustCompile(`_tx_`) transmittedRegex = regexp.MustCompile(`_tx_`)
ethtoolFixtures = kingpin.Flag("collector.ethtool.fixtures", "test fixtures to use for ethtool collector end-to-end testing").Default("").String()
) )
type EthtoolStats interface { type EthtoolStats interface {
@ -63,56 +56,6 @@ type ethtoolCollector struct {
stats EthtoolStats stats EthtoolStats
} }
type EthtoolFixture struct {
fixturePath string
}
func (e *EthtoolFixture) Stats(intf string) (map[string]uint64, error) {
res := make(map[string]uint64)
fixtureFile, err := os.Open(filepath.Join(e.fixturePath, intf))
if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {
// The fixture for this interface doesn't exist. That's OK because it replicates
// an interface that doesn't support ethtool.
return res, nil
}
if err != nil {
return res, err
}
defer fixtureFile.Close()
scanner := bufio.NewScanner(fixtureFile)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "#") {
continue
}
if strings.HasPrefix(line, "NIC statistics:") {
continue
}
line = strings.Trim(line, " ")
items := strings.Split(line, ": ")
val, err := strconv.ParseUint(items[1], 10, 64)
if err != nil {
return res, err
}
res[items[0]] = val
}
return res, err
}
func NewEthtoolTestCollector(logger log.Logger) (Collector, error) {
collector, err := makeEthtoolCollector(logger)
collector.stats = &EthtoolFixture{
fixturePath: *ethtoolFixtures,
}
if err != nil {
return nil, err
}
return collector, nil
}
// makeEthtoolCollector is the internal constructor for EthtoolCollector. // makeEthtoolCollector is the internal constructor for EthtoolCollector.
// This allows NewEthtoolTestCollector to override it's .stats interface // This allows NewEthtoolTestCollector to override it's .stats interface
// for testing. // for testing.
@ -173,11 +116,6 @@ func init() {
// NewEthtoolCollector returns a new Collector exposing ethtool stats. // NewEthtoolCollector returns a new Collector exposing ethtool stats.
func NewEthtoolCollector(logger log.Logger) (Collector, error) { func NewEthtoolCollector(logger log.Logger) (Collector, error) {
// Specifying --collector.ethtool.fixtures on the command line activates
// the test fixtures. This is for `end-to-end-test.sh`
if *ethtoolFixtures != "" {
return NewEthtoolTestCollector(logger)
}
return makeEthtoolCollector(logger) return makeEthtoolCollector(logger)
} }

View File

@ -14,13 +14,69 @@
package collector package collector
import ( import (
"bufio"
"fmt" "fmt"
"os"
"path/filepath"
"strconv"
"strings"
"syscall"
"testing" "testing"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
type EthtoolFixture struct {
fixturePath string
}
func (e *EthtoolFixture) Stats(intf string) (map[string]uint64, error) {
res := make(map[string]uint64)
fixtureFile, err := os.Open(filepath.Join(e.fixturePath, intf))
if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {
// The fixture for this interface doesn't exist. That's OK because it replicates
// an interface that doesn't support ethtool.
return res, nil
}
if err != nil {
return res, err
}
defer fixtureFile.Close()
scanner := bufio.NewScanner(fixtureFile)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "#") {
continue
}
if strings.HasPrefix(line, "NIC statistics:") {
continue
}
line = strings.Trim(line, " ")
items := strings.Split(line, ": ")
val, err := strconv.ParseUint(items[1], 10, 64)
if err != nil {
return res, err
}
res[items[0]] = val
}
return res, err
}
func NewEthtoolTestCollector(logger log.Logger) (Collector, error) {
collector, err := makeEthtoolCollector(logger)
collector.stats = &EthtoolFixture{
fixturePath: "fixtures/ethtool/",
}
if err != nil {
return nil, err
}
return collector, nil
}
func TestEthtoolCollector(t *testing.T) { func TestEthtoolCollector(t *testing.T) {
testcases := []string{ testcases := []string{
prometheus.NewDesc("node_ethtool_align_errors", "Network interface align_errors", []string{"device"}, nil).String(), prometheus.NewDesc("node_ethtool_align_errors", "Network interface align_errors", []string{"device"}, nil).String(),
@ -37,7 +93,6 @@ func TestEthtoolCollector(t *testing.T) {
} }
*sysPath = "fixtures/sys" *sysPath = "fixtures/sys"
*ethtoolFixtures = "fixtures/ethtool/"
collector, err := NewEthtoolTestCollector(log.NewNopLogger()) collector, err := NewEthtoolTestCollector(log.NewNopLogger())
if err != nil { if err != nil {

View File

@ -657,45 +657,6 @@ node_entropy_available_bits 1337
# HELP node_entropy_pool_size_bits Bits of entropy pool. # HELP node_entropy_pool_size_bits Bits of entropy pool.
# TYPE node_entropy_pool_size_bits gauge # TYPE node_entropy_pool_size_bits gauge
node_entropy_pool_size_bits 4096 node_entropy_pool_size_bits 4096
# HELP node_ethtool_align_errors Network interface align_errors
# TYPE node_ethtool_align_errors untyped
node_ethtool_align_errors{device="eth0"} 0
# HELP node_ethtool_received_broadcast Network interface rx_broadcast
# TYPE node_ethtool_received_broadcast untyped
node_ethtool_received_broadcast{device="eth0"} 5792
# HELP node_ethtool_received_errors_total Number of received frames with errors
# TYPE node_ethtool_received_errors_total untyped
node_ethtool_received_errors_total{device="eth0"} 0
# HELP node_ethtool_received_missed Network interface rx_missed
# TYPE node_ethtool_received_missed untyped
node_ethtool_received_missed{device="eth0"} 401
# HELP node_ethtool_received_multicast Network interface rx_multicast
# TYPE node_ethtool_received_multicast untyped
node_ethtool_received_multicast{device="eth0"} 23973
# HELP node_ethtool_received_packets_total Network interface packets received
# TYPE node_ethtool_received_packets_total untyped
node_ethtool_received_packets_total{device="eth0"} 1.260062e+06
# HELP node_ethtool_received_unicast Network interface rx_unicast
# TYPE node_ethtool_received_unicast untyped
node_ethtool_received_unicast{device="eth0"} 1.230297e+06
# HELP node_ethtool_transmitted_aborted Network interface tx_aborted
# TYPE node_ethtool_transmitted_aborted untyped
node_ethtool_transmitted_aborted{device="eth0"} 0
# HELP node_ethtool_transmitted_errors_total Number of sent frames with errors
# TYPE node_ethtool_transmitted_errors_total untyped
node_ethtool_transmitted_errors_total{device="eth0"} 0
# HELP node_ethtool_transmitted_multi_collisions Network interface tx_multi_collisions
# TYPE node_ethtool_transmitted_multi_collisions untyped
node_ethtool_transmitted_multi_collisions{device="eth0"} 0
# HELP node_ethtool_transmitted_packets_total Network interface packets sent
# TYPE node_ethtool_transmitted_packets_total untyped
node_ethtool_transmitted_packets_total{device="eth0"} 961500
# HELP node_ethtool_transmitted_single_collisions Network interface tx_single_collisions
# TYPE node_ethtool_transmitted_single_collisions untyped
node_ethtool_transmitted_single_collisions{device="eth0"} 0
# HELP node_ethtool_transmitted_underrun Network interface tx_underrun
# TYPE node_ethtool_transmitted_underrun untyped
node_ethtool_transmitted_underrun{device="eth0"} 0
# HELP node_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which node_exporter was built. # HELP node_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which node_exporter was built.
# TYPE node_exporter_build_info gauge # TYPE node_exporter_build_info gauge
# HELP node_fibrechannel_error_frames_total Number of errors in frames # HELP node_fibrechannel_error_frames_total Number of errors in frames
@ -2784,7 +2745,6 @@ node_scrape_collector_success{collector="diskstats"} 1
node_scrape_collector_success{collector="drbd"} 1 node_scrape_collector_success{collector="drbd"} 1
node_scrape_collector_success{collector="edac"} 1 node_scrape_collector_success{collector="edac"} 1
node_scrape_collector_success{collector="entropy"} 1 node_scrape_collector_success{collector="entropy"} 1
node_scrape_collector_success{collector="ethtool"} 1
node_scrape_collector_success{collector="fibrechannel"} 1 node_scrape_collector_success{collector="fibrechannel"} 1
node_scrape_collector_success{collector="filefd"} 1 node_scrape_collector_success{collector="filefd"} 1
node_scrape_collector_success{collector="hwmon"} 1 node_scrape_collector_success{collector="hwmon"} 1

View File

@ -14,7 +14,6 @@ enabled_collectors=$(cat << COLLECTORS
drbd drbd
edac edac
entropy entropy
ethtool
fibrechannel fibrechannel
filefd filefd
hwmon hwmon
@ -110,7 +109,6 @@ fi
--collector.qdisc.fixtures="collector/fixtures/qdisc/" \ --collector.qdisc.fixtures="collector/fixtures/qdisc/" \
--collector.netclass.ignored-devices="(dmz|int)" \ --collector.netclass.ignored-devices="(dmz|int)" \
--collector.netclass.ignore-invalid-speed \ --collector.netclass.ignore-invalid-speed \
--collector.ethtool.fixtures="collector/fixtures/ethtool/" \
--collector.bcache.priorityStats \ --collector.bcache.priorityStats \
--collector.cpu.info \ --collector.cpu.info \
--collector.cpu.info.flags-include="^(aes|avx.?|constant_tsc)$" \ --collector.cpu.info.flags-include="^(aes|avx.?|constant_tsc)$" \