Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Jun 13, 2023
1 parent f7e3a14 commit 8439c66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
14 changes: 4 additions & 10 deletions receiver/carbonreceiver/protocol/path_parser_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 12 additions & 18 deletions receiver/carbonreceiver/protocol/plaintext_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

0 comments on commit 8439c66

Please sign in to comment.