Skip to content

Commit

Permalink
omit pause container network metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sharanyad committed Mar 30, 2021
1 parent e6b9f2a commit 4e0a8b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
16 changes: 11 additions & 5 deletions agent/stats/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,17 +697,23 @@ func (engine *DockerStatsEngine) taskContainerMetricsUnsafe(taskArn string) ([]*
if !taskExistsInTaskStats {
return nil, fmt.Errorf("task not found")
}
networkStats, err := taskStatsMap.StatsQueue.GetNetworkStatsSet()
if err != nil {
seelog.Warnf("error getting network stats: %v, task: %v", err, taskArn)
if dockerContainer, err := engine.resolver.ResolveContainer(dockerID); err != nil {
seelog.Debugf("Could not map container ID to container, container: %s, err: %s", dockerID, err)
} else {
containerMetric.NetworkStatsSet = networkStats
// do not add network stats for pause container
if dockerContainer.Container.Type != apicontainer.ContainerCNIPause {
networkStats, err := taskStatsMap.StatsQueue.GetNetworkStatsSet()
if err != nil {
seelog.Warnf("error getting network stats: %v, task: %v", err, taskArn)
} else {
containerMetric.NetworkStatsSet = networkStats
}
}
}
}
}
containerMetrics = append(containerMetrics, containerMetric)
}

return containerMetrics, nil
}

Expand Down
17 changes: 15 additions & 2 deletions agent/stats/engine_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func TestNetworkModeStatsAWSVPCMode(t *testing.T) {
},
}

testContainer1 := &apicontainer.DockerContainer{
Container: &apicontainer.Container{
Name: "test1",
},
}

t1 := &apitask.Task{
Arn: "t1",
Family: "f1",
Expand All @@ -71,9 +77,11 @@ func TestNetworkModeStatsAWSVPCMode(t *testing.T) {
}

resolver.EXPECT().ResolveTask("c1").AnyTimes().Return(t1, nil)
resolver.EXPECT().ResolveTask("c2").AnyTimes().Return(t1, nil)
resolver.EXPECT().ResolveTaskByARN(gomock.Any()).Return(t1, nil).AnyTimes()

resolver.EXPECT().ResolveContainer(gomock.Any()).AnyTimes().Return(testContainer, nil)
resolver.EXPECT().ResolveContainer("c1").AnyTimes().Return(testContainer, nil)
resolver.EXPECT().ResolveContainer("c2").AnyTimes().Return(testContainer1, nil)
mockDockerClient.EXPECT().Stats(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes()

mockDockerClient.EXPECT().InspectContainer(gomock.Any(), gomock.Any(), gomock.Any()).Return(&types.ContainerJSON{
Expand All @@ -91,6 +99,7 @@ func TestNetworkModeStatsAWSVPCMode(t *testing.T) {
engine.containerInstanceArn = defaultContainerInstance
engine.client = mockDockerClient
engine.addAndStartStatsContainer("c1")
engine.addAndStartStatsContainer("c2")
ts1 := parseNanoTime("2015-02-12T21:22:05.131117533Z")
containerStats := createFakeContainerStats()
dockerStats := []*types.StatsJSON{{}, {}}
Expand All @@ -108,6 +117,10 @@ func TestNetworkModeStatsAWSVPCMode(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, taskMetrics, 1)
for _, containerMetric := range taskMetrics[0].ContainerMetrics {
assert.NotNil(t, containerMetric.NetworkStatsSet, "network stats should be non-empty")
if *containerMetric.ContainerName == "test1" {
assert.NotNil(t, containerMetric.NetworkStatsSet, "network stats should be non-empty")
} else {
assert.Nil(t, containerMetric.NetworkStatsSet, "network stats should be empty for pause")
}
}
}

0 comments on commit 4e0a8b9

Please sign in to comment.