MCPcopy Create free account
hub / github.com/prometheus/common / writeSample

Function writeSample

expfmt/text_create.go:300–343  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

298// the value. The function returns the number of bytes written and any error
299// encountered.
300func 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

Callers 1

MetricFamilyToTextFunction · 0.85

Calls 4

writeNameAndLabelPairsFunction · 0.85
writeFloatFunction · 0.85
writeIntFunction · 0.85
WriteByteMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…