MCPcopy
hub / github.com/prometheus/prometheus / add

Method add

storage/buffer.go:467–526  ·  view source on GitHub ↗

add adds a sample to the ring buffer and frees all samples that fall out of the delta range. Note that this method works for any sample implementation. If you know you are dealing with one of the implementations from this package (fSample, hSample, fhSample), call one of the specialized methods addF

(s chunks.Sample)

Source from the content-addressed store, hash-verified

465// from this package (fSample, hSample, fhSample), call one of the specialized
466// methods addF, addH, or addFH for better performance.
467func (r *sampleRing) add(s chunks.Sample) {
468 if r.bufInUse == noBuf {
469 // First sample.
470 switch s := s.(type) {
471 case fSample:
472 r.bufInUse = fBuf
473 r.fBuf = addF(s, r.fBuf, r)
474 case hSample:
475 r.bufInUse = hBuf
476 r.hBuf = addH(s, r.hBuf, r)
477 case fhSample:
478 r.bufInUse = fhBuf
479 r.fhBuf = addFH(s, r.fhBuf, r)
480 }
481 return
482 }
483 if r.bufInUse != iBuf {
484 // Nothing added to the interface buf yet. Let's check if we can
485 // stay specialized.
486 switch s := s.(type) {
487 case fSample:
488 if r.bufInUse == fBuf {
489 r.fBuf = addF(s, r.fBuf, r)
490 return
491 }
492 case hSample:
493 if r.bufInUse == hBuf {
494 r.hBuf = addH(s, r.hBuf, r)
495 return
496 }
497 case fhSample:
498 if r.bufInUse == fhBuf {
499 r.fhBuf = addFH(s, r.fhBuf, r)
500 return
501 }
502 }
503 // The new sample isn't a fit for the already existing
504 // ones. Copy the latter into the interface buffer where needed.
505 // The interface buffer is assumed to be of length zero at this point.
506 switch r.bufInUse {
507 case fBuf:
508 for _, s := range r.fBuf {
509 r.iBuf = append(r.iBuf, s)
510 }
511 r.fBuf = nil
512 case hBuf:
513 for _, s := range r.hBuf {
514 r.iBuf = append(r.iBuf, s)
515 }
516 r.hBuf = nil
517 case fhBuf:
518 for _, s := range r.fhBuf {
519 r.iBuf = append(r.iBuf, s)
520 }
521 r.fhBuf = nil
522 }
523 r.bufInUse = iBuf
524 }

Callers 3

addFMethod · 0.95
addHMethod · 0.95
addFHMethod · 0.95

Calls 4

addFFunction · 0.85
addHFunction · 0.85
addFHFunction · 0.85
addSampleFunction · 0.85

Tested by

no test coverage detected