Skip to content

Commit

Permalink
fix(metric): Update dynamic interface label to be constant (#1078)
Browse files Browse the repository at this point in the history
# Description

Updated dynamic interface label for `interface_stats` metric to be set
to `all_interfaces`. Also did some optimisation on the `EthtoolStats`
struct. All stat names will be accumulated across all interface names

## Related Issue

#1067

## Checklist

- [x] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [x] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [x] I have correctly attributed the author(s) of the code.
- [x] I have tested the changes locally.
- [x] I have followed the project's style guidelines.
- [x] I have updated the documentation, if necessary.
- [ ] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.
  • Loading branch information
BeegiiK authored Nov 27, 2024
1 parent 94415d4 commit 3945951
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
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

0 comments on commit 3945951

Please sign in to comment.