@@ -10,8 +10,10 @@ import (
1010 "errors"
1111 "fmt"
1212 "log"
13+ "math"
1314 "math/rand"
1415 "sort"
16+ "strconv"
1517 "strings"
1618 "time"
1719
@@ -296,3 +298,65 @@ func ValidateLogsFrequency(env *environment.MetaData) status.TestResult {
296298 testResult .Status = status .SUCCESSFUL
297299 return testResult
298300}
301+
302+ func ValidateNeuronCoreUtilizationValuesLogs (env * environment.MetaData ) status.TestResult {
303+ const core = "core"
304+ testResult := status.TestResult {
305+ Name : "emf-logs-neuron-core-utilization" ,
306+ Status : status .SUCCESSFUL ,
307+ }
308+ var testFailed = false
309+
310+ end := time .Now ().Add (- 2 * time .Minute ).Truncate (time .Minute )
311+ start := end .Add (- 1 * time .Minute )
312+ group := fmt .Sprintf ("/aws/containerinsights/%s/performance" , env .EKSClusterName )
313+
314+ // need to get the instances used for the EKS cluster
315+ eKSInstances , err := awsservice .GetEKSInstances (env .EKSClusterName )
316+ if err != nil {
317+ log .Println ("failed to get EKS instances" , err )
318+ testResult .Status = status .FAILED
319+ return testResult
320+ }
321+
322+ for _ , instance := range eKSInstances {
323+ stream := * instance .InstanceName
324+ coreMap , err := awsservice .GetNeuronCoreUtilizationPerCore (group , stream , & start , & end )
325+
326+ if err != nil {
327+ log .Printf ("log validation (%s/%s) failed: %v, start time : %s, error is : %s" , group , stream , err , start , err )
328+ testResult .Status = status .FAILED
329+ return testResult
330+ }
331+
332+ // We expect 32 Cores from the current test, anything less or more is a bug
333+ if len (coreMap ) != 32 {
334+ log .Printf ("32 Cores not found" )
335+ var coreMapStr strings.Builder
336+ for k , v := range coreMap {
337+ coreMapStr .WriteString (fmt .Sprintf ("%s: %f, " , k , v ))
338+ }
339+ log .Printf ("coreMap: %s" , coreMapStr .String ())
340+ testResult .Status = status .FAILED
341+ return testResult
342+ }
343+
344+ // Check if coreMap has the expected core utilization values
345+ for coreKey , actualValue := range coreMap {
346+ if strings .HasPrefix (coreKey , core ) {
347+ coreNumStr := strings .TrimPrefix (coreKey , core )
348+ expectedValue , err := strconv .Atoi (coreNumStr )
349+ if err != nil || math .Round (actualValue ) != float64 (expectedValue ) {
350+ log .Printf ("Core utilization validation failed: expected %s:%d, got %v" ,
351+ coreKey , expectedValue , actualValue )
352+ testFailed = true
353+ }
354+ }
355+ }
356+ }
357+
358+ if testFailed {
359+ testResult .Status = status .FAILED
360+ }
361+ return testResult
362+ }
0 commit comments