github.com/grafana/pyroscope@v1.18.0/pkg/model/sampletype/relabel.go (about) 1 package sampletype 2 3 import ( 4 typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1" 5 "github.com/grafana/pyroscope/pkg/slices" 6 "github.com/grafana/pyroscope/pkg/validation" 7 8 "github.com/prometheus/prometheus/model/relabel" 9 10 googlev1 "github.com/grafana/pyroscope/api/gen/proto/go/google/v1" 11 phlaremodel "github.com/grafana/pyroscope/pkg/model" 12 phlarerelabel "github.com/grafana/pyroscope/pkg/model/relabel" 13 ) 14 15 func Relabel(p validation.ValidatedProfile, rules []*relabel.Config, labels []*typesv1.LabelPair) { 16 if len(rules) == 0 { 17 return 18 } 19 keeps := make([]bool, len(p.SampleType)) 20 for i, st := range p.SampleType { 21 lb := phlaremodel.NewLabelsBuilder(labels) 22 lb.Set("__type__", p.StringTable[st.Type]) 23 lb.Set("__unit__", p.StringTable[st.Unit]) 24 _, keep := phlarerelabel.Process(lb.Labels(), rules...) 25 keeps[i] = keep 26 } 27 p.SampleType = slices.RemoveInPlace(p.SampleType, func(_ *googlev1.ValueType, idx int) bool { 28 return !keeps[idx] 29 }) 30 for _, sample := range p.Sample { 31 sample.Value = slices.RemoveInPlace(sample.Value, func(_ int64, idx int) bool { 32 return !keeps[idx] 33 }) 34 } 35 }