Repository: microsoft/retina
File: pkg/plugin/linuxutil/ethtool_stats_linux.go (Go)

Code before:
		er.l.Error("Error while getting all interfaces: %v\n", zap.Error(err))
		return err
	}

	er.data = &EthtoolStats{
		stats: make(map[string]uint64),
	}

	for _, i := range ifaces {
		// exclude lo (loopback interface), cbr0 (bridge network interface), lxc (Linux containers interface), and azv (virtual interface)
		if strings.Contains(i.Name, "lo") ||
			strings.Contains(i.Name, "cbr0") ||
			strings.Contains(i.Name, "lxc") ||
			strings.Contains(i.Name, "azv") {
			continue
		}

		// Retrieve tx from eth0
		ifaceStats, err := er.ethHandle.Stats(i.Name)
		if err != nil {
			if errors.Is(err, errskip) {
				er.l.Debug("Skipping unsupported interface", zap.String("ifacename", i.Name))
			} else if strings.Contains(err.Error(), "interface not supported while retrieving stats") {
				er.l.Warn("Unsupported interface detected:", zap.String("ifacename", i.Name), zap.Error(err))
			} else {
				er.l.Error("Error while getting ethtool:", zap.String("ifacename", i.Name), zap.Error(err))
			}
			continue
		}

		tempMap := er.processStats(ifaceStats)
		for key, value := range tempMap {
			er.data.stats[key] += value
		}

		er.l.Debug("Processed ethtool Stats ", zap.String("ifacename", i.Name))
	}

	return nil
}

func (er *EthtoolReader) processStats(ifaceStats map[string]uint64) map[string]uint64 {
	// process stats section
	newStats := make(map[string]uint64)
	for k, v := range ifaceStats {
		if !er.opts.addZeroVal && v == 0 {
			continue
		}

		if er.opts.errOrDropKeysOnly && !strings.Contains(k, "err") && !strings.Contains(k, "drop") {
			continue

Review comment (suggestion):
Update the log message. It's `Error while retrieving stats...`.

Code after:
	if err != nil {
		er.l.Error("Error while getting all interfaces: %v\n", zap.Error(err))
		return err
	}

	er.data = &EthtoolStats{
		stats: make(map[string]uint64),
	}

	for _, i := range ifaces {
		// exclude lo (loopback interface), cbr0 (bridge network interface), lxc (Linux containers interface), and azv (virtual interface)
		if strings.Contains(i.Name, "lo") ||
			strings.Contains(i.Name, "cbr0") ||
			strings.Contains(i.Name, "lxc") ||
			strings.Contains(i.Name, "azv") {
			continue
		}

		// Retrieve tx from eth0
		ifaceStats, err := er.ethHandle.Stats(i.Name)
		if err != nil {
			if errors.Is(err, errskip) {
				er.l.Debug("Skipping unsupported interface", zap.String("ifacename", i.Name))
			} else if strings.Contains(err.Error(), "interface not supported while retrieving stats") {
				er.l.Warn("Unsupported interface detected:", zap.String("ifacename", i.Name), zap.Error(err))
			} else {
				er.l.Error("Error while retrieving stats:", zap.String("ifacename", i.Name), zap.Error(err))
			}
			continue
		}

		tempMap := er.processStats(ifaceStats)
		for key, value := range tempMap {
			er.data.stats[key] += value
		}

		er.l.Debug("Processed ethtool Stats ", zap.String("ifacename", i.Name))
	}

	return nil
}

func (er *EthtoolReader) processStats(ifaceStats map[string]uint64) map[string]uint64 {
	// process stats section
	newStats := make(map[string]uint64)
	for k, v := range ifaceStats {
		if !er.opts.addZeroVal && v == 0 {
			continue
		}

		if er.opts.errOrDropKeysOnly && !strings.Contains(k, "err") && !strings.Contains(k, "drop") {