...

Source file src/k8s.io/component-base/metrics/buckets.go

Documentation: k8s.io/component-base/metrics

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package metrics
    18  
    19  import (
    20  	"github.com/prometheus/client_golang/prometheus"
    21  )
    22  
    23  // DefBuckets is a wrapper for prometheus.DefBuckets
    24  var DefBuckets = prometheus.DefBuckets
    25  
    26  // LinearBuckets is a wrapper for prometheus.LinearBuckets.
    27  func LinearBuckets(start, width float64, count int) []float64 {
    28  	return prometheus.LinearBuckets(start, width, count)
    29  }
    30  
    31  // ExponentialBuckets is a wrapper for prometheus.ExponentialBuckets.
    32  func ExponentialBuckets(start, factor float64, count int) []float64 {
    33  	return prometheus.ExponentialBuckets(start, factor, count)
    34  }
    35  
    36  // ExponentialBucketsRange creates 'count' buckets, where the lowest bucket is
    37  // 'min' and the highest bucket is 'max'. The final +Inf bucket is not counted
    38  // and not included in the returned slice. The returned slice is meant to be
    39  // used for the Buckets field of HistogramOpts.
    40  //
    41  // The function panics if 'count' is 0 or negative, if 'min' is 0 or negative.
    42  func ExponentialBucketsRange(min, max float64, count int) []float64 {
    43  	return prometheus.ExponentialBucketsRange(min, max, count)
    44  }
    45  
    46  // MergeBuckets merges buckets together
    47  func MergeBuckets(buckets ...[]float64) []float64 {
    48  	result := make([]float64, 1)
    49  	for _, s := range buckets {
    50  		result = append(result, s...)
    51  	}
    52  	return result
    53  }
    54  

View as plain text