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(metric): Update dynamic interface label to be constant #1078

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions pkg/plugin/linuxutil/ethtool_stats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/microsoft/retina/pkg/log"
"github.com/microsoft/retina/pkg/metrics"
"github.com/microsoft/retina/pkg/utils"
"github.com/safchain/ethtool"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -60,7 +61,7 @@ func (er *EthtoolReader) readInterfaceStats() error {
defer er.ethHandle.Close()

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

for _, i := range ifaces {
Expand All @@ -83,12 +84,12 @@ func (er *EthtoolReader) readInterfaceStats() error {
continue
}

er.data.stats[i.Name] = make(map[string]uint64)
tempMap := er.processStats(ifaceStats)
er.data.stats[i.Name] = tempMap
for key, value := range tempMap {
er.data.stats[key] += value
}

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

}

return nil
Expand All @@ -114,10 +115,8 @@ func (er *EthtoolReader) processStats(ifaceStats map[string]uint64) map[string]u

func (er *EthtoolReader) updateMetrics() {
// update metrics section
// retrive interfacename and statname from ethStats
for ifName, stats := range er.data.stats {
for statName, statVal := range stats {
metrics.InterfaceStatsGauge.WithLabelValues(ifName, statName).Set(float64(statVal))
}
// retrive statname from ethStats
for statName, statVal := range er.data.stats {
metrics.InterfaceStatsGauge.WithLabelValues(utils.InterfaceNameConstant, statName).Set(float64(statVal))
}
}
6 changes: 3 additions & 3 deletions pkg/plugin/linuxutil/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var netstatCuratedKeys = map[string]struct{}{
"DataCsumErr": {},
"AddAddrDrop": {},
"RmAddrDrop": {},
"TCPTimeouts": {},
"TCPTimeouts": {},
"TCPLossProbes": {},
"TCPLostRetransmit": {},
}
Expand Down Expand Up @@ -95,8 +95,8 @@ type NetstatOpts struct {
}

type EthtoolStats struct {
// Stats by interface name and stat name
stats map[string]map[string]uint64
// Stats by name
stats map[string]uint64
}

type EthtoolOpts struct {
Expand Down
31 changes: 16 additions & 15 deletions pkg/utils/attr_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@ var (
remoteNodeKey = attribute.Key("remote_node")

// todo move to attributes pkg?
Type = "type"
Reason = "reason"
Direction = "direction"
SourceNodeName = "source_node_name"
TargetNodeName = "target_node_name"
State = "state"
Address = "address"
Port = "port"
StatName = "statistic_name"
InterfaceName = "interface_name"
Flag = "flag"
Endpoint = "endpoint"
AclRule = "aclrule"
Active = "ACTIVE"
Device = "device"
Type = "type"
Reason = "reason"
Direction = "direction"
SourceNodeName = "source_node_name"
TargetNodeName = "target_node_name"
State = "state"
Address = "address"
Port = "port"
StatName = "statistic_name"
InterfaceName = "interface_name"
InterfaceNameConstant = "all_interfaces"
Flag = "flag"
Endpoint = "endpoint"
AclRule = "aclrule"
Active = "ACTIVE"
Device = "device"

// TCP Connection Statistic Names
ResetCount = "ResetCount"
Expand Down
Loading