Skip to content

Commit

Permalink
[chore] prometheusreceiver: remove isCumulative from metric family (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#13767)

Signed-off-by: Bogdan Drutu <[email protected]>

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Sep 1, 2022
1 parent 0715666 commit 63d7311
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions receiver/prometheusreceiver/internal/otlp_metricfamily.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ func newMetricFamily(metricName string, mc MetadataCache, logger *zap.Logger) *m

// includesMetric returns true if the metric is part of the family
func (mf *metricFamily) includesMetric(metricName string) bool {
if mf.isCumulativeType() {
if mf.mtype != pmetric.MetricDataTypeGauge {
// If it is a merged family type, then it should match the
// family name when suffixes are trimmed.
return normalizeMetricName(metricName) == mf.name
}
// If it isn't a merged type, the metricName and family name
// should match
// If it isn't a merged type, the metricName and family name should match
return metricName == mf.name
}

Expand Down Expand Up @@ -138,9 +137,7 @@ func (mg *metricGroup) toDistributionPoint(dest pmetric.HistogramDataPointSlice)

// The timestamp MUST be in retrieved from milliseconds and converted to nanoseconds.
tsNanos := pdataTimestampFromMs(mg.ts)
if mg.family.isCumulativeType() {
point.SetStartTimestamp(tsNanos) // metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
}
point.SetStartTimestamp(tsNanos) // metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
point.SetTimestamp(tsNanos)
populateAttributes(pmetric.MetricDataTypeHistogram, mg.ls, point.Attributes())
}
Expand Down Expand Up @@ -188,22 +185,17 @@ func (mg *metricGroup) toSummaryPoint(dest pmetric.SummaryDataPointSlice) {
// The timestamp MUST be in retrieved from milliseconds and converted to nanoseconds.
tsNanos := pdataTimestampFromMs(mg.ts)
point.SetTimestamp(tsNanos)
if mg.family.isCumulativeType() {
point.SetStartTimestamp(tsNanos) // metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
}
point.SetStartTimestamp(tsNanos) // metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
populateAttributes(pmetric.MetricDataTypeSummary, mg.ls, point.Attributes())
}

func (mg *metricGroup) toNumberDataPoint(dest pmetric.NumberDataPointSlice) {
var startTsNanos pcommon.Timestamp
tsNanos := pdataTimestampFromMs(mg.ts)
point := dest.AppendEmpty()
// gauge/undefined types have no start time.
if mg.family.isCumulativeType() {
startTsNanos = tsNanos // metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
if mg.family.mtype == pmetric.MetricDataTypeSum {
point.SetStartTimestamp(tsNanos) // metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
}

point := dest.AppendEmpty()
point.SetStartTimestamp(startTsNanos)
point.SetTimestamp(tsNanos)
if value.IsStaleNaN(mg.value) {
point.SetFlagsImmutable(pmetric.DefaultMetricDataPointFlags.WithNoRecordedValue(true))
Expand Down Expand Up @@ -232,12 +224,6 @@ func populateAttributes(mType pmetric.MetricDataType, ls labels.Labels, dest pco
}
}

func (mf *metricFamily) isCumulativeType() bool {
return mf.mtype == pmetric.MetricDataTypeSum ||
mf.mtype == pmetric.MetricDataTypeHistogram ||
mf.mtype == pmetric.MetricDataTypeSummary
}

func (mf *metricFamily) loadMetricGroupOrCreate(groupKey uint64, ls labels.Labels, ts int64) *metricGroup {
mg, ok := mf.groups[groupKey]
if !ok {
Expand Down

0 comments on commit 63d7311

Please sign in to comment.