Skip to content

Commit

Permalink
[chore] prometheusreceiver: refactor tests to allow to remove metrics…
Browse files Browse the repository at this point in the history
…builder (open-telemetry#13977)

Currently the metricsbuilder is an extra unnecessary allocation and indirection, no value added, so the plan is to merge into transaction.

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

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Sep 8, 2022
1 parent db6987e commit ba84168
Show file tree
Hide file tree
Showing 4 changed files with 397 additions and 331 deletions.
14 changes: 10 additions & 4 deletions receiver/prometheusreceiver/internal/metricsbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/value"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -112,16 +113,21 @@ func (b *metricBuilder) AddDataPoint(ls labels.Labels, t int64, v float64) error
return curMF.Add(metricName, ls, t, v)
}

// appendMetrics appends all metrics to the given slice.
// getMetrics returns all metrics to the given slice.
// The only error returned by this function is errNoDataToBuild.
func (b *metricBuilder) appendMetrics(metrics pmetric.MetricSlice) error {
func (b *metricBuilder) getMetrics(resource pcommon.Resource) (pmetric.Metrics, error) {
if len(b.families) == 0 {
return errNoDataToBuild
return pmetric.Metrics{}, errNoDataToBuild
}

md := pmetric.NewMetrics()
rms := md.ResourceMetrics().AppendEmpty()
resource.CopyTo(rms.Resource())
metrics := rms.ScopeMetrics().AppendEmpty().Metrics()

for _, mf := range b.families {
mf.appendMetric(metrics)
}

return nil
return md, nil
}
Loading

0 comments on commit ba84168

Please sign in to comment.