File: testing.go

package info (click to toggle)
mtail 3.2.24-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,384 kB
  • sloc: yacc: 647; makefile: 226; sh: 78; lisp: 77; awk: 17
file content (73 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2021 Google Inc. All Rights Reserved.
// This file is available under the Apache license.

package metrics

type MetricSlice []*Metric

func (s MetricSlice) Len() int      { return len(s) }
func (s MetricSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s MetricSlice) Less(i, j int) bool {
	return Less(s[i], s[j])
}

func Less(m1, m2 *Metric) bool {
	if m1.Name < m2.Name {
		return true
	}
	if m1.Name > m2.Name {
		return false
	}
	if m1.Program < m2.Program {
		return true
	}
	if m1.Program > m2.Program {
		return false
	}
	if m1.Kind < m2.Kind {
		return true
	}
	if m1.Kind > m2.Kind {
		return false
	}
	if m1.Type < m2.Type {
		return true
	}
	if m1.Type > m2.Type {
		return false
	}
	if len(m1.Keys) < len(m2.Keys) {
		return true
	}
	if len(m1.Keys) > len(m2.Keys) {
		return false
	}
	for x, k := range m1.Keys {
		if k < m2.Keys[x] {
			return true
		}
		if k > m2.Keys[x] {
			return false
		}
	}
	for x, lv := range m1.LabelValues {
		if len(lv.Labels) < len(m2.LabelValues[x].Labels) {
			return true
		}
		if len(lv.Labels) > len(m2.LabelValues[x].Labels) {
			return false
		}
		for y, k := range lv.Labels {
			if k < m2.LabelValues[x].Labels[y] {
				return true
			}
			if k > m2.LabelValues[x].Labels[y] {
				return false
			}
		}
		// if lv.Value < m2.LabelValues[x].Value {
		// 	return true
		// }
	}
	return false
}