Skip to content

Commit 400580c

Browse files
authored
Add IntegTests to Cover changes from PR:1713, Aggregate NeuronCore Utilization Metrics (#547)
1 parent acd1943 commit 400580c

7 files changed

Lines changed: 28272 additions & 599 deletions

File tree

docs/resources/dummy-neuron-monitor/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RUN apt-get update \
2727
&& rm -rf /tmp/tmp* \
2828
&& apt-get clean
2929

30+
COPY neuron-monitor-output.json /opt/aws/neuron/bin/neuron-monitor-output.json
3031
COPY dummy_neuron_monitor.py /opt/aws/neuron/bin/dummy_neuron_monitor.py
3132
RUN chmod 755 /opt/aws/neuron/bin/dummy_neuron_monitor.py
3233
RUN pip3 install prometheus_client boto3 requests

docs/resources/dummy-neuron-monitor/dummy_neuron_monitor.py

Lines changed: 4 additions & 598 deletions
Large diffs are not rendered by default.

docs/resources/dummy-neuron-monitor/neuron-monitor-output.json

Lines changed: 28166 additions & 0 deletions
Large diffs are not rendered by default.

terraform/eks/daemon/awsneuron/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ resource "kubernetes_daemonset" "neuron_monitor" {
395395
}
396396
container {
397397
name = "neuron-monitor-prometheus"
398-
image = "506463145083.dkr.ecr.us-west-2.amazonaws.com/mocked-neuron-monitor:v2"
398+
image = "506463145083.dkr.ecr.us-west-2.amazonaws.com/mocked-neuron-monitor:v4"
399399
port {
400400
container_port = 8000
401401
}

test/awsneuron/neuron_metrics_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (t *AwsNeuronTestRunner) Validate() status.TestGroupResult {
4040
testResults = append(testResults, metric.ValidateMetrics(t.env, awsNeuronMetricIndicator, expectedDimsToMetrics)...)
4141
testResults = append(testResults, metric.ValidateLogs(t.env))
4242
testResults = append(testResults, metric.ValidateLogsFrequency(t.env))
43+
testResults = append(testResults, metric.ValidateNeuronCoreUtilizationValuesLogs(t.env))
4344
return status.TestGroupResult{
4445
Name: t.GetTestName(),
4546
TestResults: testResults,

test/metric/container_insights_util.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

util/awsservice/cloudwatchlogs.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,38 @@ func CountMetricsInEMFLogs(logGroupName string) (int, error) {
431431

432432
return totalMetrics, nil
433433
}
434+
435+
func GetNeuronCoreUtilizationPerCore(logGroup, logStream string, since, until *time.Time) (map[string]float64, error) {
436+
var coreUtilization = make(map[string]float64)
437+
var data map[string]interface{}
438+
439+
events, err := GetLogsSince(logGroup, logStream, since, until)
440+
441+
// if there is an error, return the empty map
442+
if err != nil {
443+
return coreUtilization, err
444+
}
445+
446+
for _, event := range events {
447+
message := *event.Message
448+
449+
var eksClusterType EKSClusterType
450+
innerErr := json.Unmarshal([]byte(message), &eksClusterType)
451+
if innerErr != nil || !strings.Contains(eksClusterType.Type, "NodeAWSNeuronCore") {
452+
continue
453+
}
454+
455+
err := json.Unmarshal([]byte(message), &data)
456+
if err != nil {
457+
continue
458+
}
459+
460+
if core, ok := data["NeuronCore"].(string); ok {
461+
if util, ok := data["node_neuroncore_utilization"].(float64); ok {
462+
coreUtilization[core] = util
463+
}
464+
}
465+
}
466+
467+
return coreUtilization, nil
468+
}

0 commit comments

Comments
 (0)