@@ -128,8 +128,8 @@ func TestBlockedResourceStats_New(t *testing.T) {
128
128
a := NewBlockedResourcesStats ()
129
129
require .NotNil (t , a .ByJob )
130
130
require .Empty (t , a .ByJob )
131
- require .NotNil (t , a .ByNode )
132
- require .Empty (t , a .ByNode )
131
+ require .NotNil (t , a .ByClassInDC )
132
+ require .Empty (t , a .ByClassInDC )
133
133
}
134
134
135
135
var (
@@ -143,15 +143,20 @@ var (
143
143
Namespace : "two" ,
144
144
}
145
145
146
- node1 = node {
146
+ node1 = classInDC {
147
147
dc : "dc1" ,
148
148
class : "alpha" ,
149
149
}
150
150
151
- node2 = node {
151
+ node2 = classInDC {
152
152
dc : "dc1" ,
153
153
class : "beta" ,
154
154
}
155
+
156
+ node3 = classInDC {
157
+ dc : "dc1" ,
158
+ class : "" , // not set
159
+ }
155
160
)
156
161
157
162
func TestBlockedResourceStats_Copy (t * testing.T ) {
@@ -166,7 +171,7 @@ func TestBlockedResourceStats_Copy(t *testing.T) {
166
171
MemoryMB : 256 ,
167
172
},
168
173
}
169
- a .ByNode = map [node ]BlockedResourcesSummary {
174
+ a .ByClassInDC = map [classInDC ]BlockedResourcesSummary {
170
175
node1 : {
171
176
Timestamp : now1 ,
172
177
CPU : 300 ,
@@ -180,23 +185,23 @@ func TestBlockedResourceStats_Copy(t *testing.T) {
180
185
CPU : 888 ,
181
186
MemoryMB : 888 ,
182
187
}
183
- c .ByNode [node1 ] = BlockedResourcesSummary {
188
+ c .ByClassInDC [node1 ] = BlockedResourcesSummary {
184
189
Timestamp : now2 ,
185
190
CPU : 999 ,
186
191
MemoryMB : 999 ,
187
192
}
188
193
189
194
// underlying data should have been deep copied
190
195
require .Equal (t , 100 , a .ByJob [id1 ].CPU )
191
- require .Equal (t , 300 , a .ByNode [node1 ].CPU )
196
+ require .Equal (t , 300 , a .ByClassInDC [node1 ].CPU )
192
197
}
193
198
194
199
func TestBlockedResourcesStats_Add (t * testing.T ) {
195
200
a := NewBlockedResourcesStats ()
196
201
a .ByJob = map [structs.NamespacedID ]BlockedResourcesSummary {
197
202
id1 : {Timestamp : now (1 ), CPU : 111 , MemoryMB : 222 },
198
203
}
199
- a .ByNode = map [node ]BlockedResourcesSummary {
204
+ a .ByClassInDC = map [classInDC ]BlockedResourcesSummary {
200
205
node1 : {Timestamp : now (2 ), CPU : 333 , MemoryMB : 444 },
201
206
}
202
207
@@ -205,7 +210,7 @@ func TestBlockedResourcesStats_Add(t *testing.T) {
205
210
id1 : {Timestamp : now (3 ), CPU : 200 , MemoryMB : 300 },
206
211
id2 : {Timestamp : now (4 ), CPU : 400 , MemoryMB : 500 },
207
212
}
208
- b .ByNode = map [node ]BlockedResourcesSummary {
213
+ b .ByClassInDC = map [classInDC ]BlockedResourcesSummary {
209
214
node1 : {Timestamp : now (5 ), CPU : 600 , MemoryMB : 700 },
210
215
node2 : {Timestamp : now (6 ), CPU : 800 , MemoryMB : 900 },
211
216
}
@@ -218,10 +223,10 @@ func TestBlockedResourcesStats_Add(t *testing.T) {
218
223
id2 : {Timestamp : now (4 ), CPU : 400 , MemoryMB : 500 },
219
224
}, result .ByJob )
220
225
221
- require .Equal (t , map [node ]BlockedResourcesSummary {
226
+ require .Equal (t , map [classInDC ]BlockedResourcesSummary {
222
227
node1 : {Timestamp : now (5 ), CPU : 933 , MemoryMB : 1144 },
223
228
node2 : {Timestamp : now (6 ), CPU : 800 , MemoryMB : 900 },
224
- }, result .ByNode )
229
+ }, result .ByClassInDC )
225
230
})
226
231
227
232
// make sure we handle zeros in both directions
@@ -233,20 +238,31 @@ func TestBlockedResourcesStats_Add(t *testing.T) {
233
238
id2 : {Timestamp : now (4 ), CPU : 400 , MemoryMB : 500 },
234
239
}, result .ByJob )
235
240
236
- require .Equal (t , map [node ]BlockedResourcesSummary {
241
+ require .Equal (t , map [classInDC ]BlockedResourcesSummary {
237
242
node1 : {Timestamp : now (2 ), CPU : 933 , MemoryMB : 1144 },
238
243
node2 : {Timestamp : now (6 ), CPU : 800 , MemoryMB : 900 },
239
- }, result .ByNode )
244
+ }, result .ByClassInDC )
240
245
})
241
246
}
242
247
248
+ func TestBlockedResourcesStats_Add_NoClass (t * testing.T ) {
249
+ a := NewBlockedResourcesStats ()
250
+ a .ByClassInDC = map [classInDC ]BlockedResourcesSummary {
251
+ node3 : {Timestamp : now (1 ), CPU : 111 , MemoryMB : 1111 },
252
+ }
253
+ result := a .Add (a )
254
+ require .Equal (t , map [classInDC ]BlockedResourcesSummary {
255
+ node3 : {Timestamp : now (1 ), CPU : 222 , MemoryMB : 2222 },
256
+ }, result .ByClassInDC )
257
+ }
258
+
243
259
func TestBlockedResourcesStats_Subtract (t * testing.T ) {
244
260
a := NewBlockedResourcesStats ()
245
261
a .ByJob = map [structs.NamespacedID ]BlockedResourcesSummary {
246
262
id1 : {Timestamp : now (1 ), CPU : 100 , MemoryMB : 100 },
247
263
id2 : {Timestamp : now (2 ), CPU : 200 , MemoryMB : 200 },
248
264
}
249
- a .ByNode = map [node ]BlockedResourcesSummary {
265
+ a .ByClassInDC = map [classInDC ]BlockedResourcesSummary {
250
266
node1 : {Timestamp : now (3 ), CPU : 300 , MemoryMB : 300 },
251
267
node2 : {Timestamp : now (4 ), CPU : 400 , MemoryMB : 400 },
252
268
}
@@ -256,7 +272,7 @@ func TestBlockedResourcesStats_Subtract(t *testing.T) {
256
272
id1 : {Timestamp : now (5 ), CPU : 10 , MemoryMB : 11 },
257
273
id2 : {Timestamp : now (6 ), CPU : 12 , MemoryMB : 13 },
258
274
}
259
- b .ByNode = map [node ]BlockedResourcesSummary {
275
+ b .ByClassInDC = map [classInDC ]BlockedResourcesSummary {
260
276
node1 : {Timestamp : now (7 ), CPU : 14 , MemoryMB : 15 },
261
277
node2 : {Timestamp : now (8 ), CPU : 16 , MemoryMB : 17 },
262
278
}
@@ -274,14 +290,14 @@ func TestBlockedResourcesStats_Subtract(t *testing.T) {
274
290
require .Equal (t , 187 , result .ByJob [id2 ].MemoryMB )
275
291
276
292
// node1
277
- require .Equal (t , now (7 ), result .ByNode [node1 ].Timestamp )
278
- require .Equal (t , 286 , result .ByNode [node1 ].CPU )
279
- require .Equal (t , 285 , result .ByNode [node1 ].MemoryMB )
293
+ require .Equal (t , now (7 ), result .ByClassInDC [node1 ].Timestamp )
294
+ require .Equal (t , 286 , result .ByClassInDC [node1 ].CPU )
295
+ require .Equal (t , 285 , result .ByClassInDC [node1 ].MemoryMB )
280
296
281
297
// node2
282
- require .Equal (t , now (8 ), result .ByNode [node2 ].Timestamp )
283
- require .Equal (t , 384 , result .ByNode [node2 ].CPU )
284
- require .Equal (t , 383 , result .ByNode [node2 ].MemoryMB )
298
+ require .Equal (t , now (8 ), result .ByClassInDC [node2 ].Timestamp )
299
+ require .Equal (t , 384 , result .ByClassInDC [node2 ].CPU )
300
+ require .Equal (t , 383 , result .ByClassInDC [node2 ].MemoryMB )
285
301
}
286
302
287
303
// testBlockedEvalsRandomBlockedEval wraps an eval that is randomly generated.
@@ -363,9 +379,9 @@ func clearTimestampFromBlockedResourceStats(b *BlockedResourcesStats) {
363
379
v .Timestamp = time.Time {}
364
380
b .ByJob [k ] = v
365
381
}
366
- for k , v := range b .ByNode {
382
+ for k , v := range b .ByClassInDC {
367
383
v .Timestamp = time.Time {}
368
- b .ByNode [k ] = v
384
+ b .ByClassInDC [k ] = v
369
385
}
370
386
}
371
387
0 commit comments