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

Struct histogram

prometheus/histogram.go:708–760  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706}
707
708type histogram struct {
709 // countAndHotIdx enables lock-free writes with use of atomic updates.
710 // The most significant bit is the hot index [0 or 1] of the count field
711 // below. Observe calls update the hot one. All remaining bits count the
712 // number of Observe calls. Observe starts by incrementing this counter,
713 // and finish by incrementing the count field in the respective
714 // histogramCounts, as a marker for completion.
715 //
716 // Calls of the Write method (which are non-mutating reads from the
717 // perspective of the histogram) swap the hot–cold under the writeMtx
718 // lock. A cooldown is awaited (while locked) by comparing the number of
719 // observations with the initiation count. Once they match, then the
720 // last observation on the now cool one has completed. All cold fields must
721 // be merged into the new hot before releasing writeMtx.
722 //
723 // Fields with atomic access first! See alignment constraint:
724 // http://golang.org/pkg/sync/atomic/#pkg-note-BUG
725 countAndHotIdx uint64
726
727 selfCollector
728 desc *Desc
729
730 // Only used in the Write method and for sparse bucket management.
731 mtx sync.Mutex
732
733 // Two counts, one is "hot" for lock-free observations, the other is
734 // "cold" for writing out a dto.Metric. It has to be an array of
735 // pointers to guarantee 64bit alignment of the histogramCounts, see
736 // http://golang.org/pkg/sync/atomic/#pkg-note-BUG.
737 counts [2]*histogramCounts
738
739 upperBounds []float64
740 labelPairs []*dto.LabelPair
741 exemplars []atomic.Value // One more than buckets (to include +Inf), each a *dto.Exemplar.
742 nativeHistogramSchema int32 // The initial schema. Set to math.MinInt32 if no sparse buckets are used.
743 nativeHistogramZeroThreshold float64 // The initial zero threshold.
744 nativeHistogramMaxZeroThreshold float64
745 nativeHistogramMaxBuckets uint32
746 nativeHistogramMinResetDuration time.Duration
747 // lastResetTime is protected by mtx. It is also used as created timestamp.
748 lastResetTime time.Time
749 // resetScheduled is protected by mtx. It is true if a reset is
750 // scheduled for a later time (when nativeHistogramMinResetDuration has
751 // passed).
752 resetScheduled bool
753 nativeExemplars nativeExemplars
754
755 // now is for testing purposes, by default it's time.Now.
756 now func() time.Time
757
758 // afterFunc is for testing purposes, by default it's time.AfterFunc.
759 afterFunc func(time.Duration, func()) *time.Timer
760}
761
762func (h *histogram) Desc() *Desc {
763 return h.desc

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected