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)
| 101 | // according to configuration (different label sets require different names). |
| 102 | // This decoder method variant does caching and is suitable for metrics. |
| 103 | func (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). |