MCPcopy Index your code
hub / github.com/cloudflare/ebpf_exporter / DecodeLabelsForMetrics

Method DecodeLabelsForMetrics

decoder/decoder.go:103–135  ·  view source on GitHub ↗

DecodeLabelsForMetrics transforms eBPF map key bytes into a list of label values according to configuration (different label sets require different names). This decoder method variant does caching and is suitable for metrics.

(in []byte, name string, labels []config.Label)

Source from the content-addressed store, hash-verified

101// according to configuration (different label sets require different names).
102// This decoder method variant does caching and is suitable for metrics.
103func (s *Set) DecodeLabelsForMetrics(in []byte, name string, labels []config.Label) ([]string, error) {
104 s.mu.Lock()
105 defer s.mu.Unlock()
106
107 cache, ok := s.cache[name]
108 if !ok {
109 cache = map[string][]string{}
110 s.cache[name] = cache
111 }
112
113 // string(in) must not be a variable to avoid allocation:
114 // * https://github.com/golang/go/commit/f5f5a8b6209f8
115 if cached, ok := cache[string(in)]; ok {
116 return cached, nil
117 }
118
119 // Also check the skip cache if the input would have return ErrSkipLabelSet
120 // and return the error early.
121 if s.skipCache != nil {
122 if _, ok := s.skipCache.Get(string(in)); ok {
123 return nil, ErrSkipLabelSet
124 }
125 }
126
127 values, err := s.decodeLabels(in, labels)
128 if err != nil {
129 return nil, err
130 }
131
132 cache[string(in)] = values
133
134 return values, nil
135}
136
137// DecodeLabelsForTracing transforms eBPF map key bytes into a list of label values
138// according to configuration (different label sets require different names).

Callers 7

TestDecodeLabelsFunction · 0.95
TestDecodeSkipLabelsFunction · 0.95
TestDecoderSetCacheFunction · 0.95
BenchmarkCacheFunction · 0.95
newPerfEventArraySinkFunction · 0.80
mapValuesMethod · 0.80

Calls 1

decodeLabelsMethod · 0.95

Tested by 5

TestDecodeLabelsFunction · 0.76
TestDecodeSkipLabelsFunction · 0.76
TestDecoderSetCacheFunction · 0.76
BenchmarkCacheFunction · 0.76