MCPcopy
hub / github.com/prometheus/client_golang / Write

Method Write

prometheus/summary.go:323–362  ·  view source on GitHub ↗
(out *dto.Metric)

Source from the content-addressed store, hash-verified

321}
322
323func (s *summary) Write(out *dto.Metric) error {
324 sum := &dto.Summary{
325 CreatedTimestamp: s.createdTs,
326 }
327 qs := make([]*dto.Quantile, 0, len(s.objectives))
328
329 s.bufMtx.Lock()
330 s.mtx.Lock()
331 // Swap bufs even if hotBuf is empty to set new hotBufExpTime.
332 s.swapBufs(s.now())
333 s.bufMtx.Unlock()
334
335 s.flushColdBuf()
336 sum.SampleCount = proto.Uint64(s.cnt)
337 sum.SampleSum = proto.Float64(s.sum)
338
339 for _, rank := range s.sortedObjectives {
340 var q float64
341 if s.headStream.Count() == 0 {
342 q = math.NaN()
343 } else {
344 q = s.headStream.Query(rank)
345 }
346 qs = append(qs, &dto.Quantile{
347 Quantile: proto.Float64(rank),
348 Value: proto.Float64(q),
349 })
350 }
351
352 s.mtx.Unlock()
353
354 if len(qs) > 0 {
355 sort.Sort(quantSort(qs))
356 }
357 sum.Quantile = qs
358
359 out.Summary = sum
360 out.Label = s.labelPairs
361 return nil
362}
363
364func (s *summary) newStream() *quantile.Stream {
365 return quantile.NewTargeted(s.objectives)

Callers

nothing calls this directly

Calls 4

swapBufsMethod · 0.95
flushColdBufMethod · 0.95
quantSortTypeAlias · 0.85
QueryMethod · 0.65

Tested by

no test coverage detected