Skip to content

Commit 726f1bd

Browse files
authored
NeuronCore mapping bug fix (#341)
1 parent d042199 commit 726f1bd

2 files changed

Lines changed: 51 additions & 11 deletions

File tree

receiver/awscontainerinsightreceiver/internal/neuron/neuron_empty_metric_decorator.go

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414
)
1515

1616
const (
17-
statusType = "status_type"
18-
errorType = "error_type"
19-
memoryLocation = "memory_location"
20-
percentile = "percentile"
21-
RuntimeTagOverride = "DEFAULT"
17+
statusType = "status_type"
18+
errorType = "error_type"
19+
memoryLocation = "memory_location"
20+
percentile = "percentile"
21+
RuntimeTagOverride = "DEFAULT"
22+
DefaultNeuronCorePerDevice = 2
2223
)
2324

2425
var attributeConfig = map[string][]string{
@@ -66,6 +67,13 @@ func (ed *EmptyMetricDecorator) ConsumeMetrics(ctx context.Context, md pmetric.M
6667
neuronHardwareInfo, neuronHardwareInfoFound := findNeuronHardwareInfo(metrics)
6768
if neuronHardwareInfoFound {
6869
ed.addEmptyMetrics(neuronHardwareInfo, metrics)
70+
neuronCoresPerDevice, foundCoresPerDevice := getNeuronCoresPerDevice(neuronHardwareInfo)
71+
if foundCoresPerDevice {
72+
ed.addNeuronCorePerDeviceAttribute(metrics, neuronCoresPerDevice)
73+
} else {
74+
// Always add the Default if the above is not found, should never happen
75+
ed.addNeuronCorePerDeviceAttribute(metrics, DefaultNeuronCorePerDevice)
76+
}
6977
}
7078
}
7179
}
@@ -129,7 +137,6 @@ func populateCoreMetrics(metrics pmetric.MetricSlice, metricName string, hardwar
129137
datapoint.Attributes().PutStr(neuronCoreOriginalAttributeKey, strconv.Itoa(coreIndex))
130138
datapoint.Attributes().PutStr(neuronDeviceAttributeKey, strconv.Itoa(coreIndex/neuronCoresPerDevice))
131139
datapoint.Attributes().PutStr("runtime_tag", RuntimeTagOverride)
132-
datapoint.Attributes().PutStr("runtime_tag", RuntimeTagOverride)
133140
}
134141

135142
metricToAdd.CopyTo(metrics.AppendEmpty())
@@ -159,7 +166,38 @@ func createNewMetricFromHardwareInfo(hardwareInfo pmetric.Metric, metricName str
159166
metricBody := metricToAdd.Gauge().DataPoints().At(0)
160167
metricBody.SetDoubleValue(0)
161168
metricBody.Attributes().PutStr("runtime_tag", RuntimeTagOverride)
162-
metricBody.Attributes().PutStr("runtime_tag", RuntimeTagOverride)
163169

164170
return metricToAdd
165171
}
172+
173+
// method to add neuroncore_per_device_count attribute to all metrics
174+
func (ed *EmptyMetricDecorator) addNeuronCorePerDeviceAttribute(metrics pmetric.MetricSlice, neuronCoresPerDevice int) {
175+
attributeValue := strconv.Itoa(neuronCoresPerDevice)
176+
for i := 0; i < metrics.Len(); i++ {
177+
m := metrics.At(i)
178+
switch m.Type() {
179+
case pmetric.MetricTypeGauge:
180+
ed.addAttributeToNumberDataPoints(m.Gauge().DataPoints(), attributeValue)
181+
case pmetric.MetricTypeSum:
182+
ed.addAttributeToNumberDataPoints(m.Sum().DataPoints(), attributeValue)
183+
case pmetric.MetricTypeHistogram:
184+
dataPoints := m.Histogram().DataPoints()
185+
for j := 0; j < dataPoints.Len(); j++ {
186+
dataPoints.At(j).Attributes().PutStr(neuronCorePerDeviceKey, attributeValue)
187+
}
188+
case pmetric.MetricTypeSummary:
189+
dataPoints := m.Summary().DataPoints()
190+
for j := 0; j < dataPoints.Len(); j++ {
191+
dataPoints.At(j).Attributes().PutStr(neuronCorePerDeviceKey, attributeValue)
192+
}
193+
default:
194+
ed.Logger.Warn("Metric type not supported", zap.String("metricType", m.Type().String()))
195+
}
196+
}
197+
}
198+
199+
func (ed *EmptyMetricDecorator) addAttributeToNumberDataPoints(dataPoints pmetric.NumberDataPointSlice, attributeValue string) {
200+
for j := 0; j < dataPoints.Len(); j++ {
201+
dataPoints.At(j).Attributes().PutStr(neuronCorePerDeviceKey, attributeValue)
202+
}
203+
}

receiver/awscontainerinsightreceiver/internal/neuron/neuron_empty_metric_decorator_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,16 @@ func TestConsumeMetricsForNeuronEmptyMetricsDecorator(t *testing.T) {
336336
},
337337
{Name: NeuronExecutionStatus, MetricType: pmetric.MetricTypeGauge, DataValue: 1234}: {
338338
{
339-
statusType: "completed",
340-
"runtime_tag": "123",
339+
statusType: "completed",
340+
"runtime_tag": "123",
341+
neuronCorePerDeviceKey: "2",
341342
},
342343
},
343344
{Name: NeuronExecutionErrors, MetricType: pmetric.MetricTypeGauge, DataValue: 1111}: {
344345
{
345-
errorType: "generic",
346-
"runtime_tag": "123",
346+
errorType: "generic",
347+
"runtime_tag": "123",
348+
neuronCorePerDeviceKey: "2",
347349
},
348350
},
349351
{Name: NeuronRuntimeMemoryUsage, MetricType: pmetric.MetricTypeGauge, DataValue: 0}: {

0 commit comments

Comments
 (0)