k8s.io/apiserver@v0.31.1/pkg/util/flowcontrol/metrics/interface.go (about)

     1  /*
     2  Copyright 2019 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  // Gauge is the methods of a gauge that are used by instrumented code.
    20  type Gauge interface {
    21  	Set(float64)
    22  	Inc()
    23  	Dec()
    24  	Add(float64)
    25  	SetToCurrentTime()
    26  }
    27  
    28  // RatioedGauge tracks ratios.
    29  // The numerator is set/changed through the Gauge methods,
    30  // and the denominator can be updated through the SetDenominator method.
    31  // A ratio is tracked whenever the numerator or denominator is set/changed.
    32  type RatioedGauge interface {
    33  	Gauge
    34  
    35  	// SetDenominator sets the denominator to use until it is changed again
    36  	SetDenominator(float64)
    37  }
    38  
    39  // RatioedGaugeVec creates related observers that are
    40  // differentiated by a series of label values
    41  type RatioedGaugeVec interface {
    42  	// NewForLabelValuesSafe makes a new vector member for the given tuple of label values,
    43  	// initialized with the given numerator and denominator.
    44  	// Unlike the usual Vec WithLabelValues method, this is intended to be called only
    45  	// once per vector member (at the start of its lifecycle).
    46  	// The "Safe" part is saying that the returned object will function properly after metric registration
    47  	// even if this method is called before registration.
    48  	NewForLabelValuesSafe(initialNumerator, initialDenominator float64, labelValues []string) RatioedGauge
    49  }
    50  
    51  //////////////////////////////// Pairs ////////////////////////////////
    52  //
    53  // API Priority and Fairness tends to use RatioedGaugeVec members in pairs,
    54  // one for requests waiting in a queue and one for requests being executed.
    55  // The following definitions are a convenience layer that adds support for that
    56  // particular pattern of usage.
    57  
    58  // RatioedGaugePair is a corresponding pair of gauges, one for the
    59  // number of requests waiting in queue(s) and one for the number of
    60  // requests being executed.
    61  type RatioedGaugePair struct {
    62  	// RequestsWaiting is given observations of the number of currently queued requests
    63  	RequestsWaiting RatioedGauge
    64  
    65  	// RequestsExecuting is given observations of the number of requests currently executing
    66  	RequestsExecuting RatioedGauge
    67  }