Labels writes the labels of the current sample into the passed labels.
(l *labels.Labels)
| 213 | |
| 214 | // Labels writes the labels of the current sample into the passed labels. |
| 215 | func (p *OpenMetricsParser) Labels(l *labels.Labels) { |
| 216 | // Defensive copy in case the following keeps a reference. |
| 217 | // See https://github.com/prometheus/prometheus/issues/16490 |
| 218 | s := string(p.series) |
| 219 | |
| 220 | p.builder.Reset() |
| 221 | metricName := unreplace(s[p.offsets[0]-p.start : p.offsets[1]-p.start]) |
| 222 | |
| 223 | m := schema.Metadata{ |
| 224 | Name: metricName, |
| 225 | Type: p.mtype, |
| 226 | Unit: p.unit, |
| 227 | } |
| 228 | if p.enableTypeAndUnitLabels { |
| 229 | m.AddToLabels(&p.builder) |
| 230 | } else { |
| 231 | p.builder.Add(labels.MetricName, metricName) |
| 232 | } |
| 233 | for i := 2; i < len(p.offsets); i += 4 { |
| 234 | a := p.offsets[i] - p.start |
| 235 | b := p.offsets[i+1] - p.start |
| 236 | label := unreplace(s[a:b]) |
| 237 | if p.enableTypeAndUnitLabels && !m.IsEmptyFor(label) { |
| 238 | // Dropping user provided metadata labels, if found in the OM metadata. |
| 239 | continue |
| 240 | } |
| 241 | c := p.offsets[i+2] - p.start |
| 242 | d := p.offsets[i+3] - p.start |
| 243 | value := normalizeFloatsInLabelValues(p.mtype, label, unreplace(s[c:d])) |
| 244 | p.builder.Add(label, value) |
| 245 | } |
| 246 | |
| 247 | p.builder.Sort() |
| 248 | *l = p.builder.Labels() |
| 249 | } |
| 250 | |
| 251 | // Exemplar writes the exemplar of the current sample into the passed exemplar. |
| 252 | // It returns whether an exemplar exists. As OpenMetrics only ever has one |