forked from prometheus-community/rsyslog_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubernetes_test.go
121 lines (94 loc) · 3.71 KB
/
kubernetes_test.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import "testing"
var (
kubernetesLog = []byte(`{ "name": "mmkubernetes(https://host.domain.tld:6443)", "origin": "mmkubernetes", "recordseen": 477943, "namespacemetadatasuccess": 7, "namespacemetadatanotfound": 0, "namespacemetadatabusy": 0, "namespacemetadataerror": 0, "podmetadatasuccess": 26, "podmetadatanotfound": 0, "podmetadatabusy": 0, "podmetadataerror": 0 }`)
)
func TestNewKubernetesFromJSON(t *testing.T) {
logType := getStatType(kubernetesLog)
if logType != rsyslogKubernetes {
t.Errorf("detected pstat type should be %d but is %d", rsyslogKubernetes, logType)
}
pstat, err := newKubernetesFromJSON([]byte(kubernetesLog))
if err != nil {
t.Fatalf("expected parsing action not to fail, got: %v", err)
}
if want, got := "mmkubernetes(https://host.domain.tld:6443)", pstat.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := "https://host.domain.tld:6443", pstat.Url; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := int64(477943), pstat.RecordSeen; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(7), pstat.NamespaceMetaSuccess; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(0), pstat.NamespaceMetaNotFound; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(0), pstat.NamespaceMetaBusy; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(0), pstat.NamespaceMetaError; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(26), pstat.PodMetaSuccess; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(0), pstat.PodMetaNotFound; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(0), pstat.PodMetaBusy; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
if want, got := int64(0), pstat.PodMetaError; want != got {
t.Errorf("wanted '%d', got '%d'", want, got)
}
}
func TestKubernetesToPoints(t *testing.T) {
pstat, err := newKubernetesFromJSON([]byte(kubernetesLog))
if err != nil {
t.Fatalf("expected parsing action not to fail, got: %v", err)
}
points := pstat.toPoints()
point := points[0]
if want, got := "kubernetes_namespace_metadata_success_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
if want, got := "https://host.domain.tld:6443", point.LabelValue; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
point = points[1]
if want, got := "kubernetes_namespace_metadata_notfound_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
point = points[2]
if want, got := "kubernetes_namespace_metadata_busy_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
point = points[3]
if want, got := "kubernetes_namespace_metadata_error_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
point = points[4]
if want, got := "kubernetes_pod_metadata_success_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
point = points[5]
if want, got := "kubernetes_pod_metadata_notfound_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
point = points[6]
if want, got := "kubernetes_pod_metadata_busy_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
point = points[7]
if want, got := "kubernetes_pod_metadata_error_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
point = points[8]
if want, got := "kubernetes_record_seen_total", point.Name; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
}