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

fix(hnsstats): improve error handling and logging for VFP port counters #1002

Merged
merged 2 commits into from
Nov 15, 2024
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
8 changes: 6 additions & 2 deletions pkg/plugin/windows/hnsstats/hnsstats_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ func pullHnsStats(ctx context.Context, h *hnsstats) error {
// h.l.Info(hnsStatsData.String())

// Get VFP port counters for matching port (MAC address of endpoint as the key)
portguid := kv[mac]
portguid, ok := kv[mac]
if !ok || len(portguid) == 0 {
h.l.Error("port is either empty of not found", zap.String(zapMACField, mac))
continue
}
if countersRaw, err := getVfpPortCountersRaw(portguid); len(portguid) > 0 && err == nil {
if vfpcounters, err := parseVfpPortCounters(countersRaw); err == nil {
// Attach VFP port counters
Expand All @@ -135,7 +139,7 @@ func pullHnsStats(ctx context.Context, h *hnsstats) error {
h.l.Error("Unable to parse VFP port counters", zap.String(zapPortField, portguid), zap.Error(err))
}
} else {
h.l.Error("Unable to find VFP port counters", zap.String(zapMACField, mac), zap.Error(err))
h.l.Error("Unable to find VFP port counters", zap.String(zapMACField, mac), zap.String(zapPortField, portguid), zap.Error(err))
}

notifyHnsStats(h, hnsStatsData)
Expand Down
7 changes: 5 additions & 2 deletions pkg/plugin/windows/hnsstats/vfp_counters_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os/exec"
"strconv"
"strings"

"github.com/pkg/errors"
)

// IN/OUT Direction of vSwitch VFP port
Expand Down Expand Up @@ -151,13 +153,14 @@ func getVfpPortCountersRaw(portGUID string) (string, error) {
cmd := exec.Command("cmd", "/c", vfpCmd)
out, err := cmd.Output()

return string(out), err
return string(out), errors.Wrap(err, "errored while running vfpctrl /get-port-counter")
}

// TODO: Remove this once Resources.Allocators.EndpointPortGuid gets added to hcsshim Endpoint struct
// Lists all vSwitch ports
func listvPorts() ([]byte, error) {
return exec.Command("cmd", "/c", "vfpctrl /list-vmswitch-port").CombinedOutput()
out, err := exec.Command("cmd", "/c", "vfpctrl /list-vmswitch-port").CombinedOutput()
return out, errors.Wrap(err, "errored while running vfpctrl /list-vmswitch-port")
}

// TODO: Remove this once Resources.Allocators.EndpointPortGuid gets added to hcsshim Endpoint struct
Expand Down
Loading