Skip to content

Commit 2ead5a4

Browse files
committed
Fix undercounting of EC2 awsvpc network stats
As discussed in #4618, it seems that scaling down these network stats by the number of containers is simply incorrect. On that issue, I have empirically compared EC2 awsvpc numbers to both Fargate awsvpc and EC2 bridge numbers to deduce this. Fixes #4618.
1 parent eaff425 commit 2ead5a4

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

agent/stats/task_linux.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ func (taskStat *StatsTask) populateNIDeviceList(containerPID string) ([]string,
102102
return deviceList, err
103103
}
104104

105-
func linkStatsToDockerStats(netLinkStats *netlinklib.LinkStatistics, numberOfContainers uint64) dockerstats.NetworkStats {
105+
func linkStatsToDockerStats(netLinkStats *netlinklib.LinkStatistics) dockerstats.NetworkStats {
106106
networkStats := dockerstats.NetworkStats{
107-
RxBytes: netLinkStats.RxBytes / numberOfContainers,
108-
RxPackets: netLinkStats.RxPackets / numberOfContainers,
109-
RxErrors: netLinkStats.RxErrors / numberOfContainers,
110-
RxDropped: netLinkStats.RxDropped / numberOfContainers,
111-
TxBytes: netLinkStats.TxBytes / numberOfContainers,
112-
TxPackets: netLinkStats.TxPackets / numberOfContainers,
113-
TxErrors: netLinkStats.TxErrors / numberOfContainers,
114-
TxDropped: netLinkStats.TxDropped / numberOfContainers,
107+
RxBytes: netLinkStats.RxBytes,
108+
RxPackets: netLinkStats.RxPackets,
109+
RxErrors: netLinkStats.RxErrors,
110+
RxDropped: netLinkStats.RxDropped,
111+
TxBytes: netLinkStats.TxBytes,
112+
TxPackets: netLinkStats.TxPackets,
113+
TxErrors: netLinkStats.TxErrors,
114+
TxDropped: netLinkStats.TxDropped,
115115
}
116116
return networkStats
117117
}
@@ -142,8 +142,7 @@ func (taskStat *StatsTask) retrieveNetworkStatistics() (map[string]dockerstats.N
142142
return nil, err
143143
}
144144
netLinkStats := link.Attrs().Statistics
145-
networkStats[link.Attrs().Name] = linkStatsToDockerStats(netLinkStats,
146-
uint64(taskStat.TaskMetadata.NumberContainers))
145+
networkStats[link.Attrs().Name] = linkStatsToDockerStats(netLinkStats)
147146
}
148147

149148
return networkStats, nil

agent/stats/task_linux_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestTaskStatsCollection(t *testing.T) {
9393

9494
assert.NoError(t, err)
9595
assert.NotNil(t, networkStatsSet)
96-
rxSum := (*networkStatsSet.RxBytes.SampleCount * (int64(50))) / int64(numberOfContainers)
96+
rxSum := *networkStatsSet.RxBytes.SampleCount * (int64(50))
9797
assert.EqualValues(t, rxSum, *networkStatsSet.RxBytes.Sum)
9898
}
9999

@@ -157,8 +157,8 @@ func TestTaskStatsCollectionError(t *testing.T) {
157157

158158
networkStatsSet, err := taskStats.StatsQueue.GetNetworkStatsSet()
159159
assert.NoError(t, err)
160-
assert.EqualValues(t, 50, *networkStatsSet.RxBytes.Sum)
161-
assert.EqualValues(t, 2, *networkStatsSet.RxPackets.Sum)
160+
assert.EqualValues(t, 100, *networkStatsSet.RxBytes.Sum)
161+
assert.EqualValues(t, 4, *networkStatsSet.RxPackets.Sum)
162162
assert.EqualValues(t, 2, *networkStatsSet.RxPackets.SampleCount)
163163
assert.EqualValues(t, 2, *networkStatsSet.TxPackets.SampleCount)
164164
}

0 commit comments

Comments
 (0)