@@ -18,6 +18,8 @@ package functional_tests
18
18
import (
19
19
"fmt"
20
20
"os"
21
+ "runtime"
22
+ "strconv"
21
23
"strings"
22
24
"testing"
23
25
"time"
@@ -41,6 +43,7 @@ const (
41
43
logDriverTaskDefinition = "logdriver-jsonfile-windows"
42
44
cleanupTaskDefinition = "cleanup-windows"
43
45
networkModeTaskDefinition = "network-mode-windows"
46
+ cpuSharesPerCore = 1024
44
47
)
45
48
46
49
// TestAWSLogsDriver verifies that container logs are sent to Amazon CloudWatch Logs with awslogs as the log driver
@@ -266,14 +269,20 @@ func TestTelemetry(t *testing.T) {
266
269
time .Sleep (waitMetricsInCloudwatchDuration )
267
270
268
271
cwclient := cloudwatch .New (session .New (), aws .NewConfig ().WithRegion (* ECS .Config .Region ))
269
- err = VerifyMetrics (cwclient , params , true )
272
+ _ , err = VerifyMetrics (cwclient , params , true )
270
273
assert .NoError (t , err , "Before task running, verify metrics for CPU utilization failed" )
271
274
272
275
params .MetricName = aws .String ("MemoryUtilization" )
273
- err = VerifyMetrics (cwclient , params , true )
276
+ _ , err = VerifyMetrics (cwclient , params , true )
274
277
assert .NoError (t , err , "Before task running, verify metrics for memory utilization failed" )
275
278
276
- testTask , err := agent .StartTask (t , "telemetry-windows" )
279
+ cpuNum := runtime .NumCPU ()
280
+
281
+ tdOverrides := make (map [string ]string )
282
+ // Set the container cpu percentage 25%
283
+ tdOverrides ["$$$$CPUSHARE$$$$" ] = strconv .Itoa (int (float64 (cpuNum * cpuSharesPerCore ) * 0.25 ))
284
+
285
+ testTask , err := agent .StartTaskWithTaskDefinitionOverrides (t , "telemetry-windows" , tdOverrides )
277
286
require .NoError (t , err , "Failed to start telemetry task" )
278
287
// Wait for the task to run and the agent to send back metrics
279
288
err = testTask .WaitRunning (waitTaskStateChangeDuration )
@@ -283,11 +292,13 @@ func TestTelemetry(t *testing.T) {
283
292
params .EndTime = aws .Time (RoundTimeUp (time .Now (), time .Minute ).UTC ())
284
293
params .StartTime = aws .Time ((* params .EndTime ).Add (- waitMetricsInCloudwatchDuration ).UTC ())
285
294
params .MetricName = aws .String ("CPUUtilization" )
286
- err = VerifyMetrics (cwclient , params , false )
295
+ metrics , err : = VerifyMetrics (cwclient , params , false )
287
296
assert .NoError (t , err , "Task is running, verify metrics for CPU utilization failed" )
297
+ // Also verify the cpu usage is around 25%
298
+ assert .InDelta (t , 0.25 , * metrics .Average , 0.05 )
288
299
289
300
params .MetricName = aws .String ("MemoryUtilization" )
290
- err = VerifyMetrics (cwclient , params , false )
301
+ _ , err = VerifyMetrics (cwclient , params , false )
291
302
assert .NoError (t , err , "Task is running, verify metrics for memory utilization failed" )
292
303
293
304
err = testTask .Stop ()
@@ -300,10 +311,10 @@ func TestTelemetry(t *testing.T) {
300
311
params .EndTime = aws .Time (RoundTimeUp (time .Now (), time .Minute ).UTC ())
301
312
params .StartTime = aws .Time ((* params .EndTime ).Add (- waitMetricsInCloudwatchDuration ).UTC ())
302
313
params .MetricName = aws .String ("CPUUtilization" )
303
- err = VerifyMetrics (cwclient , params , true )
314
+ _ , err = VerifyMetrics (cwclient , params , true )
304
315
assert .NoError (t , err , "Task stopped: verify metrics for CPU utilization failed" )
305
316
306
317
params .MetricName = aws .String ("MemoryUtilization" )
307
- err = VerifyMetrics (cwclient , params , true )
318
+ _ , err = VerifyMetrics (cwclient , params , true )
308
319
assert .NoError (t , err , "Task stopped, verify metrics for memory utilization failed" )
309
320
}
0 commit comments