@@ -14,11 +14,12 @@ import (
1414)
1515
1616const (
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
2425var 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+ }
0 commit comments