Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions receiver/prometheusreceiver/internal/metricfamily.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,19 @@ func populateAttributes(mType pmetric.MetricType, ls labels.Labels, dest pcommon
dest.EnsureCapacity(ls.Len())
names := getSortedNotUsefulLabels(mType)
j := 0
for i := range ls {
for j < len(names) && names[j] < ls[i].Name {
ls.Range(func(l labels.Label) {
for j < len(names) && names[j] < l.Name {
j++
}
if j < len(names) && ls[i].Name == names[j] {
continue
if j < len(names) && l.Name == names[j] {
return
}
if ls[i].Value == "" {
if l.Value == "" {
// empty label values should be omitted
continue
return
}
dest.PutStr(ls[i].Name, ls[i].Value)
}
dest.PutStr(l.Name, l.Value)
})
}

func (mf *metricFamily) loadMetricGroupOrCreate(groupKey uint64, ls labels.Labels, ts int64) *metricGroup {
Expand Down Expand Up @@ -382,8 +382,8 @@ func (mf *metricFamily) addExemplar(seriesRef uint64, e exemplar.Exemplar) {
func convertExemplar(pe exemplar.Exemplar, e pmetric.Exemplar) {
e.SetTimestamp(timestampFromMs(pe.Ts))
e.SetDoubleValue(pe.Value)
e.FilteredAttributes().EnsureCapacity(len(pe.Labels))
for _, lb := range pe.Labels {
e.FilteredAttributes().EnsureCapacity(pe.Labels.Len())
pe.Labels.Range(func(lb labels.Label) {
switch strings.ToLower(lb.Name) {
case traceIDKey:
var tid [16]byte
Expand All @@ -404,7 +404,7 @@ func convertExemplar(pe exemplar.Exemplar, e pmetric.Exemplar) {
default:
e.FilteredAttributes().PutStr(lb.Name, lb.Value)
}
}
})
}

/*
Expand Down
34 changes: 18 additions & 16 deletions receiver/prometheusreceiver/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"sort"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/exemplar"
Expand Down Expand Up @@ -91,9 +90,12 @@ func (t *transaction) Append(_ storage.SeriesRef, ls labels.Labels, atMs int64,
default:
}

if len(t.externalLabels) != 0 {
ls = append(ls, t.externalLabels...)
sort.Sort(ls)
if t.externalLabels.Len() != 0 {
b := labels.NewBuilder(ls)
t.externalLabels.Range(func(l labels.Label) {
b.Set(l.Name, l.Value)
})
ls = b.Labels()
}

if t.isNew {
Expand Down Expand Up @@ -254,14 +256,14 @@ func (t *transaction) getMetrics(resource pcommon.Resource) (pmetric.Metrics, er

func getScopeID(ls labels.Labels) scopeID {
var scope scopeID
for _, lbl := range ls {
ls.Range(func(lbl labels.Label) {
if lbl.Name == scopeNameLabel {
scope.name = lbl.Value
}
if lbl.Name == scopeVersionLabel {
scope.version = lbl.Value
}
}
})
return scope
}

Expand Down Expand Up @@ -320,33 +322,33 @@ func (t *transaction) UpdateMetadata(_ storage.SeriesRef, _ labels.Labels, _ met
return 0, nil
}

func (t *transaction) AddTargetInfo(labels labels.Labels) {
func (t *transaction) AddTargetInfo(ls labels.Labels) {
attrs := t.nodeResource.Attributes()
for _, lbl := range labels {
ls.Range(func(lbl labels.Label) {
if lbl.Name == model.JobLabel || lbl.Name == model.InstanceLabel || lbl.Name == model.MetricNameLabel {
continue
return
}
attrs.PutStr(lbl.Name, lbl.Value)
}
})
}

func (t *transaction) addScopeInfo(labels labels.Labels) {
func (t *transaction) addScopeInfo(ls labels.Labels) {
attrs := pcommon.NewMap()
scope := scopeID{}
for _, lbl := range labels {
ls.Range(func(lbl labels.Label) {
if lbl.Name == model.JobLabel || lbl.Name == model.InstanceLabel || lbl.Name == model.MetricNameLabel {
continue
return
}
if lbl.Name == scopeNameLabel {
scope.name = lbl.Value
continue
return
}
if lbl.Name == scopeVersionLabel {
scope.version = lbl.Value
continue
return
}
attrs.PutStr(lbl.Name, lbl.Value)
}
})
t.scopeAttributes[scope] = attrs
}

Expand Down
Loading