writeOpenMetricsSample writes a single sample in OpenMetrics 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), the value (optionally as float64 or uint64, determined by
( w enhancedWriter, name, suffix string, metric *dto.Metric, additionalLabelName string, additionalLabelValue float64, floatValue float64, intValue uint64, useIntValue bool, exemplar *dto.Exemplar, )
| 395 | // useIntValue), and optionally an exemplar (use nil if not required). The |
| 396 | // function returns the number of bytes written and any error encountered. |
| 397 | func writeOpenMetricsSample( |
| 398 | w enhancedWriter, |
| 399 | name, suffix string, |
| 400 | metric *dto.Metric, |
| 401 | additionalLabelName string, additionalLabelValue float64, |
| 402 | floatValue float64, intValue uint64, useIntValue bool, |
| 403 | exemplar *dto.Exemplar, |
| 404 | ) (int, error) { |
| 405 | written := 0 |
| 406 | n, err := writeOpenMetricsNameAndLabelPairs( |
| 407 | w, name+suffix, metric.Label, additionalLabelName, additionalLabelValue, |
| 408 | ) |
| 409 | written += n |
| 410 | if err != nil { |
| 411 | return written, err |
| 412 | } |
| 413 | err = w.WriteByte(' ') |
| 414 | written++ |
| 415 | if err != nil { |
| 416 | return written, err |
| 417 | } |
| 418 | if useIntValue { |
| 419 | n, err = writeUint(w, intValue) |
| 420 | } else { |
| 421 | n, err = writeOpenMetricsFloat(w, floatValue) |
| 422 | } |
| 423 | written += n |
| 424 | if err != nil { |
| 425 | return written, err |
| 426 | } |
| 427 | if metric.TimestampMs != nil { |
| 428 | err = w.WriteByte(' ') |
| 429 | written++ |
| 430 | if err != nil { |
| 431 | return written, err |
| 432 | } |
| 433 | // TODO(beorn7): Format this directly without converting to a float first. |
| 434 | n, err = writeOpenMetricsFloat(w, float64(*metric.TimestampMs)/1000) |
| 435 | written += n |
| 436 | if err != nil { |
| 437 | return written, err |
| 438 | } |
| 439 | } |
| 440 | if exemplar != nil && len(exemplar.Label) > 0 { |
| 441 | n, err = writeExemplar(w, exemplar) |
| 442 | written += n |
| 443 | if err != nil { |
| 444 | return written, err |
| 445 | } |
| 446 | } |
| 447 | err = w.WriteByte('\n') |
| 448 | written++ |
| 449 | if err != nil { |
| 450 | return written, err |
| 451 | } |
| 452 | return written, nil |
| 453 | } |
| 454 |
no test coverage detected