|
@@ -22,6 +22,7 @@ import (
|
22
|
22
|
"net"
|
23
|
23
|
_ "net/http/pprof"
|
24
|
24
|
"os"
|
|
25
|
+ "reflect"
|
25
|
26
|
"regexp"
|
26
|
27
|
"runtime"
|
27
|
28
|
"strconv"
|
|
@@ -1077,29 +1078,85 @@ func TestIdentifyNumLabelUnits(t *testing.T) {
|
1077
|
1078
|
wantIgnoreErrCount int
|
1078
|
1079
|
}{
|
1079
|
1080
|
{
|
1080
|
|
- "Multiple keys, different units",
|
1081
|
|
- []map[string][]int64{{"key1": {131072}, "key2": {128}}},
|
1082
|
|
- []map[string][]string{{"key1": {"bytes"}, "key2": {"kilobytes"}}},
|
1083
|
|
- map[string]string{"key1": "bytes", "key2": "kilobytes"},
|
|
1081
|
+ "Multiple keys, no units for all keys",
|
|
1082
|
+ []map[string][]int64{{"keyA": {131072}, "keyB": {128}}},
|
|
1083
|
+ []map[string][]string{{"keyA": {}, "keyB": {""}}},
|
|
1084
|
+ map[string]string{"keyA": "keyA", "keyB": "keyB"},
|
1084
|
1085
|
"",
|
1085
|
1086
|
0,
|
1086
|
1087
|
},
|
1087
|
1088
|
{
|
1088
|
|
- "One key with different units in same sample",
|
1089
|
|
- []map[string][]int64{{"key1": {8, 8}}},
|
1090
|
|
- []map[string][]string{{"key1": {"bytes", "kilobytes"}}},
|
1091
|
|
- map[string]string{"key1": "bytes"},
|
1092
|
|
- `(For tag key1 used unit bytes, also encountered unit\(s\) kilobytes)`,
|
|
1089
|
+ "Multiple keys, different units for each key",
|
|
1090
|
+ []map[string][]int64{{"keyA": {131072}, "keyB": {128}}},
|
|
1091
|
+ []map[string][]string{{"keyA": {"bytes"}, "keyB": {"kilobytes"}}},
|
|
1092
|
+ map[string]string{"keyA": "bytes", "keyB": "kilobytes"},
|
|
1093
|
+ "",
|
|
1094
|
+ 0,
|
|
1095
|
+ },
|
|
1096
|
+ {
|
|
1097
|
+ "Multiple keys with multiple values, different units for each key",
|
|
1098
|
+ []map[string][]int64{{"keyC": {131072, 1}, "keyD": {128, 252}}},
|
|
1099
|
+ []map[string][]string{{"keyC": {"bytes", "bytes"}, "keyD": {"kilobytes", "kilobytes"}}},
|
|
1100
|
+ map[string]string{"keyC": "bytes", "keyD": "kilobytes"},
|
|
1101
|
+ "",
|
|
1102
|
+ 0,
|
|
1103
|
+ },
|
|
1104
|
+ {
|
|
1105
|
+ "Multiple keys with multiple values, some units missing",
|
|
1106
|
+ []map[string][]int64{{"key1": {131072, 1}, "A": {128, 252}, "key3": {128}, "key4": {1}}, {"key3": {128}, "key4": {1}}},
|
|
1107
|
+ []map[string][]string{{"key1": {"", "bytes"}, "A": {"kilobytes", ""}, "key3": {""}, "key4": {"hour"}}, {"key3": {"seconds"}, "key4": {""}}},
|
|
1108
|
+ map[string]string{"key1": "bytes", "A": "kilobytes", "key3": "seconds", "key4": "hour"},
|
|
1109
|
+ "",
|
|
1110
|
+ 0,
|
|
1111
|
+ },
|
|
1112
|
+ {
|
|
1113
|
+ "One key with three units in same sample",
|
|
1114
|
+ []map[string][]int64{{"key": {8, 8, 16}}},
|
|
1115
|
+ []map[string][]string{{"key": {"bytes", "megabytes", "kilobytes"}}},
|
|
1116
|
+ map[string]string{"key": "bytes"},
|
|
1117
|
+ `(For tag key used unit bytes, also encountered unit\(s\) kilobytes, megabytes)`,
|
|
1118
|
+ 1,
|
|
1119
|
+ },
|
|
1120
|
+ {
|
|
1121
|
+ "One key with four units in same sample",
|
|
1122
|
+ []map[string][]int64{{"key": {8, 8, 16, 32}}},
|
|
1123
|
+ []map[string][]string{{"key": {"bytes", "kilobytes", "a", "megabytes"}}},
|
|
1124
|
+ map[string]string{"key": "bytes"},
|
|
1125
|
+ `(For tag key used unit bytes, also encountered unit\(s\) a, kilobytes, megabytes)`,
|
|
1126
|
+ 1,
|
|
1127
|
+ },
|
|
1128
|
+ {
|
|
1129
|
+ "One key with two units in same sample",
|
|
1130
|
+ []map[string][]int64{{"key": {8, 8}}},
|
|
1131
|
+ []map[string][]string{{"key": {"bytes", "seconds"}}},
|
|
1132
|
+ map[string]string{"key": "bytes"},
|
|
1133
|
+ `(For tag key used unit bytes, also encountered unit\(s\) seconds)`,
|
1093
|
1134
|
1,
|
1094
|
1135
|
},
|
1095
|
1136
|
{
|
1096
|
1137
|
"One key with different units in different samples",
|
1097
|
|
- []map[string][]int64{{"key1": {8}}, {"key1": {8}}},
|
1098
|
|
- []map[string][]string{{"key1": {"bytes"}}, {"key1": {"kilobytes"}}},
|
|
1138
|
+ []map[string][]int64{{"key1": {8}}, {"key1": {8}}, {"key1": {8}}},
|
|
1139
|
+ []map[string][]string{{"key1": {"bytes"}}, {"key1": {"kilobytes"}}, {"key1": {"megabytes"}}},
|
1099
|
1140
|
map[string]string{"key1": "bytes"},
|
1100
|
|
- `(For tag key1 used unit bytes, also encountered unit\(s\) kilobytes)`,
|
|
1141
|
+ `(For tag key1 used unit bytes, also encountered unit\(s\) kilobytes, megabytes)`,
|
1101
|
1142
|
1,
|
1102
|
1143
|
},
|
|
1144
|
+ {
|
|
1145
|
+ "Key alignment, unit not specified",
|
|
1146
|
+ []map[string][]int64{{"alignment": {8}}},
|
|
1147
|
+ []map[string][]string{nil},
|
|
1148
|
+ map[string]string{"alignment": "bytes"},
|
|
1149
|
+ "",
|
|
1150
|
+ 0,
|
|
1151
|
+ },
|
|
1152
|
+ {
|
|
1153
|
+ "Key request, unit not specified",
|
|
1154
|
+ []map[string][]int64{{"request": {8}}, {"request": {8, 8}}},
|
|
1155
|
+ []map[string][]string{nil, nil},
|
|
1156
|
+ map[string]string{"request": "bytes"},
|
|
1157
|
+ "",
|
|
1158
|
+ 0,
|
|
1159
|
+ },
|
1103
|
1160
|
{
|
1104
|
1161
|
"Check units not over-written for keys with default units",
|
1105
|
1162
|
[]map[string][]int64{{
|
|
@@ -1133,11 +1190,8 @@ func TestIdentifyNumLabelUnits(t *testing.T) {
|
1133
|
1190
|
}
|
1134
|
1191
|
testUI := &proftest.TestUI{T: t, AllowRx: test.allowedRx}
|
1135
|
1192
|
units := identifyNumLabelUnits(&p, testUI)
|
1136
|
|
- for key, wantUnit := range test.wantUnits {
|
1137
|
|
- unit := units[key]
|
1138
|
|
- if wantUnit != unit {
|
1139
|
|
- t.Errorf("for key %s, got unit %s, want unit %s", key, unit, wantUnit)
|
1140
|
|
- }
|
|
1193
|
+ if !reflect.DeepEqual(test.wantUnits, units) {
|
|
1194
|
+ t.Errorf("got %v units, want %v", units, test.wantUnits)
|
1141
|
1195
|
}
|
1142
|
1196
|
if got, want := testUI.NumAllowRxMatches, test.wantIgnoreErrCount; want != got {
|
1143
|
1197
|
t.Errorf("got %d errors logged, want %d errors logged", got, want)
|