Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aws/amazon-ecs-agent
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: abe50e7c1541c99e2fa435dbc444e09a9f30208d
Choose a base ref
..
head repository: aws/amazon-ecs-agent
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8a060f8258ab7cc8fb6441f8aeba71f51d33e1ab
Choose a head ref
Showing with 42 additions and 2 deletions.
  1. +1 −1 agent/stats/utils_unix.go
  2. +1 −1 agent/stats/utils_unix_test.go
  3. +40 −0 agent/stats/utils_windows_test.go
2 changes: 1 addition & 1 deletion agent/stats/utils_unix.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import (
// dockerStatsToContainerStats returns a new object of the ContainerStats object from docker stats.
func dockerStatsToContainerStats(dockerStats *docker.Stats) (*ContainerStats, error) {
// The length of PercpuUsage represents the number of cores in an instance.
if len(dockerStats.CPUStats.CPUUsage.PercpuUsage) == 0 {
if len(dockerStats.CPUStats.CPUUsage.PercpuUsage) == 0 || numCores == uint64(0) {
seelog.Debug("Invalid container statistics reported, no cpu core usage reported")
return nil, fmt.Errorf("Invalid container statistics reported, no cpu core usage reported")
}
2 changes: 1 addition & 1 deletion agent/stats/utils_unix_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows
// +build !windows,!integration
// Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
40 changes: 40 additions & 0 deletions agent/stats/utils_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// +build windows,!integration
// Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package stats

import (
"encoding/json"
"fmt"
"testing"

docker "github.com/fsouza/go-dockerclient"
)

func TestDockerStatsToContainerStatsZeroCoresGeneratesError(t *testing.T) {
numCores = uint64(0)
jsonStat := fmt.Sprintf(`
{
"cpu_stats":{
"cpu_usage":{
"total_usage":%d
}
}
}`, 100)
dockerStat := &docker.Stats{}
json.Unmarshal([]byte(jsonStat), dockerStat)
_, err := dockerStatsToContainerStats(dockerStat)
if err == nil {
t.Error("Expected error converting container stats with zero cpu cores")
}
}