writeSample writes a single sample in text format to w, given the metric name, the metric proto message itself, optionally an additional label name with a float64 value (use empty string as label name if not required), and the value. The function returns the number of bytes written and any error enc
( w enhancedWriter, name, suffix string, metric *dto.Metric, additionalLabelName string, additionalLabelValue float64, value float64, )
| 298 | // the value. The function returns the number of bytes written and any error |
| 299 | // encountered. |
| 300 | func writeSample( |
| 301 | w enhancedWriter, |
| 302 | name, suffix string, |
| 303 | metric *dto.Metric, |
| 304 | additionalLabelName string, additionalLabelValue float64, |
| 305 | value float64, |
| 306 | ) (int, error) { |
| 307 | written := 0 |
| 308 | n, err := writeNameAndLabelPairs( |
| 309 | w, name+suffix, metric.Label, additionalLabelName, additionalLabelValue, |
| 310 | ) |
| 311 | written += n |
| 312 | if err != nil { |
| 313 | return written, err |
| 314 | } |
| 315 | err = w.WriteByte(' ') |
| 316 | written++ |
| 317 | if err != nil { |
| 318 | return written, err |
| 319 | } |
| 320 | n, err = writeFloat(w, value) |
| 321 | written += n |
| 322 | if err != nil { |
| 323 | return written, err |
| 324 | } |
| 325 | if metric.TimestampMs != nil { |
| 326 | err = w.WriteByte(' ') |
| 327 | written++ |
| 328 | if err != nil { |
| 329 | return written, err |
| 330 | } |
| 331 | n, err = writeInt(w, *metric.TimestampMs) |
| 332 | written += n |
| 333 | if err != nil { |
| 334 | return written, err |
| 335 | } |
| 336 | } |
| 337 | err = w.WriteByte('\n') |
| 338 | written++ |
| 339 | if err != nil { |
| 340 | return written, err |
| 341 | } |
| 342 | return written, nil |
| 343 | } |
| 344 | |
| 345 | // writeNameAndLabelPairs converts a slice of LabelPair proto messages plus the |
| 346 | // explicitly given metric name and additional label pair into text formatted as |
no test coverage detected
searching dependent graphs…