...
1
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 }
67
View as plain text