diff --git a/receiver/carbonreceiver/protocol/path_parser_helper.go b/receiver/carbonreceiver/protocol/path_parser_helper.go index 03b8db48a65c..2b508d5d512a 100644 --- a/receiver/carbonreceiver/protocol/path_parser_helper.go +++ b/receiver/carbonreceiver/protocol/path_parser_helper.go @@ -120,20 +120,14 @@ func (pph *PathParserHelper) Parse(line string) (pmetric.Metric, error) { m := pmetric.NewMetric() m.SetName(parsedPath.MetricName) + var dp pmetric.NumberDataPoint if parsedPath.MetricType == CumulativeMetricType { sum := m.SetEmptySum() sum.SetIsMonotonic(true) - dp := sum.DataPoints().AppendEmpty() - dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(unixTime, 0))) - if errIsFloat != nil { - dp.SetDoubleValue(dblVal) - } else { - dp.SetIntValue(intVal) - } - parsedPath.Attributes.CopyTo(dp.Attributes()) - return m, nil + dp = sum.DataPoints().AppendEmpty() + } else { + dp = m.SetEmptyGauge().DataPoints().AppendEmpty() } - dp := m.SetEmptyGauge().DataPoints().AppendEmpty() dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(unixTime, 0))) if errIsFloat != nil { dp.SetDoubleValue(dblVal) diff --git a/receiver/carbonreceiver/protocol/plaintext_parser_test.go b/receiver/carbonreceiver/protocol/plaintext_parser_test.go index 185cd07be305..2c2f9d52bc15 100644 --- a/receiver/carbonreceiver/protocol/plaintext_parser_test.go +++ b/receiver/carbonreceiver/protocol/plaintext_parser_test.go @@ -180,20 +180,17 @@ func buildIntMetric( ) pmetric.Metric { m := pmetric.NewMetric() m.SetName(name) + var dp pmetric.NumberDataPoint if typ == CumulativeMetricType { sum := m.SetEmptySum() sum.SetIsMonotonic(true) - dp := sum.DataPoints().AppendEmpty() - dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(timestamp, 0))) - attributes.CopyTo(dp.Attributes()) - dp.SetIntValue(value) + dp = sum.DataPoints().AppendEmpty() } else { - g := m.SetEmptyGauge() - dp := g.DataPoints().AppendEmpty() - dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(timestamp, 0))) - attributes.CopyTo(dp.Attributes()) - dp.SetIntValue(value) + dp = m.SetEmptyGauge().DataPoints().AppendEmpty() } + dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(timestamp, 0))) + attributes.CopyTo(dp.Attributes()) + dp.SetIntValue(value) return m } @@ -206,19 +203,16 @@ func buildDoubleMetric( ) pmetric.Metric { m := pmetric.NewMetric() m.SetName(name) + var dp pmetric.NumberDataPoint if typ == CumulativeMetricType { sum := m.SetEmptySum() sum.SetIsMonotonic(true) - dp := sum.DataPoints().AppendEmpty() - dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(timestamp, 0))) - _ = dp.Attributes().FromRaw(attributes) - dp.SetDoubleValue(value) + dp = sum.DataPoints().AppendEmpty() } else { - g := m.SetEmptyGauge() - dp := g.DataPoints().AppendEmpty() - dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(timestamp, 0))) - _ = dp.Attributes().FromRaw(attributes) - dp.SetDoubleValue(value) + dp = m.SetEmptyGauge().DataPoints().AppendEmpty() } + dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(timestamp, 0))) + _ = dp.Attributes().FromRaw(attributes) + dp.SetDoubleValue(value) return m }