Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
)

const (
statusType = "status_type"

Check failure on line 17 in receiver/awscontainerinsightreceiver/internal/neuron/neuron_empty_metric_decorator.go

View workflow job for this annotation

GitHub Actions / lint-matrix (windows, receiver-0)

File is not properly formatted (gci)

Check failure on line 17 in receiver/awscontainerinsightreceiver/internal/neuron/neuron_empty_metric_decorator.go

View workflow job for this annotation

GitHub Actions / lint-matrix (linux, receiver-0)

File is not properly formatted (gci)
errorType = "error_type"
memoryLocation = "memory_location"
percentile = "percentile"
RuntimeTagOverride = "DEFAULT"
DefaultNeuronCorePerDevice = 2
)

var attributeConfig = map[string][]string{
Expand Down Expand Up @@ -66,6 +67,13 @@
neuronHardwareInfo, neuronHardwareInfoFound := findNeuronHardwareInfo(metrics)
if neuronHardwareInfoFound {
ed.addEmptyMetrics(neuronHardwareInfo, metrics)
neuronCoresPerDevice, foundCoresPerDevice := getNeuronCoresPerDevice(neuronHardwareInfo)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for better readability

Suggested change
neuronCoresPerDevice, foundCoresPerDevice := getNeuronCoresPerDevice(neuronHardwareInfo)
neuronCoresPerDevice, foundCoresPerDevice := getNeuronCoresPerDevice(neuronHardwareInfo)
if !foundCoresPerDevice {
neuronCoresPerDevice = DefaultNeuronCorePerDevice
}
ed.addNeuronCorePerDeviceAttribute(metrics, neuronCoresPerDevice)

if foundCoresPerDevice {
ed.addNeuronCorePerDeviceAttribute(metrics, neuronCoresPerDevice)
} else {
// Always add the Default if the above is not found, should never happen
ed.addNeuronCorePerDeviceAttribute(metrics, DefaultNeuronCorePerDevice)
}
}
}
}
Expand Down Expand Up @@ -129,7 +137,6 @@
datapoint.Attributes().PutStr(neuronCoreOriginalAttributeKey, strconv.Itoa(coreIndex))
datapoint.Attributes().PutStr(neuronDeviceAttributeKey, strconv.Itoa(coreIndex/neuronCoresPerDevice))
datapoint.Attributes().PutStr("runtime_tag", RuntimeTagOverride)
datapoint.Attributes().PutStr("runtime_tag", RuntimeTagOverride)
}

metricToAdd.CopyTo(metrics.AppendEmpty())
Expand Down Expand Up @@ -159,7 +166,38 @@
metricBody := metricToAdd.Gauge().DataPoints().At(0)
metricBody.SetDoubleValue(0)
metricBody.Attributes().PutStr("runtime_tag", RuntimeTagOverride)
metricBody.Attributes().PutStr("runtime_tag", RuntimeTagOverride)

return metricToAdd
}

// method to add neuroncore_per_device_count attribute to all metrics
func (ed *EmptyMetricDecorator) addNeuronCorePerDeviceAttribute(metrics pmetric.MetricSlice, neuronCoresPerDevice int) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this have to be a datapoint attribute? Cant it be a resource attr?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We chose to do it like this because we don't have access to the resource later on. But this would be a good idea for future refactoring.
https://github.com/aws/amazon-cloudwatch-agent/blob/main/plugins/processors/gpuattributes/internal/awsneuron_metric_modifier.go#L152

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its the same pmetric getting passed to the processor right? I dont get why it wont be available later on.
Please track this as a to-do.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, thank you for pointing this out

attributeValue := strconv.Itoa(neuronCoresPerDevice)
for i := 0; i < metrics.Len(); i++ {
m := metrics.At(i)
switch m.Type() {
case pmetric.MetricTypeGauge:
ed.addAttributeToNumberDataPoints(m.Gauge().DataPoints(), attributeValue)
case pmetric.MetricTypeSum:
ed.addAttributeToNumberDataPoints(m.Sum().DataPoints(), attributeValue)
case pmetric.MetricTypeHistogram:
dataPoints := m.Histogram().DataPoints()
for j := 0; j < dataPoints.Len(); j++ {
dataPoints.At(j).Attributes().PutStr(neuronCorePerDeviceKey, attributeValue)
}
case pmetric.MetricTypeSummary:
dataPoints := m.Summary().DataPoints()
for j := 0; j < dataPoints.Len(); j++ {
dataPoints.At(j).Attributes().PutStr(neuronCorePerDeviceKey, attributeValue)
}
default:
ed.Logger.Info("Metric type not supported", zap.String("metricType", m.Type().String()))
Comment thread
petruanica marked this conversation as resolved.
Outdated
}
}
}

func (ed *EmptyMetricDecorator) addAttributeToNumberDataPoints(dataPoints pmetric.NumberDataPointSlice, attributeValue string) {
for j := 0; j < dataPoints.Len(); j++ {
dataPoints.At(j).Attributes().PutStr(neuronCorePerDeviceKey, attributeValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,16 @@
},
{Name: NeuronExecutionStatus, MetricType: pmetric.MetricTypeGauge, DataValue: 1234}: {
{
statusType: "completed",

Check failure on line 339 in receiver/awscontainerinsightreceiver/internal/neuron/neuron_empty_metric_decorator_test.go

View workflow job for this annotation

GitHub Actions / lint-matrix (windows, receiver-0)

File is not properly formatted (gci)

Check failure on line 339 in receiver/awscontainerinsightreceiver/internal/neuron/neuron_empty_metric_decorator_test.go

View workflow job for this annotation

GitHub Actions / lint-matrix (linux, receiver-0)

File is not properly formatted (gci)
"runtime_tag": "123",
neuronCorePerDeviceKey: "2",
},
},
{Name: NeuronExecutionErrors, MetricType: pmetric.MetricTypeGauge, DataValue: 1111}: {
{
errorType: "generic",
"runtime_tag": "123",
neuronCorePerDeviceKey: "2",
},
},
{Name: NeuronRuntimeMemoryUsage, MetricType: pmetric.MetricTypeGauge, DataValue: 0}: {
Expand Down
Loading