k8s.io/kubernetes@v1.29.3/test/instrumentation/metric.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 main
    18  
    19  import (
    20  	"k8s.io/component-base/metrics"
    21  )
    22  
    23  const (
    24  	counterMetricType    = "Counter"
    25  	gaugeMetricType      = "Gauge"
    26  	histogramMetricType  = "Histogram"
    27  	summaryMetricType    = "Summary"
    28  	timingRatioHistogram = "TimingRatioHistogram"
    29  	customType           = "Custom"
    30  )
    31  
    32  type metric struct {
    33  	Name              string              `yaml:"name" json:"name"`
    34  	Subsystem         string              `yaml:"subsystem,omitempty" json:"subsystem,omitempty"`
    35  	Namespace         string              `yaml:"namespace,omitempty" json:"namespace,omitempty"`
    36  	Help              string              `yaml:"help,omitempty" json:"help,omitempty"`
    37  	Type              string              `yaml:"type,omitempty" json:"type,omitempty"`
    38  	DeprecatedVersion string              `yaml:"deprecatedVersion,omitempty" json:"deprecatedVersion,omitempty"`
    39  	StabilityLevel    string              `yaml:"stabilityLevel,omitempty" json:"stabilityLevel,omitempty"`
    40  	Labels            []string            `yaml:"labels,omitempty" json:"labels,omitempty"`
    41  	Buckets           []float64           `yaml:"buckets,omitempty" json:"buckets,omitempty"`
    42  	Objectives        map[float64]float64 `yaml:"objectives,omitempty" json:"objectives,omitempty"`
    43  	AgeBuckets        uint32              `yaml:"ageBuckets,omitempty" json:"ageBuckets,omitempty"`
    44  	BufCap            uint32              `yaml:"bufCap,omitempty" json:"bufCap,omitempty"`
    45  	MaxAge            int64               `yaml:"maxAge,omitempty" json:"maxAge,omitempty"`
    46  	ConstLabels       map[string]string   `yaml:"constLabels,omitempty" json:"constLabels,omitempty"`
    47  }
    48  
    49  func (m metric) buildFQName() string {
    50  	return metrics.BuildFQName(m.Namespace, m.Subsystem, m.Name)
    51  }
    52  
    53  type byFQName []metric
    54  
    55  func (ms byFQName) Len() int { return len(ms) }
    56  func (ms byFQName) Less(i, j int) bool {
    57  	if ms[i].StabilityLevel < ms[j].StabilityLevel {
    58  		return true
    59  	} else if ms[i].StabilityLevel > ms[j].StabilityLevel {
    60  		return false
    61  	}
    62  	return ms[i].buildFQName() < ms[j].buildFQName()
    63  }
    64  func (ms byFQName) Swap(i, j int) {
    65  	ms[i], ms[j] = ms[j], ms[i]
    66  }