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

Function newHistogram

prometheus/histogram.go:535–611  ·  view source on GitHub ↗
(desc *Desc, opts HistogramOpts, labelValues ...string)

Source from the content-addressed store, hash-verified

533}
534
535func newHistogram(desc *Desc, opts HistogramOpts, labelValues ...string) Histogram {
536 if len(desc.variableLabels.names) != len(labelValues) {
537 panic(makeInconsistentCardinalityError(desc.fqName, desc.variableLabels.names, labelValues))
538 }
539
540 for _, n := range desc.variableLabels.names {
541 if n == bucketLabel {
542 panic(errBucketLabelNotAllowed)
543 }
544 }
545 for _, lp := range desc.constLabelPairs {
546 if lp.GetName() == bucketLabel {
547 panic(errBucketLabelNotAllowed)
548 }
549 }
550
551 if opts.now == nil {
552 opts.now = time.Now
553 }
554 if opts.afterFunc == nil {
555 opts.afterFunc = time.AfterFunc
556 }
557
558 h := &histogram{
559 desc: desc,
560 upperBounds: opts.Buckets,
561 labelPairs: MakeLabelPairs(desc, labelValues),
562 nativeHistogramMaxBuckets: opts.NativeHistogramMaxBucketNumber,
563 nativeHistogramMaxZeroThreshold: opts.NativeHistogramMaxZeroThreshold,
564 nativeHistogramMinResetDuration: opts.NativeHistogramMinResetDuration,
565 lastResetTime: opts.now(),
566 now: opts.now,
567 afterFunc: opts.afterFunc,
568 }
569 if len(h.upperBounds) == 0 && opts.NativeHistogramBucketFactor <= 1 {
570 h.upperBounds = DefBuckets
571 }
572 if opts.NativeHistogramBucketFactor <= 1 {
573 h.nativeHistogramSchema = math.MinInt32 // To mark that there are no sparse buckets.
574 } else {
575 switch {
576 case opts.NativeHistogramZeroThreshold > 0:
577 h.nativeHistogramZeroThreshold = opts.NativeHistogramZeroThreshold
578 case opts.NativeHistogramZeroThreshold == 0:
579 h.nativeHistogramZeroThreshold = DefNativeHistogramZeroThreshold
580 } // Leave h.nativeHistogramZeroThreshold at 0 otherwise.
581 h.nativeHistogramSchema = pickSchema(opts.NativeHistogramBucketFactor)
582 h.nativeExemplars = makeNativeExemplars(opts.NativeHistogramExemplarTTL, opts.NativeHistogramMaxExemplars)
583 }
584 for i, upperBound := range h.upperBounds {
585 if i < len(h.upperBounds)-1 {
586 if upperBound >= h.upperBounds[i+1] {
587 panic(fmt.Errorf(
588 "histogram buckets must be in increasing order: %f >= %f",
589 upperBound, h.upperBounds[i+1],
590 ))
591 }
592 } else {

Callers 2

NewHistogramFunction · 0.85
NewHistogramVecMethod · 0.85

Calls 5

MakeLabelPairsFunction · 0.85
pickSchemaFunction · 0.85
makeNativeExemplarsFunction · 0.85
initMethod · 0.80

Tested by

no test coverage detected