(out *dto.Metric)
| 321 | } |
| 322 | |
| 323 | func (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 | |
| 364 | func (s *summary) newStream() *quantile.Stream { |
| 365 | return quantile.NewTargeted(s.objectives) |
nothing calls this directly
no test coverage detected