metric.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package main
  14. import (
  15. "k8s.io/component-base/metrics"
  16. )
  17. const (
  18. counterMetricType = "Counter"
  19. gaugeMetricType = "Gauge"
  20. histogramMetricType = "Histogram"
  21. )
  22. type metric struct {
  23. Name string `yaml:"name"`
  24. Subsystem string `yaml:"subsystem,omitempty"`
  25. Namespace string `yaml:"namespace,omitempty"`
  26. Help string `yaml:"help,omitempty"`
  27. Type string `yaml:"type,omitempty"`
  28. DeprecatedVersion string `yaml:"deprecatedVersion,omitempty"`
  29. StabilityLevel string `yaml:"stabilityLevel,omitempty"`
  30. Labels []string `yaml:"labels,omitempty"`
  31. Buckets []float64 `yaml:"buckets,omitempty"`
  32. }
  33. func (m metric) buildFQName() string {
  34. return metrics.BuildFQName(m.Namespace, m.Subsystem, m.Name)
  35. }
  36. type byFQName []metric
  37. func (ms byFQName) Len() int { return len(ms) }
  38. func (ms byFQName) Less(i, j int) bool {
  39. return ms[i].buildFQName() < ms[j].buildFQName()
  40. }
  41. func (ms byFQName) Swap(i, j int) {
  42. ms[i], ms[j] = ms[j], ms[i]
  43. }