github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/devices/gpu/nvidia/stats_test.go (about) 1 package nvidia 2 3 import ( 4 "errors" 5 "sort" 6 "testing" 7 "time" 8 9 hclog "github.com/hashicorp/go-hclog" 10 "github.com/hashicorp/nomad/devices/gpu/nvidia/nvml" 11 "github.com/hashicorp/nomad/helper" 12 "github.com/hashicorp/nomad/plugins/device" 13 "github.com/hashicorp/nomad/plugins/shared/structs" 14 "github.com/stretchr/testify/require" 15 ) 16 17 func TestFilterStatsByID(t *testing.T) { 18 for _, testCase := range []struct { 19 Name string 20 ProvidedStats []*nvml.StatsData 21 ProvidedIDs map[string]struct{} 22 ExpectedResult []*nvml.StatsData 23 }{ 24 { 25 Name: "All ids are in the map", 26 ProvidedStats: []*nvml.StatsData{ 27 { 28 DeviceData: &nvml.DeviceData{ 29 UUID: "UUID1", 30 DeviceName: helper.StringToPtr("DeviceName1"), 31 MemoryMiB: helper.Uint64ToPtr(1), 32 PowerW: helper.UintToPtr(2), 33 BAR1MiB: helper.Uint64ToPtr(256), 34 }, 35 PowerUsageW: helper.UintToPtr(1), 36 GPUUtilization: helper.UintToPtr(1), 37 MemoryUtilization: helper.UintToPtr(1), 38 EncoderUtilization: helper.UintToPtr(1), 39 DecoderUtilization: helper.UintToPtr(1), 40 TemperatureC: helper.UintToPtr(1), 41 UsedMemoryMiB: helper.Uint64ToPtr(1), 42 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 43 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 44 ECCErrorsDevice: helper.Uint64ToPtr(100), 45 }, 46 { 47 DeviceData: &nvml.DeviceData{ 48 UUID: "UUID2", 49 DeviceName: helper.StringToPtr("DeviceName1"), 50 MemoryMiB: helper.Uint64ToPtr(1), 51 PowerW: helper.UintToPtr(2), 52 BAR1MiB: helper.Uint64ToPtr(256), 53 }, 54 PowerUsageW: helper.UintToPtr(1), 55 GPUUtilization: helper.UintToPtr(1), 56 MemoryUtilization: helper.UintToPtr(1), 57 EncoderUtilization: helper.UintToPtr(1), 58 DecoderUtilization: helper.UintToPtr(1), 59 TemperatureC: helper.UintToPtr(1), 60 UsedMemoryMiB: helper.Uint64ToPtr(1), 61 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 62 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 63 ECCErrorsDevice: helper.Uint64ToPtr(100), 64 }, 65 { 66 DeviceData: &nvml.DeviceData{ 67 UUID: "UUID3", 68 DeviceName: helper.StringToPtr("DeviceName1"), 69 MemoryMiB: helper.Uint64ToPtr(1), 70 PowerW: helper.UintToPtr(2), 71 BAR1MiB: helper.Uint64ToPtr(256), 72 }, 73 PowerUsageW: helper.UintToPtr(1), 74 GPUUtilization: helper.UintToPtr(1), 75 MemoryUtilization: helper.UintToPtr(1), 76 EncoderUtilization: helper.UintToPtr(1), 77 DecoderUtilization: helper.UintToPtr(1), 78 TemperatureC: helper.UintToPtr(1), 79 UsedMemoryMiB: helper.Uint64ToPtr(1), 80 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 81 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 82 ECCErrorsDevice: helper.Uint64ToPtr(100), 83 }, 84 }, 85 ProvidedIDs: map[string]struct{}{ 86 "UUID1": {}, 87 "UUID2": {}, 88 "UUID3": {}, 89 }, 90 ExpectedResult: []*nvml.StatsData{ 91 { 92 DeviceData: &nvml.DeviceData{ 93 UUID: "UUID1", 94 DeviceName: helper.StringToPtr("DeviceName1"), 95 MemoryMiB: helper.Uint64ToPtr(1), 96 PowerW: helper.UintToPtr(2), 97 BAR1MiB: helper.Uint64ToPtr(256), 98 }, 99 PowerUsageW: helper.UintToPtr(1), 100 GPUUtilization: helper.UintToPtr(1), 101 MemoryUtilization: helper.UintToPtr(1), 102 EncoderUtilization: helper.UintToPtr(1), 103 DecoderUtilization: helper.UintToPtr(1), 104 TemperatureC: helper.UintToPtr(1), 105 UsedMemoryMiB: helper.Uint64ToPtr(1), 106 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 107 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 108 ECCErrorsDevice: helper.Uint64ToPtr(100), 109 }, 110 { 111 DeviceData: &nvml.DeviceData{ 112 UUID: "UUID2", 113 DeviceName: helper.StringToPtr("DeviceName1"), 114 MemoryMiB: helper.Uint64ToPtr(1), 115 PowerW: helper.UintToPtr(2), 116 BAR1MiB: helper.Uint64ToPtr(256), 117 }, 118 PowerUsageW: helper.UintToPtr(1), 119 GPUUtilization: helper.UintToPtr(1), 120 MemoryUtilization: helper.UintToPtr(1), 121 EncoderUtilization: helper.UintToPtr(1), 122 DecoderUtilization: helper.UintToPtr(1), 123 TemperatureC: helper.UintToPtr(1), 124 UsedMemoryMiB: helper.Uint64ToPtr(1), 125 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 126 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 127 ECCErrorsDevice: helper.Uint64ToPtr(100), 128 }, 129 { 130 DeviceData: &nvml.DeviceData{ 131 UUID: "UUID3", 132 DeviceName: helper.StringToPtr("DeviceName1"), 133 MemoryMiB: helper.Uint64ToPtr(1), 134 PowerW: helper.UintToPtr(2), 135 BAR1MiB: helper.Uint64ToPtr(256), 136 }, 137 PowerUsageW: helper.UintToPtr(1), 138 GPUUtilization: helper.UintToPtr(1), 139 MemoryUtilization: helper.UintToPtr(1), 140 EncoderUtilization: helper.UintToPtr(1), 141 DecoderUtilization: helper.UintToPtr(1), 142 TemperatureC: helper.UintToPtr(1), 143 UsedMemoryMiB: helper.Uint64ToPtr(1), 144 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 145 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 146 ECCErrorsDevice: helper.Uint64ToPtr(100), 147 }, 148 }, 149 }, 150 { 151 Name: "Odd are not provided in the map", 152 ProvidedStats: []*nvml.StatsData{ 153 { 154 DeviceData: &nvml.DeviceData{ 155 UUID: "UUID1", 156 DeviceName: helper.StringToPtr("DeviceName1"), 157 MemoryMiB: helper.Uint64ToPtr(1), 158 PowerW: helper.UintToPtr(2), 159 BAR1MiB: helper.Uint64ToPtr(256), 160 }, 161 PowerUsageW: helper.UintToPtr(1), 162 GPUUtilization: helper.UintToPtr(1), 163 MemoryUtilization: helper.UintToPtr(1), 164 EncoderUtilization: helper.UintToPtr(1), 165 DecoderUtilization: helper.UintToPtr(1), 166 TemperatureC: helper.UintToPtr(1), 167 UsedMemoryMiB: helper.Uint64ToPtr(1), 168 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 169 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 170 ECCErrorsDevice: helper.Uint64ToPtr(100), 171 }, 172 { 173 DeviceData: &nvml.DeviceData{ 174 UUID: "UUID2", 175 DeviceName: helper.StringToPtr("DeviceName1"), 176 MemoryMiB: helper.Uint64ToPtr(1), 177 PowerW: helper.UintToPtr(2), 178 BAR1MiB: helper.Uint64ToPtr(256), 179 }, 180 PowerUsageW: helper.UintToPtr(1), 181 GPUUtilization: helper.UintToPtr(1), 182 MemoryUtilization: helper.UintToPtr(1), 183 EncoderUtilization: helper.UintToPtr(1), 184 DecoderUtilization: helper.UintToPtr(1), 185 TemperatureC: helper.UintToPtr(1), 186 UsedMemoryMiB: helper.Uint64ToPtr(1), 187 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 188 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 189 ECCErrorsDevice: helper.Uint64ToPtr(100), 190 }, 191 { 192 DeviceData: &nvml.DeviceData{ 193 UUID: "UUID3", 194 DeviceName: helper.StringToPtr("DeviceName1"), 195 MemoryMiB: helper.Uint64ToPtr(1), 196 PowerW: helper.UintToPtr(2), 197 BAR1MiB: helper.Uint64ToPtr(256), 198 }, 199 PowerUsageW: helper.UintToPtr(1), 200 GPUUtilization: helper.UintToPtr(1), 201 MemoryUtilization: helper.UintToPtr(1), 202 EncoderUtilization: helper.UintToPtr(1), 203 DecoderUtilization: helper.UintToPtr(1), 204 TemperatureC: helper.UintToPtr(1), 205 UsedMemoryMiB: helper.Uint64ToPtr(1), 206 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 207 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 208 ECCErrorsDevice: helper.Uint64ToPtr(100), 209 }, 210 }, 211 ProvidedIDs: map[string]struct{}{ 212 "UUID2": {}, 213 }, 214 ExpectedResult: []*nvml.StatsData{ 215 { 216 DeviceData: &nvml.DeviceData{ 217 UUID: "UUID2", 218 DeviceName: helper.StringToPtr("DeviceName1"), 219 MemoryMiB: helper.Uint64ToPtr(1), 220 PowerW: helper.UintToPtr(2), 221 BAR1MiB: helper.Uint64ToPtr(256), 222 }, 223 PowerUsageW: helper.UintToPtr(1), 224 GPUUtilization: helper.UintToPtr(1), 225 MemoryUtilization: helper.UintToPtr(1), 226 EncoderUtilization: helper.UintToPtr(1), 227 DecoderUtilization: helper.UintToPtr(1), 228 TemperatureC: helper.UintToPtr(1), 229 UsedMemoryMiB: helper.Uint64ToPtr(1), 230 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 231 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 232 ECCErrorsDevice: helper.Uint64ToPtr(100), 233 }, 234 }, 235 }, 236 { 237 Name: "Even are not provided in the map", 238 ProvidedStats: []*nvml.StatsData{ 239 { 240 DeviceData: &nvml.DeviceData{ 241 UUID: "UUID1", 242 DeviceName: helper.StringToPtr("DeviceName1"), 243 MemoryMiB: helper.Uint64ToPtr(1), 244 PowerW: helper.UintToPtr(2), 245 BAR1MiB: helper.Uint64ToPtr(256), 246 }, 247 PowerUsageW: helper.UintToPtr(1), 248 GPUUtilization: helper.UintToPtr(1), 249 MemoryUtilization: helper.UintToPtr(1), 250 EncoderUtilization: helper.UintToPtr(1), 251 DecoderUtilization: helper.UintToPtr(1), 252 TemperatureC: helper.UintToPtr(1), 253 UsedMemoryMiB: helper.Uint64ToPtr(1), 254 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 255 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 256 ECCErrorsDevice: helper.Uint64ToPtr(100), 257 }, 258 { 259 DeviceData: &nvml.DeviceData{ 260 UUID: "UUID2", 261 DeviceName: helper.StringToPtr("DeviceName1"), 262 MemoryMiB: helper.Uint64ToPtr(1), 263 PowerW: helper.UintToPtr(2), 264 BAR1MiB: helper.Uint64ToPtr(256), 265 }, 266 PowerUsageW: helper.UintToPtr(1), 267 GPUUtilization: helper.UintToPtr(1), 268 MemoryUtilization: helper.UintToPtr(1), 269 EncoderUtilization: helper.UintToPtr(1), 270 DecoderUtilization: helper.UintToPtr(1), 271 TemperatureC: helper.UintToPtr(1), 272 UsedMemoryMiB: helper.Uint64ToPtr(1), 273 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 274 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 275 ECCErrorsDevice: helper.Uint64ToPtr(100), 276 }, 277 { 278 DeviceData: &nvml.DeviceData{ 279 UUID: "UUID3", 280 DeviceName: helper.StringToPtr("DeviceName1"), 281 MemoryMiB: helper.Uint64ToPtr(1), 282 PowerW: helper.UintToPtr(2), 283 BAR1MiB: helper.Uint64ToPtr(256), 284 }, 285 PowerUsageW: helper.UintToPtr(1), 286 GPUUtilization: helper.UintToPtr(1), 287 MemoryUtilization: helper.UintToPtr(1), 288 EncoderUtilization: helper.UintToPtr(1), 289 DecoderUtilization: helper.UintToPtr(1), 290 TemperatureC: helper.UintToPtr(1), 291 UsedMemoryMiB: helper.Uint64ToPtr(1), 292 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 293 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 294 ECCErrorsDevice: helper.Uint64ToPtr(100), 295 }, 296 }, 297 ProvidedIDs: map[string]struct{}{ 298 "UUID1": {}, 299 "UUID3": {}, 300 }, 301 ExpectedResult: []*nvml.StatsData{ 302 { 303 DeviceData: &nvml.DeviceData{ 304 UUID: "UUID1", 305 DeviceName: helper.StringToPtr("DeviceName1"), 306 MemoryMiB: helper.Uint64ToPtr(1), 307 PowerW: helper.UintToPtr(2), 308 BAR1MiB: helper.Uint64ToPtr(256), 309 }, 310 PowerUsageW: helper.UintToPtr(1), 311 GPUUtilization: helper.UintToPtr(1), 312 MemoryUtilization: helper.UintToPtr(1), 313 EncoderUtilization: helper.UintToPtr(1), 314 DecoderUtilization: helper.UintToPtr(1), 315 TemperatureC: helper.UintToPtr(1), 316 UsedMemoryMiB: helper.Uint64ToPtr(1), 317 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 318 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 319 ECCErrorsDevice: helper.Uint64ToPtr(100), 320 }, 321 { 322 DeviceData: &nvml.DeviceData{ 323 UUID: "UUID3", 324 DeviceName: helper.StringToPtr("DeviceName1"), 325 MemoryMiB: helper.Uint64ToPtr(1), 326 PowerW: helper.UintToPtr(2), 327 BAR1MiB: helper.Uint64ToPtr(256), 328 }, 329 PowerUsageW: helper.UintToPtr(1), 330 GPUUtilization: helper.UintToPtr(1), 331 MemoryUtilization: helper.UintToPtr(1), 332 EncoderUtilization: helper.UintToPtr(1), 333 DecoderUtilization: helper.UintToPtr(1), 334 TemperatureC: helper.UintToPtr(1), 335 UsedMemoryMiB: helper.Uint64ToPtr(1), 336 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 337 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 338 ECCErrorsDevice: helper.Uint64ToPtr(100), 339 }, 340 }, 341 }, 342 { 343 Name: "No Stats were provided", 344 ProvidedIDs: map[string]struct{}{ 345 "UUID1": {}, 346 "UUID2": {}, 347 "UUID3": {}, 348 }, 349 }, 350 { 351 Name: "No Ids were provided", 352 ProvidedStats: []*nvml.StatsData{ 353 { 354 DeviceData: &nvml.DeviceData{ 355 UUID: "UUID1", 356 DeviceName: helper.StringToPtr("DeviceName1"), 357 MemoryMiB: helper.Uint64ToPtr(1), 358 PowerW: helper.UintToPtr(2), 359 BAR1MiB: helper.Uint64ToPtr(256), 360 }, 361 PowerUsageW: helper.UintToPtr(1), 362 GPUUtilization: helper.UintToPtr(1), 363 MemoryUtilization: helper.UintToPtr(1), 364 EncoderUtilization: helper.UintToPtr(1), 365 DecoderUtilization: helper.UintToPtr(1), 366 TemperatureC: helper.UintToPtr(1), 367 UsedMemoryMiB: helper.Uint64ToPtr(1), 368 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 369 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 370 ECCErrorsDevice: helper.Uint64ToPtr(100), 371 }, 372 { 373 DeviceData: &nvml.DeviceData{ 374 UUID: "UUID2", 375 DeviceName: helper.StringToPtr("DeviceName1"), 376 MemoryMiB: helper.Uint64ToPtr(1), 377 PowerW: helper.UintToPtr(2), 378 BAR1MiB: helper.Uint64ToPtr(256), 379 }, 380 PowerUsageW: helper.UintToPtr(1), 381 GPUUtilization: helper.UintToPtr(1), 382 MemoryUtilization: helper.UintToPtr(1), 383 EncoderUtilization: helper.UintToPtr(1), 384 DecoderUtilization: helper.UintToPtr(1), 385 TemperatureC: helper.UintToPtr(1), 386 UsedMemoryMiB: helper.Uint64ToPtr(1), 387 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 388 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 389 ECCErrorsDevice: helper.Uint64ToPtr(100), 390 }, 391 { 392 DeviceData: &nvml.DeviceData{ 393 UUID: "UUID3", 394 DeviceName: helper.StringToPtr("DeviceName1"), 395 MemoryMiB: helper.Uint64ToPtr(1), 396 PowerW: helper.UintToPtr(2), 397 BAR1MiB: helper.Uint64ToPtr(256), 398 }, 399 PowerUsageW: helper.UintToPtr(1), 400 GPUUtilization: helper.UintToPtr(1), 401 MemoryUtilization: helper.UintToPtr(1), 402 EncoderUtilization: helper.UintToPtr(1), 403 DecoderUtilization: helper.UintToPtr(1), 404 TemperatureC: helper.UintToPtr(1), 405 UsedMemoryMiB: helper.Uint64ToPtr(1), 406 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 407 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 408 ECCErrorsDevice: helper.Uint64ToPtr(100), 409 }, 410 }, 411 }, 412 } { 413 actualResult := filterStatsByID(testCase.ProvidedStats, testCase.ProvidedIDs) 414 require.New(t).Equal(testCase.ExpectedResult, actualResult) 415 } 416 } 417 418 func TestStatsForItem(t *testing.T) { 419 for _, testCase := range []struct { 420 Name string 421 Timestamp time.Time 422 ItemStat *nvml.StatsData 423 ExpectedResult *device.DeviceStats 424 }{ 425 { 426 Name: "All fields in ItemStat are not nil", 427 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 428 ItemStat: &nvml.StatsData{ 429 DeviceData: &nvml.DeviceData{ 430 UUID: "UUID1", 431 DeviceName: helper.StringToPtr("DeviceName1"), 432 MemoryMiB: helper.Uint64ToPtr(1), 433 PowerW: helper.UintToPtr(1), 434 BAR1MiB: helper.Uint64ToPtr(256), 435 }, 436 PowerUsageW: helper.UintToPtr(1), 437 GPUUtilization: helper.UintToPtr(1), 438 MemoryUtilization: helper.UintToPtr(1), 439 EncoderUtilization: helper.UintToPtr(1), 440 DecoderUtilization: helper.UintToPtr(1), 441 TemperatureC: helper.UintToPtr(1), 442 UsedMemoryMiB: helper.Uint64ToPtr(1), 443 BAR1UsedMiB: helper.Uint64ToPtr(1), 444 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 445 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 446 ECCErrorsDevice: helper.Uint64ToPtr(100), 447 }, 448 ExpectedResult: &device.DeviceStats{ 449 Summary: &structs.StatValue{ 450 Unit: MemoryStateUnit, 451 Desc: MemoryStateDesc, 452 IntNumeratorVal: helper.Int64ToPtr(1), 453 IntDenominatorVal: helper.Int64ToPtr(1), 454 }, 455 Stats: &structs.StatObject{ 456 Attributes: map[string]*structs.StatValue{ 457 PowerUsageAttr: { 458 Unit: PowerUsageUnit, 459 Desc: PowerUsageDesc, 460 IntNumeratorVal: helper.Int64ToPtr(1), 461 IntDenominatorVal: helper.Int64ToPtr(1), 462 }, 463 GPUUtilizationAttr: { 464 Unit: GPUUtilizationUnit, 465 Desc: GPUUtilizationDesc, 466 IntNumeratorVal: helper.Int64ToPtr(1), 467 }, 468 MemoryUtilizationAttr: { 469 Unit: MemoryUtilizationUnit, 470 Desc: MemoryUtilizationDesc, 471 IntNumeratorVal: helper.Int64ToPtr(1), 472 }, 473 EncoderUtilizationAttr: { 474 Unit: EncoderUtilizationUnit, 475 Desc: EncoderUtilizationDesc, 476 IntNumeratorVal: helper.Int64ToPtr(1), 477 }, 478 DecoderUtilizationAttr: { 479 Unit: DecoderUtilizationUnit, 480 Desc: DecoderUtilizationDesc, 481 IntNumeratorVal: helper.Int64ToPtr(1), 482 }, 483 TemperatureAttr: { 484 Unit: TemperatureUnit, 485 Desc: TemperatureDesc, 486 IntNumeratorVal: helper.Int64ToPtr(1), 487 }, 488 MemoryStateAttr: { 489 Unit: MemoryStateUnit, 490 Desc: MemoryStateDesc, 491 IntNumeratorVal: helper.Int64ToPtr(1), 492 IntDenominatorVal: helper.Int64ToPtr(1), 493 }, 494 BAR1StateAttr: { 495 Unit: BAR1StateUnit, 496 Desc: BAR1StateDesc, 497 IntNumeratorVal: helper.Int64ToPtr(1), 498 IntDenominatorVal: helper.Int64ToPtr(256), 499 }, 500 ECCErrorsL1CacheAttr: { 501 Unit: ECCErrorsL1CacheUnit, 502 Desc: ECCErrorsL1CacheDesc, 503 IntNumeratorVal: helper.Int64ToPtr(100), 504 }, 505 ECCErrorsL2CacheAttr: { 506 Unit: ECCErrorsL2CacheUnit, 507 Desc: ECCErrorsL2CacheDesc, 508 IntNumeratorVal: helper.Int64ToPtr(100), 509 }, 510 ECCErrorsDeviceAttr: { 511 Unit: ECCErrorsDeviceUnit, 512 Desc: ECCErrorsDeviceDesc, 513 IntNumeratorVal: helper.Int64ToPtr(100), 514 }, 515 }, 516 }, 517 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 518 }, 519 }, 520 { 521 Name: "Power usage is nil", 522 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 523 ItemStat: &nvml.StatsData{ 524 DeviceData: &nvml.DeviceData{ 525 UUID: "UUID1", 526 DeviceName: helper.StringToPtr("DeviceName1"), 527 MemoryMiB: helper.Uint64ToPtr(1), 528 PowerW: helper.UintToPtr(1), 529 BAR1MiB: helper.Uint64ToPtr(256), 530 }, 531 PowerUsageW: nil, 532 GPUUtilization: helper.UintToPtr(1), 533 MemoryUtilization: helper.UintToPtr(1), 534 EncoderUtilization: helper.UintToPtr(1), 535 DecoderUtilization: helper.UintToPtr(1), 536 TemperatureC: helper.UintToPtr(1), 537 UsedMemoryMiB: helper.Uint64ToPtr(1), 538 BAR1UsedMiB: helper.Uint64ToPtr(1), 539 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 540 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 541 ECCErrorsDevice: helper.Uint64ToPtr(100), 542 }, 543 ExpectedResult: &device.DeviceStats{ 544 Summary: &structs.StatValue{ 545 Unit: MemoryStateUnit, 546 Desc: MemoryStateDesc, 547 IntNumeratorVal: helper.Int64ToPtr(1), 548 IntDenominatorVal: helper.Int64ToPtr(1), 549 }, 550 Stats: &structs.StatObject{ 551 Attributes: map[string]*structs.StatValue{ 552 PowerUsageAttr: { 553 Unit: PowerUsageUnit, 554 Desc: PowerUsageDesc, 555 StringVal: helper.StringToPtr(notAvailable), 556 }, 557 GPUUtilizationAttr: { 558 Unit: GPUUtilizationUnit, 559 Desc: GPUUtilizationDesc, 560 IntNumeratorVal: helper.Int64ToPtr(1), 561 }, 562 MemoryUtilizationAttr: { 563 Unit: MemoryUtilizationUnit, 564 Desc: MemoryUtilizationDesc, 565 IntNumeratorVal: helper.Int64ToPtr(1), 566 }, 567 EncoderUtilizationAttr: { 568 Unit: EncoderUtilizationUnit, 569 Desc: EncoderUtilizationDesc, 570 IntNumeratorVal: helper.Int64ToPtr(1), 571 }, 572 DecoderUtilizationAttr: { 573 Unit: DecoderUtilizationUnit, 574 Desc: DecoderUtilizationDesc, 575 IntNumeratorVal: helper.Int64ToPtr(1), 576 }, 577 TemperatureAttr: { 578 Unit: TemperatureUnit, 579 Desc: TemperatureDesc, 580 IntNumeratorVal: helper.Int64ToPtr(1), 581 }, 582 MemoryStateAttr: { 583 Unit: MemoryStateUnit, 584 Desc: MemoryStateDesc, 585 IntNumeratorVal: helper.Int64ToPtr(1), 586 IntDenominatorVal: helper.Int64ToPtr(1), 587 }, 588 BAR1StateAttr: { 589 Unit: BAR1StateUnit, 590 Desc: BAR1StateDesc, 591 IntNumeratorVal: helper.Int64ToPtr(1), 592 IntDenominatorVal: helper.Int64ToPtr(256), 593 }, 594 ECCErrorsL1CacheAttr: { 595 Unit: ECCErrorsL1CacheUnit, 596 Desc: ECCErrorsL1CacheDesc, 597 IntNumeratorVal: helper.Int64ToPtr(100), 598 }, 599 ECCErrorsL2CacheAttr: { 600 Unit: ECCErrorsL2CacheUnit, 601 Desc: ECCErrorsL2CacheDesc, 602 IntNumeratorVal: helper.Int64ToPtr(100), 603 }, 604 ECCErrorsDeviceAttr: { 605 Unit: ECCErrorsDeviceUnit, 606 Desc: ECCErrorsDeviceDesc, 607 IntNumeratorVal: helper.Int64ToPtr(100), 608 }, 609 }, 610 }, 611 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 612 }, 613 }, 614 { 615 Name: "PowerW is nil", 616 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 617 ItemStat: &nvml.StatsData{ 618 DeviceData: &nvml.DeviceData{ 619 UUID: "UUID1", 620 DeviceName: helper.StringToPtr("DeviceName1"), 621 MemoryMiB: helper.Uint64ToPtr(1), 622 PowerW: nil, 623 BAR1MiB: helper.Uint64ToPtr(256), 624 }, 625 PowerUsageW: helper.UintToPtr(1), 626 GPUUtilization: helper.UintToPtr(1), 627 MemoryUtilization: helper.UintToPtr(1), 628 EncoderUtilization: helper.UintToPtr(1), 629 DecoderUtilization: helper.UintToPtr(1), 630 TemperatureC: helper.UintToPtr(1), 631 UsedMemoryMiB: helper.Uint64ToPtr(1), 632 BAR1UsedMiB: helper.Uint64ToPtr(1), 633 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 634 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 635 ECCErrorsDevice: helper.Uint64ToPtr(100), 636 }, 637 ExpectedResult: &device.DeviceStats{ 638 Summary: &structs.StatValue{ 639 Unit: MemoryStateUnit, 640 Desc: MemoryStateDesc, 641 IntNumeratorVal: helper.Int64ToPtr(1), 642 IntDenominatorVal: helper.Int64ToPtr(1), 643 }, 644 Stats: &structs.StatObject{ 645 Attributes: map[string]*structs.StatValue{ 646 PowerUsageAttr: { 647 Unit: PowerUsageUnit, 648 Desc: PowerUsageDesc, 649 StringVal: helper.StringToPtr(notAvailable), 650 }, 651 GPUUtilizationAttr: { 652 Unit: GPUUtilizationUnit, 653 Desc: GPUUtilizationDesc, 654 IntNumeratorVal: helper.Int64ToPtr(1), 655 }, 656 MemoryUtilizationAttr: { 657 Unit: MemoryUtilizationUnit, 658 Desc: MemoryUtilizationDesc, 659 IntNumeratorVal: helper.Int64ToPtr(1), 660 }, 661 EncoderUtilizationAttr: { 662 Unit: EncoderUtilizationUnit, 663 Desc: EncoderUtilizationDesc, 664 IntNumeratorVal: helper.Int64ToPtr(1), 665 }, 666 DecoderUtilizationAttr: { 667 Unit: DecoderUtilizationUnit, 668 Desc: DecoderUtilizationDesc, 669 IntNumeratorVal: helper.Int64ToPtr(1), 670 }, 671 TemperatureAttr: { 672 Unit: TemperatureUnit, 673 Desc: TemperatureDesc, 674 IntNumeratorVal: helper.Int64ToPtr(1), 675 }, 676 MemoryStateAttr: { 677 Unit: MemoryStateUnit, 678 Desc: MemoryStateDesc, 679 IntNumeratorVal: helper.Int64ToPtr(1), 680 IntDenominatorVal: helper.Int64ToPtr(1), 681 }, 682 BAR1StateAttr: { 683 Unit: BAR1StateUnit, 684 Desc: BAR1StateDesc, 685 IntNumeratorVal: helper.Int64ToPtr(1), 686 IntDenominatorVal: helper.Int64ToPtr(256), 687 }, 688 ECCErrorsL1CacheAttr: { 689 Unit: ECCErrorsL1CacheUnit, 690 Desc: ECCErrorsL1CacheDesc, 691 IntNumeratorVal: helper.Int64ToPtr(100), 692 }, 693 ECCErrorsL2CacheAttr: { 694 Unit: ECCErrorsL2CacheUnit, 695 Desc: ECCErrorsL2CacheDesc, 696 IntNumeratorVal: helper.Int64ToPtr(100), 697 }, 698 ECCErrorsDeviceAttr: { 699 Unit: ECCErrorsDeviceUnit, 700 Desc: ECCErrorsDeviceDesc, 701 IntNumeratorVal: helper.Int64ToPtr(100), 702 }, 703 }, 704 }, 705 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 706 }, 707 }, 708 { 709 Name: "GPUUtilization is nil", 710 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 711 ItemStat: &nvml.StatsData{ 712 DeviceData: &nvml.DeviceData{ 713 UUID: "UUID1", 714 DeviceName: helper.StringToPtr("DeviceName1"), 715 MemoryMiB: helper.Uint64ToPtr(1), 716 PowerW: helper.UintToPtr(1), 717 BAR1MiB: helper.Uint64ToPtr(256), 718 }, 719 PowerUsageW: helper.UintToPtr(1), 720 GPUUtilization: nil, 721 MemoryUtilization: helper.UintToPtr(1), 722 EncoderUtilization: helper.UintToPtr(1), 723 DecoderUtilization: helper.UintToPtr(1), 724 TemperatureC: helper.UintToPtr(1), 725 UsedMemoryMiB: helper.Uint64ToPtr(1), 726 BAR1UsedMiB: helper.Uint64ToPtr(1), 727 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 728 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 729 ECCErrorsDevice: helper.Uint64ToPtr(100), 730 }, 731 ExpectedResult: &device.DeviceStats{ 732 Summary: &structs.StatValue{ 733 Unit: MemoryStateUnit, 734 Desc: MemoryStateDesc, 735 IntNumeratorVal: helper.Int64ToPtr(1), 736 IntDenominatorVal: helper.Int64ToPtr(1), 737 }, 738 Stats: &structs.StatObject{ 739 Attributes: map[string]*structs.StatValue{ 740 PowerUsageAttr: { 741 Unit: PowerUsageUnit, 742 Desc: PowerUsageDesc, 743 IntNumeratorVal: helper.Int64ToPtr(1), 744 IntDenominatorVal: helper.Int64ToPtr(1), 745 }, 746 GPUUtilizationAttr: { 747 Unit: GPUUtilizationUnit, 748 Desc: GPUUtilizationDesc, 749 StringVal: helper.StringToPtr(notAvailable), 750 }, 751 MemoryUtilizationAttr: { 752 Unit: MemoryUtilizationUnit, 753 Desc: MemoryUtilizationDesc, 754 IntNumeratorVal: helper.Int64ToPtr(1), 755 }, 756 EncoderUtilizationAttr: { 757 Unit: EncoderUtilizationUnit, 758 Desc: EncoderUtilizationDesc, 759 IntNumeratorVal: helper.Int64ToPtr(1), 760 }, 761 DecoderUtilizationAttr: { 762 Unit: DecoderUtilizationUnit, 763 Desc: DecoderUtilizationDesc, 764 IntNumeratorVal: helper.Int64ToPtr(1), 765 }, 766 TemperatureAttr: { 767 Unit: TemperatureUnit, 768 Desc: TemperatureDesc, 769 IntNumeratorVal: helper.Int64ToPtr(1), 770 }, 771 MemoryStateAttr: { 772 Unit: MemoryStateUnit, 773 Desc: MemoryStateDesc, 774 IntNumeratorVal: helper.Int64ToPtr(1), 775 IntDenominatorVal: helper.Int64ToPtr(1), 776 }, 777 BAR1StateAttr: { 778 Unit: BAR1StateUnit, 779 Desc: BAR1StateDesc, 780 IntNumeratorVal: helper.Int64ToPtr(1), 781 IntDenominatorVal: helper.Int64ToPtr(256), 782 }, 783 ECCErrorsL1CacheAttr: { 784 Unit: ECCErrorsL1CacheUnit, 785 Desc: ECCErrorsL1CacheDesc, 786 IntNumeratorVal: helper.Int64ToPtr(100), 787 }, 788 ECCErrorsL2CacheAttr: { 789 Unit: ECCErrorsL2CacheUnit, 790 Desc: ECCErrorsL2CacheDesc, 791 IntNumeratorVal: helper.Int64ToPtr(100), 792 }, 793 ECCErrorsDeviceAttr: { 794 Unit: ECCErrorsDeviceUnit, 795 Desc: ECCErrorsDeviceDesc, 796 IntNumeratorVal: helper.Int64ToPtr(100), 797 }, 798 }, 799 }, 800 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 801 }, 802 }, 803 { 804 Name: "MemoryUtilization is nil", 805 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 806 ItemStat: &nvml.StatsData{ 807 DeviceData: &nvml.DeviceData{ 808 UUID: "UUID1", 809 DeviceName: helper.StringToPtr("DeviceName1"), 810 MemoryMiB: helper.Uint64ToPtr(1), 811 PowerW: helper.UintToPtr(1), 812 BAR1MiB: helper.Uint64ToPtr(256), 813 }, 814 PowerUsageW: helper.UintToPtr(1), 815 GPUUtilization: helper.UintToPtr(1), 816 MemoryUtilization: nil, 817 EncoderUtilization: helper.UintToPtr(1), 818 DecoderUtilization: helper.UintToPtr(1), 819 TemperatureC: helper.UintToPtr(1), 820 UsedMemoryMiB: helper.Uint64ToPtr(1), 821 BAR1UsedMiB: helper.Uint64ToPtr(1), 822 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 823 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 824 ECCErrorsDevice: helper.Uint64ToPtr(100), 825 }, 826 ExpectedResult: &device.DeviceStats{ 827 Summary: &structs.StatValue{ 828 Unit: MemoryStateUnit, 829 Desc: MemoryStateDesc, 830 IntNumeratorVal: helper.Int64ToPtr(1), 831 IntDenominatorVal: helper.Int64ToPtr(1), 832 }, 833 Stats: &structs.StatObject{ 834 Attributes: map[string]*structs.StatValue{ 835 PowerUsageAttr: { 836 Unit: PowerUsageUnit, 837 Desc: PowerUsageDesc, 838 IntNumeratorVal: helper.Int64ToPtr(1), 839 IntDenominatorVal: helper.Int64ToPtr(1), 840 }, 841 GPUUtilizationAttr: { 842 Unit: GPUUtilizationUnit, 843 Desc: GPUUtilizationDesc, 844 IntNumeratorVal: helper.Int64ToPtr(1), 845 }, 846 MemoryUtilizationAttr: { 847 Unit: MemoryUtilizationUnit, 848 Desc: MemoryUtilizationDesc, 849 StringVal: helper.StringToPtr(notAvailable), 850 }, 851 EncoderUtilizationAttr: { 852 Unit: EncoderUtilizationUnit, 853 Desc: EncoderUtilizationDesc, 854 IntNumeratorVal: helper.Int64ToPtr(1), 855 }, 856 DecoderUtilizationAttr: { 857 Unit: DecoderUtilizationUnit, 858 Desc: DecoderUtilizationDesc, 859 IntNumeratorVal: helper.Int64ToPtr(1), 860 }, 861 TemperatureAttr: { 862 Unit: TemperatureUnit, 863 Desc: TemperatureDesc, 864 IntNumeratorVal: helper.Int64ToPtr(1), 865 }, 866 MemoryStateAttr: { 867 Unit: MemoryStateUnit, 868 Desc: MemoryStateDesc, 869 IntNumeratorVal: helper.Int64ToPtr(1), 870 IntDenominatorVal: helper.Int64ToPtr(1), 871 }, 872 BAR1StateAttr: { 873 Unit: BAR1StateUnit, 874 Desc: BAR1StateDesc, 875 IntNumeratorVal: helper.Int64ToPtr(1), 876 IntDenominatorVal: helper.Int64ToPtr(256), 877 }, 878 ECCErrorsL1CacheAttr: { 879 Unit: ECCErrorsL1CacheUnit, 880 Desc: ECCErrorsL1CacheDesc, 881 IntNumeratorVal: helper.Int64ToPtr(100), 882 }, 883 ECCErrorsL2CacheAttr: { 884 Unit: ECCErrorsL2CacheUnit, 885 Desc: ECCErrorsL2CacheDesc, 886 IntNumeratorVal: helper.Int64ToPtr(100), 887 }, 888 ECCErrorsDeviceAttr: { 889 Unit: ECCErrorsDeviceUnit, 890 Desc: ECCErrorsDeviceDesc, 891 IntNumeratorVal: helper.Int64ToPtr(100), 892 }, 893 }, 894 }, 895 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 896 }, 897 }, 898 { 899 Name: "EncoderUtilization is nil", 900 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 901 ItemStat: &nvml.StatsData{ 902 DeviceData: &nvml.DeviceData{ 903 UUID: "UUID1", 904 DeviceName: helper.StringToPtr("DeviceName1"), 905 MemoryMiB: helper.Uint64ToPtr(1), 906 PowerW: helper.UintToPtr(1), 907 BAR1MiB: helper.Uint64ToPtr(256), 908 }, 909 PowerUsageW: helper.UintToPtr(1), 910 GPUUtilization: helper.UintToPtr(1), 911 MemoryUtilization: helper.UintToPtr(1), 912 EncoderUtilization: nil, 913 DecoderUtilization: helper.UintToPtr(1), 914 TemperatureC: helper.UintToPtr(1), 915 UsedMemoryMiB: helper.Uint64ToPtr(1), 916 BAR1UsedMiB: helper.Uint64ToPtr(1), 917 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 918 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 919 ECCErrorsDevice: helper.Uint64ToPtr(100), 920 }, 921 ExpectedResult: &device.DeviceStats{ 922 Summary: &structs.StatValue{ 923 Unit: MemoryStateUnit, 924 Desc: MemoryStateDesc, 925 IntNumeratorVal: helper.Int64ToPtr(1), 926 IntDenominatorVal: helper.Int64ToPtr(1), 927 }, 928 Stats: &structs.StatObject{ 929 Attributes: map[string]*structs.StatValue{ 930 PowerUsageAttr: { 931 Unit: PowerUsageUnit, 932 Desc: PowerUsageDesc, 933 IntNumeratorVal: helper.Int64ToPtr(1), 934 IntDenominatorVal: helper.Int64ToPtr(1), 935 }, 936 GPUUtilizationAttr: { 937 Unit: GPUUtilizationUnit, 938 Desc: GPUUtilizationDesc, 939 IntNumeratorVal: helper.Int64ToPtr(1), 940 }, 941 MemoryUtilizationAttr: { 942 Unit: MemoryUtilizationUnit, 943 Desc: MemoryUtilizationDesc, 944 IntNumeratorVal: helper.Int64ToPtr(1), 945 }, 946 EncoderUtilizationAttr: { 947 Unit: EncoderUtilizationUnit, 948 Desc: EncoderUtilizationDesc, 949 StringVal: helper.StringToPtr(notAvailable), 950 }, 951 DecoderUtilizationAttr: { 952 Unit: DecoderUtilizationUnit, 953 Desc: DecoderUtilizationDesc, 954 IntNumeratorVal: helper.Int64ToPtr(1), 955 }, 956 TemperatureAttr: { 957 Unit: TemperatureUnit, 958 Desc: TemperatureDesc, 959 IntNumeratorVal: helper.Int64ToPtr(1), 960 }, 961 MemoryStateAttr: { 962 Unit: MemoryStateUnit, 963 Desc: MemoryStateDesc, 964 IntNumeratorVal: helper.Int64ToPtr(1), 965 IntDenominatorVal: helper.Int64ToPtr(1), 966 }, 967 BAR1StateAttr: { 968 Unit: BAR1StateUnit, 969 Desc: BAR1StateDesc, 970 IntNumeratorVal: helper.Int64ToPtr(1), 971 IntDenominatorVal: helper.Int64ToPtr(256), 972 }, 973 ECCErrorsL1CacheAttr: { 974 Unit: ECCErrorsL1CacheUnit, 975 Desc: ECCErrorsL1CacheDesc, 976 IntNumeratorVal: helper.Int64ToPtr(100), 977 }, 978 ECCErrorsL2CacheAttr: { 979 Unit: ECCErrorsL2CacheUnit, 980 Desc: ECCErrorsL2CacheDesc, 981 IntNumeratorVal: helper.Int64ToPtr(100), 982 }, 983 ECCErrorsDeviceAttr: { 984 Unit: ECCErrorsDeviceUnit, 985 Desc: ECCErrorsDeviceDesc, 986 IntNumeratorVal: helper.Int64ToPtr(100), 987 }, 988 }, 989 }, 990 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 991 }, 992 }, 993 { 994 Name: "DecoderUtilization is nil", 995 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 996 ItemStat: &nvml.StatsData{ 997 DeviceData: &nvml.DeviceData{ 998 UUID: "UUID1", 999 DeviceName: helper.StringToPtr("DeviceName1"), 1000 MemoryMiB: helper.Uint64ToPtr(1), 1001 PowerW: helper.UintToPtr(1), 1002 BAR1MiB: helper.Uint64ToPtr(256), 1003 }, 1004 PowerUsageW: helper.UintToPtr(1), 1005 GPUUtilization: helper.UintToPtr(1), 1006 MemoryUtilization: helper.UintToPtr(1), 1007 EncoderUtilization: helper.UintToPtr(1), 1008 DecoderUtilization: nil, 1009 TemperatureC: helper.UintToPtr(1), 1010 UsedMemoryMiB: helper.Uint64ToPtr(1), 1011 BAR1UsedMiB: helper.Uint64ToPtr(1), 1012 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1013 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1014 ECCErrorsDevice: helper.Uint64ToPtr(100), 1015 }, 1016 ExpectedResult: &device.DeviceStats{ 1017 Summary: &structs.StatValue{ 1018 Unit: MemoryStateUnit, 1019 Desc: MemoryStateDesc, 1020 IntNumeratorVal: helper.Int64ToPtr(1), 1021 IntDenominatorVal: helper.Int64ToPtr(1), 1022 }, 1023 Stats: &structs.StatObject{ 1024 Attributes: map[string]*structs.StatValue{ 1025 PowerUsageAttr: { 1026 Unit: PowerUsageUnit, 1027 Desc: PowerUsageDesc, 1028 IntNumeratorVal: helper.Int64ToPtr(1), 1029 IntDenominatorVal: helper.Int64ToPtr(1), 1030 }, 1031 GPUUtilizationAttr: { 1032 Unit: GPUUtilizationUnit, 1033 Desc: GPUUtilizationDesc, 1034 IntNumeratorVal: helper.Int64ToPtr(1), 1035 }, 1036 MemoryUtilizationAttr: { 1037 Unit: MemoryUtilizationUnit, 1038 Desc: MemoryUtilizationDesc, 1039 IntNumeratorVal: helper.Int64ToPtr(1), 1040 }, 1041 EncoderUtilizationAttr: { 1042 Unit: EncoderUtilizationUnit, 1043 Desc: EncoderUtilizationDesc, 1044 IntNumeratorVal: helper.Int64ToPtr(1), 1045 }, 1046 DecoderUtilizationAttr: { 1047 Unit: DecoderUtilizationUnit, 1048 Desc: DecoderUtilizationDesc, 1049 StringVal: helper.StringToPtr(notAvailable), 1050 }, 1051 TemperatureAttr: { 1052 Unit: TemperatureUnit, 1053 Desc: TemperatureDesc, 1054 IntNumeratorVal: helper.Int64ToPtr(1), 1055 }, 1056 MemoryStateAttr: { 1057 Unit: MemoryStateUnit, 1058 Desc: MemoryStateDesc, 1059 IntNumeratorVal: helper.Int64ToPtr(1), 1060 IntDenominatorVal: helper.Int64ToPtr(1), 1061 }, 1062 BAR1StateAttr: { 1063 Unit: BAR1StateUnit, 1064 Desc: BAR1StateDesc, 1065 IntNumeratorVal: helper.Int64ToPtr(1), 1066 IntDenominatorVal: helper.Int64ToPtr(256), 1067 }, 1068 ECCErrorsL1CacheAttr: { 1069 Unit: ECCErrorsL1CacheUnit, 1070 Desc: ECCErrorsL1CacheDesc, 1071 IntNumeratorVal: helper.Int64ToPtr(100), 1072 }, 1073 ECCErrorsL2CacheAttr: { 1074 Unit: ECCErrorsL2CacheUnit, 1075 Desc: ECCErrorsL2CacheDesc, 1076 IntNumeratorVal: helper.Int64ToPtr(100), 1077 }, 1078 ECCErrorsDeviceAttr: { 1079 Unit: ECCErrorsDeviceUnit, 1080 Desc: ECCErrorsDeviceDesc, 1081 IntNumeratorVal: helper.Int64ToPtr(100), 1082 }, 1083 }, 1084 }, 1085 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1086 }, 1087 }, 1088 { 1089 Name: "Temperature is nil", 1090 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1091 ItemStat: &nvml.StatsData{ 1092 DeviceData: &nvml.DeviceData{ 1093 UUID: "UUID1", 1094 DeviceName: helper.StringToPtr("DeviceName1"), 1095 MemoryMiB: helper.Uint64ToPtr(1), 1096 PowerW: helper.UintToPtr(1), 1097 BAR1MiB: helper.Uint64ToPtr(256), 1098 }, 1099 PowerUsageW: helper.UintToPtr(1), 1100 GPUUtilization: helper.UintToPtr(1), 1101 MemoryUtilization: helper.UintToPtr(1), 1102 EncoderUtilization: helper.UintToPtr(1), 1103 DecoderUtilization: helper.UintToPtr(1), 1104 TemperatureC: nil, 1105 UsedMemoryMiB: helper.Uint64ToPtr(1), 1106 BAR1UsedMiB: helper.Uint64ToPtr(1), 1107 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1108 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1109 ECCErrorsDevice: helper.Uint64ToPtr(100), 1110 }, 1111 ExpectedResult: &device.DeviceStats{ 1112 Summary: &structs.StatValue{ 1113 Unit: MemoryStateUnit, 1114 Desc: MemoryStateDesc, 1115 IntNumeratorVal: helper.Int64ToPtr(1), 1116 IntDenominatorVal: helper.Int64ToPtr(1), 1117 }, 1118 Stats: &structs.StatObject{ 1119 Attributes: map[string]*structs.StatValue{ 1120 PowerUsageAttr: { 1121 Unit: PowerUsageUnit, 1122 Desc: PowerUsageDesc, 1123 IntNumeratorVal: helper.Int64ToPtr(1), 1124 IntDenominatorVal: helper.Int64ToPtr(1), 1125 }, 1126 GPUUtilizationAttr: { 1127 Unit: GPUUtilizationUnit, 1128 Desc: GPUUtilizationDesc, 1129 IntNumeratorVal: helper.Int64ToPtr(1), 1130 }, 1131 MemoryUtilizationAttr: { 1132 Unit: MemoryUtilizationUnit, 1133 Desc: MemoryUtilizationDesc, 1134 IntNumeratorVal: helper.Int64ToPtr(1), 1135 }, 1136 EncoderUtilizationAttr: { 1137 Unit: EncoderUtilizationUnit, 1138 Desc: EncoderUtilizationDesc, 1139 IntNumeratorVal: helper.Int64ToPtr(1), 1140 }, 1141 DecoderUtilizationAttr: { 1142 Unit: DecoderUtilizationUnit, 1143 Desc: DecoderUtilizationDesc, 1144 IntNumeratorVal: helper.Int64ToPtr(1), 1145 }, 1146 TemperatureAttr: { 1147 Unit: TemperatureUnit, 1148 Desc: TemperatureDesc, 1149 StringVal: helper.StringToPtr(notAvailable), 1150 }, 1151 MemoryStateAttr: { 1152 Unit: MemoryStateUnit, 1153 Desc: MemoryStateDesc, 1154 IntNumeratorVal: helper.Int64ToPtr(1), 1155 IntDenominatorVal: helper.Int64ToPtr(1), 1156 }, 1157 BAR1StateAttr: { 1158 Unit: BAR1StateUnit, 1159 Desc: BAR1StateDesc, 1160 IntNumeratorVal: helper.Int64ToPtr(1), 1161 IntDenominatorVal: helper.Int64ToPtr(256), 1162 }, 1163 ECCErrorsL1CacheAttr: { 1164 Unit: ECCErrorsL1CacheUnit, 1165 Desc: ECCErrorsL1CacheDesc, 1166 IntNumeratorVal: helper.Int64ToPtr(100), 1167 }, 1168 ECCErrorsL2CacheAttr: { 1169 Unit: ECCErrorsL2CacheUnit, 1170 Desc: ECCErrorsL2CacheDesc, 1171 IntNumeratorVal: helper.Int64ToPtr(100), 1172 }, 1173 ECCErrorsDeviceAttr: { 1174 Unit: ECCErrorsDeviceUnit, 1175 Desc: ECCErrorsDeviceDesc, 1176 IntNumeratorVal: helper.Int64ToPtr(100), 1177 }, 1178 }, 1179 }, 1180 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1181 }, 1182 }, 1183 { 1184 Name: "UsedMemoryMiB is nil", 1185 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1186 ItemStat: &nvml.StatsData{ 1187 DeviceData: &nvml.DeviceData{ 1188 UUID: "UUID1", 1189 DeviceName: helper.StringToPtr("DeviceName1"), 1190 MemoryMiB: helper.Uint64ToPtr(1), 1191 PowerW: helper.UintToPtr(1), 1192 BAR1MiB: helper.Uint64ToPtr(256), 1193 }, 1194 PowerUsageW: helper.UintToPtr(1), 1195 GPUUtilization: helper.UintToPtr(1), 1196 MemoryUtilization: helper.UintToPtr(1), 1197 EncoderUtilization: helper.UintToPtr(1), 1198 DecoderUtilization: helper.UintToPtr(1), 1199 TemperatureC: helper.UintToPtr(1), 1200 UsedMemoryMiB: nil, 1201 BAR1UsedMiB: helper.Uint64ToPtr(1), 1202 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1203 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1204 ECCErrorsDevice: helper.Uint64ToPtr(100), 1205 }, 1206 ExpectedResult: &device.DeviceStats{ 1207 Summary: &structs.StatValue{ 1208 Unit: MemoryStateUnit, 1209 Desc: MemoryStateDesc, 1210 StringVal: helper.StringToPtr(notAvailable), 1211 }, 1212 Stats: &structs.StatObject{ 1213 Attributes: map[string]*structs.StatValue{ 1214 PowerUsageAttr: { 1215 Unit: PowerUsageUnit, 1216 Desc: PowerUsageDesc, 1217 IntNumeratorVal: helper.Int64ToPtr(1), 1218 IntDenominatorVal: helper.Int64ToPtr(1), 1219 }, 1220 GPUUtilizationAttr: { 1221 Unit: GPUUtilizationUnit, 1222 Desc: GPUUtilizationDesc, 1223 IntNumeratorVal: helper.Int64ToPtr(1), 1224 }, 1225 MemoryUtilizationAttr: { 1226 Unit: MemoryUtilizationUnit, 1227 Desc: MemoryUtilizationDesc, 1228 IntNumeratorVal: helper.Int64ToPtr(1), 1229 }, 1230 EncoderUtilizationAttr: { 1231 Unit: EncoderUtilizationUnit, 1232 Desc: EncoderUtilizationDesc, 1233 IntNumeratorVal: helper.Int64ToPtr(1), 1234 }, 1235 DecoderUtilizationAttr: { 1236 Unit: DecoderUtilizationUnit, 1237 Desc: DecoderUtilizationDesc, 1238 IntNumeratorVal: helper.Int64ToPtr(1), 1239 }, 1240 TemperatureAttr: { 1241 Unit: TemperatureUnit, 1242 Desc: TemperatureDesc, 1243 IntNumeratorVal: helper.Int64ToPtr(1), 1244 }, 1245 MemoryStateAttr: { 1246 Unit: MemoryStateUnit, 1247 Desc: MemoryStateDesc, 1248 StringVal: helper.StringToPtr(notAvailable), 1249 }, 1250 BAR1StateAttr: { 1251 Unit: BAR1StateUnit, 1252 Desc: BAR1StateDesc, 1253 IntNumeratorVal: helper.Int64ToPtr(1), 1254 IntDenominatorVal: helper.Int64ToPtr(256), 1255 }, 1256 ECCErrorsL1CacheAttr: { 1257 Unit: ECCErrorsL1CacheUnit, 1258 Desc: ECCErrorsL1CacheDesc, 1259 IntNumeratorVal: helper.Int64ToPtr(100), 1260 }, 1261 ECCErrorsL2CacheAttr: { 1262 Unit: ECCErrorsL2CacheUnit, 1263 Desc: ECCErrorsL2CacheDesc, 1264 IntNumeratorVal: helper.Int64ToPtr(100), 1265 }, 1266 ECCErrorsDeviceAttr: { 1267 Unit: ECCErrorsDeviceUnit, 1268 Desc: ECCErrorsDeviceDesc, 1269 IntNumeratorVal: helper.Int64ToPtr(100), 1270 }, 1271 }, 1272 }, 1273 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1274 }, 1275 }, 1276 { 1277 Name: "MemoryMiB is nil", 1278 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1279 ItemStat: &nvml.StatsData{ 1280 DeviceData: &nvml.DeviceData{ 1281 UUID: "UUID1", 1282 DeviceName: helper.StringToPtr("DeviceName1"), 1283 MemoryMiB: nil, 1284 PowerW: helper.UintToPtr(1), 1285 BAR1MiB: helper.Uint64ToPtr(256), 1286 }, 1287 PowerUsageW: helper.UintToPtr(1), 1288 GPUUtilization: helper.UintToPtr(1), 1289 MemoryUtilization: helper.UintToPtr(1), 1290 EncoderUtilization: helper.UintToPtr(1), 1291 DecoderUtilization: helper.UintToPtr(1), 1292 TemperatureC: helper.UintToPtr(1), 1293 UsedMemoryMiB: helper.Uint64ToPtr(1), 1294 BAR1UsedMiB: helper.Uint64ToPtr(1), 1295 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1296 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1297 ECCErrorsDevice: helper.Uint64ToPtr(100), 1298 }, 1299 ExpectedResult: &device.DeviceStats{ 1300 Summary: &structs.StatValue{ 1301 Unit: MemoryStateUnit, 1302 Desc: MemoryStateDesc, 1303 StringVal: helper.StringToPtr(notAvailable), 1304 }, 1305 Stats: &structs.StatObject{ 1306 Attributes: map[string]*structs.StatValue{ 1307 PowerUsageAttr: { 1308 Unit: PowerUsageUnit, 1309 Desc: PowerUsageDesc, 1310 IntNumeratorVal: helper.Int64ToPtr(1), 1311 IntDenominatorVal: helper.Int64ToPtr(1), 1312 }, 1313 GPUUtilizationAttr: { 1314 Unit: GPUUtilizationUnit, 1315 Desc: GPUUtilizationDesc, 1316 IntNumeratorVal: helper.Int64ToPtr(1), 1317 }, 1318 MemoryUtilizationAttr: { 1319 Unit: MemoryUtilizationUnit, 1320 Desc: MemoryUtilizationDesc, 1321 IntNumeratorVal: helper.Int64ToPtr(1), 1322 }, 1323 EncoderUtilizationAttr: { 1324 Unit: EncoderUtilizationUnit, 1325 Desc: EncoderUtilizationDesc, 1326 IntNumeratorVal: helper.Int64ToPtr(1), 1327 }, 1328 DecoderUtilizationAttr: { 1329 Unit: DecoderUtilizationUnit, 1330 Desc: DecoderUtilizationDesc, 1331 IntNumeratorVal: helper.Int64ToPtr(1), 1332 }, 1333 TemperatureAttr: { 1334 Unit: TemperatureUnit, 1335 Desc: TemperatureDesc, 1336 IntNumeratorVal: helper.Int64ToPtr(1), 1337 }, 1338 MemoryStateAttr: { 1339 Unit: MemoryStateUnit, 1340 Desc: MemoryStateDesc, 1341 StringVal: helper.StringToPtr(notAvailable), 1342 }, 1343 BAR1StateAttr: { 1344 Unit: BAR1StateUnit, 1345 Desc: BAR1StateDesc, 1346 IntNumeratorVal: helper.Int64ToPtr(1), 1347 IntDenominatorVal: helper.Int64ToPtr(256), 1348 }, 1349 ECCErrorsL1CacheAttr: { 1350 Unit: ECCErrorsL1CacheUnit, 1351 Desc: ECCErrorsL1CacheDesc, 1352 IntNumeratorVal: helper.Int64ToPtr(100), 1353 }, 1354 ECCErrorsL2CacheAttr: { 1355 Unit: ECCErrorsL2CacheUnit, 1356 Desc: ECCErrorsL2CacheDesc, 1357 IntNumeratorVal: helper.Int64ToPtr(100), 1358 }, 1359 ECCErrorsDeviceAttr: { 1360 Unit: ECCErrorsDeviceUnit, 1361 Desc: ECCErrorsDeviceDesc, 1362 IntNumeratorVal: helper.Int64ToPtr(100), 1363 }, 1364 }, 1365 }, 1366 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1367 }, 1368 }, 1369 { 1370 Name: "BAR1UsedMiB is nil", 1371 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1372 ItemStat: &nvml.StatsData{ 1373 DeviceData: &nvml.DeviceData{ 1374 UUID: "UUID1", 1375 DeviceName: helper.StringToPtr("DeviceName1"), 1376 MemoryMiB: helper.Uint64ToPtr(1), 1377 PowerW: helper.UintToPtr(1), 1378 BAR1MiB: helper.Uint64ToPtr(256), 1379 }, 1380 PowerUsageW: helper.UintToPtr(1), 1381 GPUUtilization: helper.UintToPtr(1), 1382 MemoryUtilization: helper.UintToPtr(1), 1383 EncoderUtilization: helper.UintToPtr(1), 1384 DecoderUtilization: helper.UintToPtr(1), 1385 TemperatureC: helper.UintToPtr(1), 1386 UsedMemoryMiB: helper.Uint64ToPtr(1), 1387 BAR1UsedMiB: nil, 1388 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1389 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1390 ECCErrorsDevice: helper.Uint64ToPtr(100), 1391 }, 1392 ExpectedResult: &device.DeviceStats{ 1393 Summary: &structs.StatValue{ 1394 Unit: MemoryStateUnit, 1395 Desc: MemoryStateDesc, 1396 IntNumeratorVal: helper.Int64ToPtr(1), 1397 IntDenominatorVal: helper.Int64ToPtr(1), 1398 }, 1399 Stats: &structs.StatObject{ 1400 Attributes: map[string]*structs.StatValue{ 1401 PowerUsageAttr: { 1402 Unit: PowerUsageUnit, 1403 Desc: PowerUsageDesc, 1404 IntNumeratorVal: helper.Int64ToPtr(1), 1405 IntDenominatorVal: helper.Int64ToPtr(1), 1406 }, 1407 GPUUtilizationAttr: { 1408 Unit: GPUUtilizationUnit, 1409 Desc: GPUUtilizationDesc, 1410 IntNumeratorVal: helper.Int64ToPtr(1), 1411 }, 1412 MemoryUtilizationAttr: { 1413 Unit: MemoryUtilizationUnit, 1414 Desc: MemoryUtilizationDesc, 1415 IntNumeratorVal: helper.Int64ToPtr(1), 1416 }, 1417 EncoderUtilizationAttr: { 1418 Unit: EncoderUtilizationUnit, 1419 Desc: EncoderUtilizationDesc, 1420 IntNumeratorVal: helper.Int64ToPtr(1), 1421 }, 1422 DecoderUtilizationAttr: { 1423 Unit: DecoderUtilizationUnit, 1424 Desc: DecoderUtilizationDesc, 1425 IntNumeratorVal: helper.Int64ToPtr(1), 1426 }, 1427 TemperatureAttr: { 1428 Unit: TemperatureUnit, 1429 Desc: TemperatureDesc, 1430 IntNumeratorVal: helper.Int64ToPtr(1), 1431 }, 1432 MemoryStateAttr: { 1433 Unit: MemoryStateUnit, 1434 Desc: MemoryStateDesc, 1435 IntNumeratorVal: helper.Int64ToPtr(1), 1436 IntDenominatorVal: helper.Int64ToPtr(1), 1437 }, 1438 BAR1StateAttr: { 1439 Unit: BAR1StateUnit, 1440 Desc: BAR1StateDesc, 1441 StringVal: helper.StringToPtr(notAvailable), 1442 }, 1443 ECCErrorsL1CacheAttr: { 1444 Unit: ECCErrorsL1CacheUnit, 1445 Desc: ECCErrorsL1CacheDesc, 1446 IntNumeratorVal: helper.Int64ToPtr(100), 1447 }, 1448 ECCErrorsL2CacheAttr: { 1449 Unit: ECCErrorsL2CacheUnit, 1450 Desc: ECCErrorsL2CacheDesc, 1451 IntNumeratorVal: helper.Int64ToPtr(100), 1452 }, 1453 ECCErrorsDeviceAttr: { 1454 Unit: ECCErrorsDeviceUnit, 1455 Desc: ECCErrorsDeviceDesc, 1456 IntNumeratorVal: helper.Int64ToPtr(100), 1457 }, 1458 }, 1459 }, 1460 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1461 }, 1462 }, 1463 { 1464 Name: "BAR1MiB is nil", 1465 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1466 ItemStat: &nvml.StatsData{ 1467 DeviceData: &nvml.DeviceData{ 1468 UUID: "UUID1", 1469 DeviceName: helper.StringToPtr("DeviceName1"), 1470 MemoryMiB: helper.Uint64ToPtr(1), 1471 PowerW: helper.UintToPtr(1), 1472 BAR1MiB: nil, 1473 }, 1474 PowerUsageW: helper.UintToPtr(1), 1475 GPUUtilization: helper.UintToPtr(1), 1476 MemoryUtilization: helper.UintToPtr(1), 1477 EncoderUtilization: helper.UintToPtr(1), 1478 DecoderUtilization: helper.UintToPtr(1), 1479 TemperatureC: helper.UintToPtr(1), 1480 UsedMemoryMiB: helper.Uint64ToPtr(1), 1481 BAR1UsedMiB: helper.Uint64ToPtr(1), 1482 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1483 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1484 ECCErrorsDevice: helper.Uint64ToPtr(100), 1485 }, 1486 ExpectedResult: &device.DeviceStats{ 1487 Summary: &structs.StatValue{ 1488 Unit: MemoryStateUnit, 1489 Desc: MemoryStateDesc, 1490 IntNumeratorVal: helper.Int64ToPtr(1), 1491 IntDenominatorVal: helper.Int64ToPtr(1), 1492 }, 1493 Stats: &structs.StatObject{ 1494 Attributes: map[string]*structs.StatValue{ 1495 PowerUsageAttr: { 1496 Unit: PowerUsageUnit, 1497 Desc: PowerUsageDesc, 1498 IntNumeratorVal: helper.Int64ToPtr(1), 1499 IntDenominatorVal: helper.Int64ToPtr(1), 1500 }, 1501 GPUUtilizationAttr: { 1502 Unit: GPUUtilizationUnit, 1503 Desc: GPUUtilizationDesc, 1504 IntNumeratorVal: helper.Int64ToPtr(1), 1505 }, 1506 MemoryUtilizationAttr: { 1507 Unit: MemoryUtilizationUnit, 1508 Desc: MemoryUtilizationDesc, 1509 IntNumeratorVal: helper.Int64ToPtr(1), 1510 }, 1511 EncoderUtilizationAttr: { 1512 Unit: EncoderUtilizationUnit, 1513 Desc: EncoderUtilizationDesc, 1514 IntNumeratorVal: helper.Int64ToPtr(1), 1515 }, 1516 DecoderUtilizationAttr: { 1517 Unit: DecoderUtilizationUnit, 1518 Desc: DecoderUtilizationDesc, 1519 IntNumeratorVal: helper.Int64ToPtr(1), 1520 }, 1521 TemperatureAttr: { 1522 Unit: TemperatureUnit, 1523 Desc: TemperatureDesc, 1524 IntNumeratorVal: helper.Int64ToPtr(1), 1525 }, 1526 MemoryStateAttr: { 1527 Unit: MemoryStateUnit, 1528 Desc: MemoryStateDesc, 1529 IntNumeratorVal: helper.Int64ToPtr(1), 1530 IntDenominatorVal: helper.Int64ToPtr(1), 1531 }, 1532 BAR1StateAttr: { 1533 Unit: BAR1StateUnit, 1534 Desc: BAR1StateDesc, 1535 StringVal: helper.StringToPtr(notAvailable), 1536 }, 1537 ECCErrorsL1CacheAttr: { 1538 Unit: ECCErrorsL1CacheUnit, 1539 Desc: ECCErrorsL1CacheDesc, 1540 IntNumeratorVal: helper.Int64ToPtr(100), 1541 }, 1542 ECCErrorsL2CacheAttr: { 1543 Unit: ECCErrorsL2CacheUnit, 1544 Desc: ECCErrorsL2CacheDesc, 1545 IntNumeratorVal: helper.Int64ToPtr(100), 1546 }, 1547 ECCErrorsDeviceAttr: { 1548 Unit: ECCErrorsDeviceUnit, 1549 Desc: ECCErrorsDeviceDesc, 1550 IntNumeratorVal: helper.Int64ToPtr(100), 1551 }, 1552 }, 1553 }, 1554 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1555 }, 1556 }, 1557 { 1558 Name: "ECCErrorsL1Cache is nil", 1559 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1560 ItemStat: &nvml.StatsData{ 1561 DeviceData: &nvml.DeviceData{ 1562 UUID: "UUID1", 1563 DeviceName: helper.StringToPtr("DeviceName1"), 1564 MemoryMiB: helper.Uint64ToPtr(1), 1565 PowerW: helper.UintToPtr(1), 1566 BAR1MiB: helper.Uint64ToPtr(256), 1567 }, 1568 PowerUsageW: helper.UintToPtr(1), 1569 GPUUtilization: helper.UintToPtr(1), 1570 MemoryUtilization: helper.UintToPtr(1), 1571 EncoderUtilization: helper.UintToPtr(1), 1572 DecoderUtilization: helper.UintToPtr(1), 1573 TemperatureC: helper.UintToPtr(1), 1574 UsedMemoryMiB: helper.Uint64ToPtr(1), 1575 BAR1UsedMiB: helper.Uint64ToPtr(1), 1576 ECCErrorsL1Cache: nil, 1577 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1578 ECCErrorsDevice: helper.Uint64ToPtr(100), 1579 }, 1580 ExpectedResult: &device.DeviceStats{ 1581 Summary: &structs.StatValue{ 1582 Unit: MemoryStateUnit, 1583 Desc: MemoryStateDesc, 1584 IntNumeratorVal: helper.Int64ToPtr(1), 1585 IntDenominatorVal: helper.Int64ToPtr(1), 1586 }, 1587 Stats: &structs.StatObject{ 1588 Attributes: map[string]*structs.StatValue{ 1589 PowerUsageAttr: { 1590 Unit: PowerUsageUnit, 1591 Desc: PowerUsageDesc, 1592 IntNumeratorVal: helper.Int64ToPtr(1), 1593 IntDenominatorVal: helper.Int64ToPtr(1), 1594 }, 1595 GPUUtilizationAttr: { 1596 Unit: GPUUtilizationUnit, 1597 Desc: GPUUtilizationDesc, 1598 IntNumeratorVal: helper.Int64ToPtr(1), 1599 }, 1600 MemoryUtilizationAttr: { 1601 Unit: MemoryUtilizationUnit, 1602 Desc: MemoryUtilizationDesc, 1603 IntNumeratorVal: helper.Int64ToPtr(1), 1604 }, 1605 EncoderUtilizationAttr: { 1606 Unit: EncoderUtilizationUnit, 1607 Desc: EncoderUtilizationDesc, 1608 IntNumeratorVal: helper.Int64ToPtr(1), 1609 }, 1610 DecoderUtilizationAttr: { 1611 Unit: DecoderUtilizationUnit, 1612 Desc: DecoderUtilizationDesc, 1613 IntNumeratorVal: helper.Int64ToPtr(1), 1614 }, 1615 TemperatureAttr: { 1616 Unit: TemperatureUnit, 1617 Desc: TemperatureDesc, 1618 IntNumeratorVal: helper.Int64ToPtr(1), 1619 }, 1620 MemoryStateAttr: { 1621 Unit: MemoryStateUnit, 1622 Desc: MemoryStateDesc, 1623 IntNumeratorVal: helper.Int64ToPtr(1), 1624 IntDenominatorVal: helper.Int64ToPtr(1), 1625 }, 1626 BAR1StateAttr: { 1627 Unit: BAR1StateUnit, 1628 Desc: BAR1StateDesc, 1629 IntNumeratorVal: helper.Int64ToPtr(1), 1630 IntDenominatorVal: helper.Int64ToPtr(256), 1631 }, 1632 ECCErrorsL1CacheAttr: { 1633 Unit: ECCErrorsL1CacheUnit, 1634 Desc: ECCErrorsL1CacheDesc, 1635 StringVal: helper.StringToPtr(notAvailable), 1636 }, 1637 ECCErrorsL2CacheAttr: { 1638 Unit: ECCErrorsL2CacheUnit, 1639 Desc: ECCErrorsL2CacheDesc, 1640 IntNumeratorVal: helper.Int64ToPtr(100), 1641 }, 1642 ECCErrorsDeviceAttr: { 1643 Unit: ECCErrorsDeviceUnit, 1644 Desc: ECCErrorsDeviceDesc, 1645 IntNumeratorVal: helper.Int64ToPtr(100), 1646 }, 1647 }, 1648 }, 1649 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1650 }, 1651 }, 1652 { 1653 Name: "ECCErrorsL2Cache is nil", 1654 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1655 ItemStat: &nvml.StatsData{ 1656 DeviceData: &nvml.DeviceData{ 1657 UUID: "UUID1", 1658 DeviceName: helper.StringToPtr("DeviceName1"), 1659 MemoryMiB: helper.Uint64ToPtr(1), 1660 PowerW: helper.UintToPtr(1), 1661 BAR1MiB: helper.Uint64ToPtr(256), 1662 }, 1663 PowerUsageW: helper.UintToPtr(1), 1664 GPUUtilization: helper.UintToPtr(1), 1665 MemoryUtilization: helper.UintToPtr(1), 1666 EncoderUtilization: helper.UintToPtr(1), 1667 DecoderUtilization: helper.UintToPtr(1), 1668 TemperatureC: helper.UintToPtr(1), 1669 UsedMemoryMiB: helper.Uint64ToPtr(1), 1670 BAR1UsedMiB: helper.Uint64ToPtr(1), 1671 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1672 ECCErrorsL2Cache: nil, 1673 ECCErrorsDevice: helper.Uint64ToPtr(100), 1674 }, 1675 ExpectedResult: &device.DeviceStats{ 1676 Summary: &structs.StatValue{ 1677 Unit: MemoryStateUnit, 1678 Desc: MemoryStateDesc, 1679 IntNumeratorVal: helper.Int64ToPtr(1), 1680 IntDenominatorVal: helper.Int64ToPtr(1), 1681 }, 1682 Stats: &structs.StatObject{ 1683 Attributes: map[string]*structs.StatValue{ 1684 PowerUsageAttr: { 1685 Unit: PowerUsageUnit, 1686 Desc: PowerUsageDesc, 1687 IntNumeratorVal: helper.Int64ToPtr(1), 1688 IntDenominatorVal: helper.Int64ToPtr(1), 1689 }, 1690 GPUUtilizationAttr: { 1691 Unit: GPUUtilizationUnit, 1692 Desc: GPUUtilizationDesc, 1693 IntNumeratorVal: helper.Int64ToPtr(1), 1694 }, 1695 MemoryUtilizationAttr: { 1696 Unit: MemoryUtilizationUnit, 1697 Desc: MemoryUtilizationDesc, 1698 IntNumeratorVal: helper.Int64ToPtr(1), 1699 }, 1700 EncoderUtilizationAttr: { 1701 Unit: EncoderUtilizationUnit, 1702 Desc: EncoderUtilizationDesc, 1703 IntNumeratorVal: helper.Int64ToPtr(1), 1704 }, 1705 DecoderUtilizationAttr: { 1706 Unit: DecoderUtilizationUnit, 1707 Desc: DecoderUtilizationDesc, 1708 IntNumeratorVal: helper.Int64ToPtr(1), 1709 }, 1710 TemperatureAttr: { 1711 Unit: TemperatureUnit, 1712 Desc: TemperatureDesc, 1713 IntNumeratorVal: helper.Int64ToPtr(1), 1714 }, 1715 MemoryStateAttr: { 1716 Unit: MemoryStateUnit, 1717 Desc: MemoryStateDesc, 1718 IntNumeratorVal: helper.Int64ToPtr(1), 1719 IntDenominatorVal: helper.Int64ToPtr(1), 1720 }, 1721 BAR1StateAttr: { 1722 Unit: BAR1StateUnit, 1723 Desc: BAR1StateDesc, 1724 IntNumeratorVal: helper.Int64ToPtr(1), 1725 IntDenominatorVal: helper.Int64ToPtr(256), 1726 }, 1727 ECCErrorsL1CacheAttr: { 1728 Unit: ECCErrorsL1CacheUnit, 1729 Desc: ECCErrorsL1CacheDesc, 1730 IntNumeratorVal: helper.Int64ToPtr(100), 1731 }, 1732 ECCErrorsL2CacheAttr: { 1733 Unit: ECCErrorsL2CacheUnit, 1734 Desc: ECCErrorsL2CacheDesc, 1735 StringVal: helper.StringToPtr(notAvailable), 1736 }, 1737 ECCErrorsDeviceAttr: { 1738 Unit: ECCErrorsDeviceUnit, 1739 Desc: ECCErrorsDeviceDesc, 1740 IntNumeratorVal: helper.Int64ToPtr(100), 1741 }, 1742 }, 1743 }, 1744 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1745 }, 1746 }, 1747 { 1748 Name: "ECCErrorsDevice is nil", 1749 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1750 ItemStat: &nvml.StatsData{ 1751 DeviceData: &nvml.DeviceData{ 1752 UUID: "UUID1", 1753 DeviceName: helper.StringToPtr("DeviceName1"), 1754 MemoryMiB: helper.Uint64ToPtr(1), 1755 PowerW: helper.UintToPtr(1), 1756 BAR1MiB: helper.Uint64ToPtr(256), 1757 }, 1758 PowerUsageW: helper.UintToPtr(1), 1759 GPUUtilization: helper.UintToPtr(1), 1760 MemoryUtilization: helper.UintToPtr(1), 1761 EncoderUtilization: helper.UintToPtr(1), 1762 DecoderUtilization: helper.UintToPtr(1), 1763 TemperatureC: helper.UintToPtr(1), 1764 UsedMemoryMiB: helper.Uint64ToPtr(1), 1765 BAR1UsedMiB: helper.Uint64ToPtr(1), 1766 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1767 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1768 ECCErrorsDevice: nil, 1769 }, 1770 ExpectedResult: &device.DeviceStats{ 1771 Summary: &structs.StatValue{ 1772 Unit: MemoryStateUnit, 1773 Desc: MemoryStateDesc, 1774 IntNumeratorVal: helper.Int64ToPtr(1), 1775 IntDenominatorVal: helper.Int64ToPtr(1), 1776 }, 1777 Stats: &structs.StatObject{ 1778 Attributes: map[string]*structs.StatValue{ 1779 PowerUsageAttr: { 1780 Unit: PowerUsageUnit, 1781 Desc: PowerUsageDesc, 1782 IntNumeratorVal: helper.Int64ToPtr(1), 1783 IntDenominatorVal: helper.Int64ToPtr(1), 1784 }, 1785 GPUUtilizationAttr: { 1786 Unit: GPUUtilizationUnit, 1787 Desc: GPUUtilizationDesc, 1788 IntNumeratorVal: helper.Int64ToPtr(1), 1789 }, 1790 MemoryUtilizationAttr: { 1791 Unit: MemoryUtilizationUnit, 1792 Desc: MemoryUtilizationDesc, 1793 IntNumeratorVal: helper.Int64ToPtr(1), 1794 }, 1795 EncoderUtilizationAttr: { 1796 Unit: EncoderUtilizationUnit, 1797 Desc: EncoderUtilizationDesc, 1798 IntNumeratorVal: helper.Int64ToPtr(1), 1799 }, 1800 DecoderUtilizationAttr: { 1801 Unit: DecoderUtilizationUnit, 1802 Desc: DecoderUtilizationDesc, 1803 IntNumeratorVal: helper.Int64ToPtr(1), 1804 }, 1805 TemperatureAttr: { 1806 Unit: TemperatureUnit, 1807 Desc: TemperatureDesc, 1808 IntNumeratorVal: helper.Int64ToPtr(1), 1809 }, 1810 MemoryStateAttr: { 1811 Unit: MemoryStateUnit, 1812 Desc: MemoryStateDesc, 1813 IntNumeratorVal: helper.Int64ToPtr(1), 1814 IntDenominatorVal: helper.Int64ToPtr(1), 1815 }, 1816 BAR1StateAttr: { 1817 Unit: BAR1StateUnit, 1818 Desc: BAR1StateDesc, 1819 IntNumeratorVal: helper.Int64ToPtr(1), 1820 IntDenominatorVal: helper.Int64ToPtr(256), 1821 }, 1822 ECCErrorsL1CacheAttr: { 1823 Unit: ECCErrorsL1CacheUnit, 1824 Desc: ECCErrorsL1CacheDesc, 1825 IntNumeratorVal: helper.Int64ToPtr(100), 1826 }, 1827 ECCErrorsL2CacheAttr: { 1828 Unit: ECCErrorsL2CacheUnit, 1829 Desc: ECCErrorsL2CacheDesc, 1830 IntNumeratorVal: helper.Int64ToPtr(100), 1831 }, 1832 ECCErrorsDeviceAttr: { 1833 Unit: ECCErrorsDeviceUnit, 1834 Desc: ECCErrorsDeviceDesc, 1835 StringVal: helper.StringToPtr(notAvailable), 1836 }, 1837 }, 1838 }, 1839 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1840 }, 1841 }, 1842 } { 1843 actualResult := statsForItem(testCase.ItemStat, testCase.Timestamp) 1844 require.New(t).Equal(testCase.ExpectedResult, actualResult) 1845 } 1846 } 1847 1848 func TestStatsForGroup(t *testing.T) { 1849 for _, testCase := range []struct { 1850 Name string 1851 Timestamp time.Time 1852 GroupStats []*nvml.StatsData 1853 GroupName string 1854 ExpectedResult *device.DeviceGroupStats 1855 }{ 1856 { 1857 Name: "make sure that all data is transformed correctly", 1858 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1859 GroupName: "DeviceName1", 1860 GroupStats: []*nvml.StatsData{ 1861 { 1862 DeviceData: &nvml.DeviceData{ 1863 UUID: "UUID1", 1864 DeviceName: helper.StringToPtr("DeviceName1"), 1865 MemoryMiB: helper.Uint64ToPtr(1), 1866 PowerW: helper.UintToPtr(1), 1867 BAR1MiB: helper.Uint64ToPtr(256), 1868 }, 1869 PowerUsageW: helper.UintToPtr(1), 1870 GPUUtilization: helper.UintToPtr(1), 1871 MemoryUtilization: helper.UintToPtr(1), 1872 EncoderUtilization: helper.UintToPtr(1), 1873 DecoderUtilization: helper.UintToPtr(1), 1874 TemperatureC: helper.UintToPtr(1), 1875 UsedMemoryMiB: helper.Uint64ToPtr(1), 1876 BAR1UsedMiB: helper.Uint64ToPtr(1), 1877 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 1878 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 1879 ECCErrorsDevice: helper.Uint64ToPtr(100), 1880 }, 1881 { 1882 DeviceData: &nvml.DeviceData{ 1883 UUID: "UUID2", 1884 DeviceName: helper.StringToPtr("DeviceName2"), 1885 MemoryMiB: helper.Uint64ToPtr(2), 1886 PowerW: helper.UintToPtr(2), 1887 BAR1MiB: helper.Uint64ToPtr(256), 1888 }, 1889 PowerUsageW: helper.UintToPtr(2), 1890 GPUUtilization: helper.UintToPtr(2), 1891 MemoryUtilization: helper.UintToPtr(2), 1892 EncoderUtilization: helper.UintToPtr(2), 1893 DecoderUtilization: helper.UintToPtr(2), 1894 TemperatureC: helper.UintToPtr(2), 1895 UsedMemoryMiB: helper.Uint64ToPtr(2), 1896 BAR1UsedMiB: helper.Uint64ToPtr(2), 1897 ECCErrorsL1Cache: helper.Uint64ToPtr(200), 1898 ECCErrorsL2Cache: helper.Uint64ToPtr(200), 1899 ECCErrorsDevice: helper.Uint64ToPtr(200), 1900 }, 1901 { 1902 DeviceData: &nvml.DeviceData{ 1903 UUID: "UUID3", 1904 DeviceName: helper.StringToPtr("DeviceName3"), 1905 MemoryMiB: helper.Uint64ToPtr(3), 1906 PowerW: helper.UintToPtr(3), 1907 BAR1MiB: helper.Uint64ToPtr(256), 1908 }, 1909 PowerUsageW: helper.UintToPtr(3), 1910 GPUUtilization: helper.UintToPtr(3), 1911 MemoryUtilization: helper.UintToPtr(3), 1912 EncoderUtilization: helper.UintToPtr(3), 1913 DecoderUtilization: helper.UintToPtr(3), 1914 TemperatureC: helper.UintToPtr(3), 1915 UsedMemoryMiB: helper.Uint64ToPtr(3), 1916 BAR1UsedMiB: helper.Uint64ToPtr(3), 1917 ECCErrorsL1Cache: helper.Uint64ToPtr(300), 1918 ECCErrorsL2Cache: helper.Uint64ToPtr(300), 1919 ECCErrorsDevice: helper.Uint64ToPtr(300), 1920 }, 1921 }, 1922 ExpectedResult: &device.DeviceGroupStats{ 1923 Vendor: vendor, 1924 Type: deviceType, 1925 Name: "DeviceName1", 1926 InstanceStats: map[string]*device.DeviceStats{ 1927 "UUID1": { 1928 Summary: &structs.StatValue{ 1929 Unit: MemoryStateUnit, 1930 Desc: MemoryStateDesc, 1931 IntNumeratorVal: helper.Int64ToPtr(1), 1932 IntDenominatorVal: helper.Int64ToPtr(1), 1933 }, 1934 Stats: &structs.StatObject{ 1935 Attributes: map[string]*structs.StatValue{ 1936 PowerUsageAttr: { 1937 Unit: PowerUsageUnit, 1938 Desc: PowerUsageDesc, 1939 IntNumeratorVal: helper.Int64ToPtr(1), 1940 IntDenominatorVal: helper.Int64ToPtr(1), 1941 }, 1942 GPUUtilizationAttr: { 1943 Unit: GPUUtilizationUnit, 1944 Desc: GPUUtilizationDesc, 1945 IntNumeratorVal: helper.Int64ToPtr(1), 1946 }, 1947 MemoryUtilizationAttr: { 1948 Unit: MemoryUtilizationUnit, 1949 Desc: MemoryUtilizationDesc, 1950 IntNumeratorVal: helper.Int64ToPtr(1), 1951 }, 1952 EncoderUtilizationAttr: { 1953 Unit: EncoderUtilizationUnit, 1954 Desc: EncoderUtilizationDesc, 1955 IntNumeratorVal: helper.Int64ToPtr(1), 1956 }, 1957 DecoderUtilizationAttr: { 1958 Unit: DecoderUtilizationUnit, 1959 Desc: DecoderUtilizationDesc, 1960 IntNumeratorVal: helper.Int64ToPtr(1), 1961 }, 1962 TemperatureAttr: { 1963 Unit: TemperatureUnit, 1964 Desc: TemperatureDesc, 1965 IntNumeratorVal: helper.Int64ToPtr(1), 1966 }, 1967 MemoryStateAttr: { 1968 Unit: MemoryStateUnit, 1969 Desc: MemoryStateDesc, 1970 IntNumeratorVal: helper.Int64ToPtr(1), 1971 IntDenominatorVal: helper.Int64ToPtr(1), 1972 }, 1973 BAR1StateAttr: { 1974 Unit: BAR1StateUnit, 1975 Desc: BAR1StateDesc, 1976 IntNumeratorVal: helper.Int64ToPtr(1), 1977 IntDenominatorVal: helper.Int64ToPtr(256), 1978 }, 1979 ECCErrorsL1CacheAttr: { 1980 Unit: ECCErrorsL1CacheUnit, 1981 Desc: ECCErrorsL1CacheDesc, 1982 IntNumeratorVal: helper.Int64ToPtr(100), 1983 }, 1984 ECCErrorsL2CacheAttr: { 1985 Unit: ECCErrorsL2CacheUnit, 1986 Desc: ECCErrorsL2CacheDesc, 1987 IntNumeratorVal: helper.Int64ToPtr(100), 1988 }, 1989 ECCErrorsDeviceAttr: { 1990 Unit: ECCErrorsDeviceUnit, 1991 Desc: ECCErrorsDeviceDesc, 1992 IntNumeratorVal: helper.Int64ToPtr(100), 1993 }, 1994 }, 1995 }, 1996 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 1997 }, 1998 "UUID2": { 1999 Summary: &structs.StatValue{ 2000 Unit: MemoryStateUnit, 2001 Desc: MemoryStateDesc, 2002 IntNumeratorVal: helper.Int64ToPtr(2), 2003 IntDenominatorVal: helper.Int64ToPtr(2), 2004 }, 2005 Stats: &structs.StatObject{ 2006 Attributes: map[string]*structs.StatValue{ 2007 PowerUsageAttr: { 2008 Unit: PowerUsageUnit, 2009 Desc: PowerUsageDesc, 2010 IntNumeratorVal: helper.Int64ToPtr(2), 2011 IntDenominatorVal: helper.Int64ToPtr(2), 2012 }, 2013 GPUUtilizationAttr: { 2014 Unit: GPUUtilizationUnit, 2015 Desc: GPUUtilizationDesc, 2016 IntNumeratorVal: helper.Int64ToPtr(2), 2017 }, 2018 MemoryUtilizationAttr: { 2019 Unit: MemoryUtilizationUnit, 2020 Desc: MemoryUtilizationDesc, 2021 IntNumeratorVal: helper.Int64ToPtr(2), 2022 }, 2023 EncoderUtilizationAttr: { 2024 Unit: EncoderUtilizationUnit, 2025 Desc: EncoderUtilizationDesc, 2026 IntNumeratorVal: helper.Int64ToPtr(2), 2027 }, 2028 DecoderUtilizationAttr: { 2029 Unit: DecoderUtilizationUnit, 2030 Desc: DecoderUtilizationDesc, 2031 IntNumeratorVal: helper.Int64ToPtr(2), 2032 }, 2033 TemperatureAttr: { 2034 Unit: TemperatureUnit, 2035 Desc: TemperatureDesc, 2036 IntNumeratorVal: helper.Int64ToPtr(2), 2037 }, 2038 MemoryStateAttr: { 2039 Unit: MemoryStateUnit, 2040 Desc: MemoryStateDesc, 2041 IntNumeratorVal: helper.Int64ToPtr(2), 2042 IntDenominatorVal: helper.Int64ToPtr(2), 2043 }, 2044 BAR1StateAttr: { 2045 Unit: BAR1StateUnit, 2046 Desc: BAR1StateDesc, 2047 IntNumeratorVal: helper.Int64ToPtr(2), 2048 IntDenominatorVal: helper.Int64ToPtr(256), 2049 }, 2050 ECCErrorsL1CacheAttr: { 2051 Unit: ECCErrorsL1CacheUnit, 2052 Desc: ECCErrorsL1CacheDesc, 2053 IntNumeratorVal: helper.Int64ToPtr(200), 2054 }, 2055 ECCErrorsL2CacheAttr: { 2056 Unit: ECCErrorsL2CacheUnit, 2057 Desc: ECCErrorsL2CacheDesc, 2058 IntNumeratorVal: helper.Int64ToPtr(200), 2059 }, 2060 ECCErrorsDeviceAttr: { 2061 Unit: ECCErrorsDeviceUnit, 2062 Desc: ECCErrorsDeviceDesc, 2063 IntNumeratorVal: helper.Int64ToPtr(200), 2064 }, 2065 }, 2066 }, 2067 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2068 }, 2069 "UUID3": { 2070 Summary: &structs.StatValue{ 2071 Unit: MemoryStateUnit, 2072 Desc: MemoryStateDesc, 2073 IntNumeratorVal: helper.Int64ToPtr(3), 2074 IntDenominatorVal: helper.Int64ToPtr(3), 2075 }, 2076 Stats: &structs.StatObject{ 2077 Attributes: map[string]*structs.StatValue{ 2078 PowerUsageAttr: { 2079 Unit: PowerUsageUnit, 2080 Desc: PowerUsageDesc, 2081 IntNumeratorVal: helper.Int64ToPtr(3), 2082 IntDenominatorVal: helper.Int64ToPtr(3), 2083 }, 2084 GPUUtilizationAttr: { 2085 Unit: GPUUtilizationUnit, 2086 Desc: GPUUtilizationDesc, 2087 IntNumeratorVal: helper.Int64ToPtr(3), 2088 }, 2089 MemoryUtilizationAttr: { 2090 Unit: MemoryUtilizationUnit, 2091 Desc: MemoryUtilizationDesc, 2092 IntNumeratorVal: helper.Int64ToPtr(3), 2093 }, 2094 EncoderUtilizationAttr: { 2095 Unit: EncoderUtilizationUnit, 2096 Desc: EncoderUtilizationDesc, 2097 IntNumeratorVal: helper.Int64ToPtr(3), 2098 }, 2099 DecoderUtilizationAttr: { 2100 Unit: DecoderUtilizationUnit, 2101 Desc: DecoderUtilizationDesc, 2102 IntNumeratorVal: helper.Int64ToPtr(3), 2103 }, 2104 TemperatureAttr: { 2105 Unit: TemperatureUnit, 2106 Desc: TemperatureDesc, 2107 IntNumeratorVal: helper.Int64ToPtr(3), 2108 }, 2109 MemoryStateAttr: { 2110 Unit: MemoryStateUnit, 2111 Desc: MemoryStateDesc, 2112 IntNumeratorVal: helper.Int64ToPtr(3), 2113 IntDenominatorVal: helper.Int64ToPtr(3), 2114 }, 2115 BAR1StateAttr: { 2116 Unit: BAR1StateUnit, 2117 Desc: BAR1StateDesc, 2118 IntNumeratorVal: helper.Int64ToPtr(3), 2119 IntDenominatorVal: helper.Int64ToPtr(256), 2120 }, 2121 ECCErrorsL1CacheAttr: { 2122 Unit: ECCErrorsL1CacheUnit, 2123 Desc: ECCErrorsL1CacheDesc, 2124 IntNumeratorVal: helper.Int64ToPtr(300), 2125 }, 2126 ECCErrorsL2CacheAttr: { 2127 Unit: ECCErrorsL2CacheUnit, 2128 Desc: ECCErrorsL2CacheDesc, 2129 IntNumeratorVal: helper.Int64ToPtr(300), 2130 }, 2131 ECCErrorsDeviceAttr: { 2132 Unit: ECCErrorsDeviceUnit, 2133 Desc: ECCErrorsDeviceDesc, 2134 IntNumeratorVal: helper.Int64ToPtr(300), 2135 }, 2136 }, 2137 }, 2138 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2139 }, 2140 }, 2141 }, 2142 }, 2143 } { 2144 actualResult := statsForGroup(testCase.GroupName, testCase.GroupStats, testCase.Timestamp) 2145 require.New(t).Equal(testCase.ExpectedResult, actualResult) 2146 } 2147 } 2148 2149 func TestWriteStatsToChannel(t *testing.T) { 2150 for _, testCase := range []struct { 2151 Name string 2152 ExpectedWriteToChannel *device.StatsResponse 2153 Timestamp time.Time 2154 Device *NvidiaDevice 2155 }{ 2156 { 2157 Name: "NVML wrapper returns error", 2158 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2159 ExpectedWriteToChannel: &device.StatsResponse{ 2160 Error: errors.New(""), 2161 }, 2162 Device: &NvidiaDevice{ 2163 nvmlClient: &MockNvmlClient{ 2164 StatsError: errors.New(""), 2165 }, 2166 logger: hclog.NewNullLogger(), 2167 }, 2168 }, 2169 { 2170 Name: "Check that stats with multiple DeviceNames are assigned to different groups", 2171 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2172 Device: &NvidiaDevice{ 2173 devices: map[string]struct{}{ 2174 "UUID1": {}, 2175 "UUID2": {}, 2176 "UUID3": {}, 2177 }, 2178 nvmlClient: &MockNvmlClient{ 2179 StatsResponseReturned: []*nvml.StatsData{ 2180 { 2181 DeviceData: &nvml.DeviceData{ 2182 UUID: "UUID1", 2183 DeviceName: helper.StringToPtr("DeviceName1"), 2184 MemoryMiB: helper.Uint64ToPtr(1), 2185 PowerW: helper.UintToPtr(1), 2186 BAR1MiB: helper.Uint64ToPtr(256), 2187 }, 2188 PowerUsageW: helper.UintToPtr(1), 2189 GPUUtilization: helper.UintToPtr(1), 2190 MemoryUtilization: helper.UintToPtr(1), 2191 EncoderUtilization: helper.UintToPtr(1), 2192 DecoderUtilization: helper.UintToPtr(1), 2193 TemperatureC: helper.UintToPtr(1), 2194 UsedMemoryMiB: helper.Uint64ToPtr(1), 2195 BAR1UsedMiB: helper.Uint64ToPtr(1), 2196 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 2197 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 2198 ECCErrorsDevice: helper.Uint64ToPtr(100), 2199 }, 2200 { 2201 DeviceData: &nvml.DeviceData{ 2202 UUID: "UUID2", 2203 DeviceName: helper.StringToPtr("DeviceName2"), 2204 MemoryMiB: helper.Uint64ToPtr(2), 2205 PowerW: helper.UintToPtr(2), 2206 BAR1MiB: helper.Uint64ToPtr(256), 2207 }, 2208 PowerUsageW: helper.UintToPtr(2), 2209 GPUUtilization: helper.UintToPtr(2), 2210 MemoryUtilization: helper.UintToPtr(2), 2211 EncoderUtilization: helper.UintToPtr(2), 2212 DecoderUtilization: helper.UintToPtr(2), 2213 TemperatureC: helper.UintToPtr(2), 2214 UsedMemoryMiB: helper.Uint64ToPtr(2), 2215 BAR1UsedMiB: helper.Uint64ToPtr(2), 2216 ECCErrorsL1Cache: helper.Uint64ToPtr(200), 2217 ECCErrorsL2Cache: helper.Uint64ToPtr(200), 2218 ECCErrorsDevice: helper.Uint64ToPtr(200), 2219 }, 2220 { 2221 DeviceData: &nvml.DeviceData{ 2222 UUID: "UUID3", 2223 DeviceName: helper.StringToPtr("DeviceName3"), 2224 MemoryMiB: helper.Uint64ToPtr(3), 2225 PowerW: helper.UintToPtr(3), 2226 BAR1MiB: helper.Uint64ToPtr(256), 2227 }, 2228 PowerUsageW: helper.UintToPtr(3), 2229 GPUUtilization: helper.UintToPtr(3), 2230 MemoryUtilization: helper.UintToPtr(3), 2231 EncoderUtilization: helper.UintToPtr(3), 2232 DecoderUtilization: helper.UintToPtr(3), 2233 TemperatureC: helper.UintToPtr(3), 2234 UsedMemoryMiB: helper.Uint64ToPtr(3), 2235 BAR1UsedMiB: helper.Uint64ToPtr(3), 2236 ECCErrorsL1Cache: helper.Uint64ToPtr(300), 2237 ECCErrorsL2Cache: helper.Uint64ToPtr(300), 2238 ECCErrorsDevice: helper.Uint64ToPtr(300), 2239 }, 2240 }, 2241 }, 2242 logger: hclog.NewNullLogger(), 2243 }, 2244 ExpectedWriteToChannel: &device.StatsResponse{ 2245 Groups: []*device.DeviceGroupStats{ 2246 { 2247 Vendor: vendor, 2248 Type: deviceType, 2249 Name: "DeviceName1", 2250 InstanceStats: map[string]*device.DeviceStats{ 2251 "UUID1": { 2252 Summary: &structs.StatValue{ 2253 Unit: MemoryStateUnit, 2254 Desc: MemoryStateDesc, 2255 IntNumeratorVal: helper.Int64ToPtr(1), 2256 IntDenominatorVal: helper.Int64ToPtr(1), 2257 }, 2258 Stats: &structs.StatObject{ 2259 Attributes: map[string]*structs.StatValue{ 2260 PowerUsageAttr: { 2261 Unit: PowerUsageUnit, 2262 Desc: PowerUsageDesc, 2263 IntNumeratorVal: helper.Int64ToPtr(1), 2264 IntDenominatorVal: helper.Int64ToPtr(1), 2265 }, 2266 GPUUtilizationAttr: { 2267 Unit: GPUUtilizationUnit, 2268 Desc: GPUUtilizationDesc, 2269 IntNumeratorVal: helper.Int64ToPtr(1), 2270 }, 2271 MemoryUtilizationAttr: { 2272 Unit: MemoryUtilizationUnit, 2273 Desc: MemoryUtilizationDesc, 2274 IntNumeratorVal: helper.Int64ToPtr(1), 2275 }, 2276 EncoderUtilizationAttr: { 2277 Unit: EncoderUtilizationUnit, 2278 Desc: EncoderUtilizationDesc, 2279 IntNumeratorVal: helper.Int64ToPtr(1), 2280 }, 2281 DecoderUtilizationAttr: { 2282 Unit: DecoderUtilizationUnit, 2283 Desc: DecoderUtilizationDesc, 2284 IntNumeratorVal: helper.Int64ToPtr(1), 2285 }, 2286 TemperatureAttr: { 2287 Unit: TemperatureUnit, 2288 Desc: TemperatureDesc, 2289 IntNumeratorVal: helper.Int64ToPtr(1), 2290 }, 2291 MemoryStateAttr: { 2292 Unit: MemoryStateUnit, 2293 Desc: MemoryStateDesc, 2294 IntNumeratorVal: helper.Int64ToPtr(1), 2295 IntDenominatorVal: helper.Int64ToPtr(1), 2296 }, 2297 BAR1StateAttr: { 2298 Unit: BAR1StateUnit, 2299 Desc: BAR1StateDesc, 2300 IntNumeratorVal: helper.Int64ToPtr(1), 2301 IntDenominatorVal: helper.Int64ToPtr(256), 2302 }, 2303 ECCErrorsL1CacheAttr: { 2304 Unit: ECCErrorsL1CacheUnit, 2305 Desc: ECCErrorsL1CacheDesc, 2306 IntNumeratorVal: helper.Int64ToPtr(100), 2307 }, 2308 ECCErrorsL2CacheAttr: { 2309 Unit: ECCErrorsL2CacheUnit, 2310 Desc: ECCErrorsL2CacheDesc, 2311 IntNumeratorVal: helper.Int64ToPtr(100), 2312 }, 2313 ECCErrorsDeviceAttr: { 2314 Unit: ECCErrorsDeviceUnit, 2315 Desc: ECCErrorsDeviceDesc, 2316 IntNumeratorVal: helper.Int64ToPtr(100), 2317 }, 2318 }, 2319 }, 2320 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2321 }, 2322 }, 2323 }, 2324 { 2325 Vendor: vendor, 2326 Type: deviceType, 2327 Name: "DeviceName2", 2328 InstanceStats: map[string]*device.DeviceStats{ 2329 "UUID2": { 2330 Summary: &structs.StatValue{ 2331 Unit: MemoryStateUnit, 2332 Desc: MemoryStateDesc, 2333 IntNumeratorVal: helper.Int64ToPtr(2), 2334 IntDenominatorVal: helper.Int64ToPtr(2), 2335 }, 2336 Stats: &structs.StatObject{ 2337 Attributes: map[string]*structs.StatValue{ 2338 PowerUsageAttr: { 2339 Unit: PowerUsageUnit, 2340 Desc: PowerUsageDesc, 2341 IntNumeratorVal: helper.Int64ToPtr(2), 2342 IntDenominatorVal: helper.Int64ToPtr(2), 2343 }, 2344 GPUUtilizationAttr: { 2345 Unit: GPUUtilizationUnit, 2346 Desc: GPUUtilizationDesc, 2347 IntNumeratorVal: helper.Int64ToPtr(2), 2348 }, 2349 MemoryUtilizationAttr: { 2350 Unit: MemoryUtilizationUnit, 2351 Desc: MemoryUtilizationDesc, 2352 IntNumeratorVal: helper.Int64ToPtr(2), 2353 }, 2354 EncoderUtilizationAttr: { 2355 Unit: EncoderUtilizationUnit, 2356 Desc: EncoderUtilizationDesc, 2357 IntNumeratorVal: helper.Int64ToPtr(2), 2358 }, 2359 DecoderUtilizationAttr: { 2360 Unit: DecoderUtilizationUnit, 2361 Desc: DecoderUtilizationDesc, 2362 IntNumeratorVal: helper.Int64ToPtr(2), 2363 }, 2364 TemperatureAttr: { 2365 Unit: TemperatureUnit, 2366 Desc: TemperatureDesc, 2367 IntNumeratorVal: helper.Int64ToPtr(2), 2368 }, 2369 MemoryStateAttr: { 2370 Unit: MemoryStateUnit, 2371 Desc: MemoryStateDesc, 2372 IntNumeratorVal: helper.Int64ToPtr(2), 2373 IntDenominatorVal: helper.Int64ToPtr(2), 2374 }, 2375 BAR1StateAttr: { 2376 Unit: BAR1StateUnit, 2377 Desc: BAR1StateDesc, 2378 IntNumeratorVal: helper.Int64ToPtr(2), 2379 IntDenominatorVal: helper.Int64ToPtr(256), 2380 }, 2381 ECCErrorsL1CacheAttr: { 2382 Unit: ECCErrorsL1CacheUnit, 2383 Desc: ECCErrorsL1CacheDesc, 2384 IntNumeratorVal: helper.Int64ToPtr(200), 2385 }, 2386 ECCErrorsL2CacheAttr: { 2387 Unit: ECCErrorsL2CacheUnit, 2388 Desc: ECCErrorsL2CacheDesc, 2389 IntNumeratorVal: helper.Int64ToPtr(200), 2390 }, 2391 ECCErrorsDeviceAttr: { 2392 Unit: ECCErrorsDeviceUnit, 2393 Desc: ECCErrorsDeviceDesc, 2394 IntNumeratorVal: helper.Int64ToPtr(200), 2395 }, 2396 }, 2397 }, 2398 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2399 }, 2400 }, 2401 }, 2402 { 2403 Vendor: vendor, 2404 Type: deviceType, 2405 Name: "DeviceName3", 2406 InstanceStats: map[string]*device.DeviceStats{ 2407 "UUID3": { 2408 Summary: &structs.StatValue{ 2409 Unit: MemoryStateUnit, 2410 Desc: MemoryStateDesc, 2411 IntNumeratorVal: helper.Int64ToPtr(3), 2412 IntDenominatorVal: helper.Int64ToPtr(3), 2413 }, 2414 Stats: &structs.StatObject{ 2415 Attributes: map[string]*structs.StatValue{ 2416 PowerUsageAttr: { 2417 Unit: PowerUsageUnit, 2418 Desc: PowerUsageDesc, 2419 IntNumeratorVal: helper.Int64ToPtr(3), 2420 IntDenominatorVal: helper.Int64ToPtr(3), 2421 }, 2422 GPUUtilizationAttr: { 2423 Unit: GPUUtilizationUnit, 2424 Desc: GPUUtilizationDesc, 2425 IntNumeratorVal: helper.Int64ToPtr(3), 2426 }, 2427 MemoryUtilizationAttr: { 2428 Unit: MemoryUtilizationUnit, 2429 Desc: MemoryUtilizationDesc, 2430 IntNumeratorVal: helper.Int64ToPtr(3), 2431 }, 2432 EncoderUtilizationAttr: { 2433 Unit: EncoderUtilizationUnit, 2434 Desc: EncoderUtilizationDesc, 2435 IntNumeratorVal: helper.Int64ToPtr(3), 2436 }, 2437 DecoderUtilizationAttr: { 2438 Unit: DecoderUtilizationUnit, 2439 Desc: DecoderUtilizationDesc, 2440 IntNumeratorVal: helper.Int64ToPtr(3), 2441 }, 2442 TemperatureAttr: { 2443 Unit: TemperatureUnit, 2444 Desc: TemperatureDesc, 2445 IntNumeratorVal: helper.Int64ToPtr(3), 2446 }, 2447 MemoryStateAttr: { 2448 Unit: MemoryStateUnit, 2449 Desc: MemoryStateDesc, 2450 IntNumeratorVal: helper.Int64ToPtr(3), 2451 IntDenominatorVal: helper.Int64ToPtr(3), 2452 }, 2453 BAR1StateAttr: { 2454 Unit: BAR1StateUnit, 2455 Desc: BAR1StateDesc, 2456 IntNumeratorVal: helper.Int64ToPtr(3), 2457 IntDenominatorVal: helper.Int64ToPtr(256), 2458 }, 2459 ECCErrorsL1CacheAttr: { 2460 Unit: ECCErrorsL1CacheUnit, 2461 Desc: ECCErrorsL1CacheDesc, 2462 IntNumeratorVal: helper.Int64ToPtr(300), 2463 }, 2464 ECCErrorsL2CacheAttr: { 2465 Unit: ECCErrorsL2CacheUnit, 2466 Desc: ECCErrorsL2CacheDesc, 2467 IntNumeratorVal: helper.Int64ToPtr(300), 2468 }, 2469 ECCErrorsDeviceAttr: { 2470 Unit: ECCErrorsDeviceUnit, 2471 Desc: ECCErrorsDeviceDesc, 2472 IntNumeratorVal: helper.Int64ToPtr(300), 2473 }, 2474 }, 2475 }, 2476 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2477 }, 2478 }, 2479 }, 2480 }, 2481 }, 2482 }, 2483 { 2484 Name: "Check that stats with multiple DeviceNames are assigned to different groups 2", 2485 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2486 Device: &NvidiaDevice{ 2487 devices: map[string]struct{}{ 2488 "UUID1": {}, 2489 "UUID2": {}, 2490 "UUID3": {}, 2491 }, 2492 nvmlClient: &MockNvmlClient{ 2493 StatsResponseReturned: []*nvml.StatsData{ 2494 { 2495 DeviceData: &nvml.DeviceData{ 2496 UUID: "UUID1", 2497 DeviceName: helper.StringToPtr("DeviceName1"), 2498 MemoryMiB: helper.Uint64ToPtr(1), 2499 PowerW: helper.UintToPtr(1), 2500 BAR1MiB: helper.Uint64ToPtr(256), 2501 }, 2502 PowerUsageW: helper.UintToPtr(1), 2503 GPUUtilization: helper.UintToPtr(1), 2504 MemoryUtilization: helper.UintToPtr(1), 2505 EncoderUtilization: helper.UintToPtr(1), 2506 DecoderUtilization: helper.UintToPtr(1), 2507 TemperatureC: helper.UintToPtr(1), 2508 UsedMemoryMiB: helper.Uint64ToPtr(1), 2509 BAR1UsedMiB: helper.Uint64ToPtr(1), 2510 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 2511 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 2512 ECCErrorsDevice: helper.Uint64ToPtr(100), 2513 }, 2514 { 2515 DeviceData: &nvml.DeviceData{ 2516 UUID: "UUID2", 2517 DeviceName: helper.StringToPtr("DeviceName2"), 2518 MemoryMiB: helper.Uint64ToPtr(2), 2519 PowerW: helper.UintToPtr(2), 2520 BAR1MiB: helper.Uint64ToPtr(256), 2521 }, 2522 PowerUsageW: helper.UintToPtr(2), 2523 GPUUtilization: helper.UintToPtr(2), 2524 MemoryUtilization: helper.UintToPtr(2), 2525 EncoderUtilization: helper.UintToPtr(2), 2526 DecoderUtilization: helper.UintToPtr(2), 2527 TemperatureC: helper.UintToPtr(2), 2528 UsedMemoryMiB: helper.Uint64ToPtr(2), 2529 BAR1UsedMiB: helper.Uint64ToPtr(2), 2530 ECCErrorsL1Cache: helper.Uint64ToPtr(200), 2531 ECCErrorsL2Cache: helper.Uint64ToPtr(200), 2532 ECCErrorsDevice: helper.Uint64ToPtr(200), 2533 }, 2534 { 2535 DeviceData: &nvml.DeviceData{ 2536 UUID: "UUID3", 2537 DeviceName: helper.StringToPtr("DeviceName2"), 2538 MemoryMiB: helper.Uint64ToPtr(3), 2539 PowerW: helper.UintToPtr(3), 2540 BAR1MiB: helper.Uint64ToPtr(256), 2541 }, 2542 PowerUsageW: helper.UintToPtr(3), 2543 GPUUtilization: helper.UintToPtr(3), 2544 MemoryUtilization: helper.UintToPtr(3), 2545 EncoderUtilization: helper.UintToPtr(3), 2546 DecoderUtilization: helper.UintToPtr(3), 2547 TemperatureC: helper.UintToPtr(3), 2548 UsedMemoryMiB: helper.Uint64ToPtr(3), 2549 BAR1UsedMiB: helper.Uint64ToPtr(3), 2550 ECCErrorsL1Cache: helper.Uint64ToPtr(300), 2551 ECCErrorsL2Cache: helper.Uint64ToPtr(300), 2552 ECCErrorsDevice: helper.Uint64ToPtr(300), 2553 }, 2554 }, 2555 }, 2556 logger: hclog.NewNullLogger(), 2557 }, 2558 ExpectedWriteToChannel: &device.StatsResponse{ 2559 Groups: []*device.DeviceGroupStats{ 2560 { 2561 Vendor: vendor, 2562 Type: deviceType, 2563 Name: "DeviceName1", 2564 InstanceStats: map[string]*device.DeviceStats{ 2565 "UUID1": { 2566 Summary: &structs.StatValue{ 2567 Unit: MemoryStateUnit, 2568 Desc: MemoryStateDesc, 2569 IntNumeratorVal: helper.Int64ToPtr(1), 2570 IntDenominatorVal: helper.Int64ToPtr(1), 2571 }, 2572 Stats: &structs.StatObject{ 2573 Attributes: map[string]*structs.StatValue{ 2574 PowerUsageAttr: { 2575 Unit: PowerUsageUnit, 2576 Desc: PowerUsageDesc, 2577 IntNumeratorVal: helper.Int64ToPtr(1), 2578 IntDenominatorVal: helper.Int64ToPtr(1), 2579 }, 2580 GPUUtilizationAttr: { 2581 Unit: GPUUtilizationUnit, 2582 Desc: GPUUtilizationDesc, 2583 IntNumeratorVal: helper.Int64ToPtr(1), 2584 }, 2585 MemoryUtilizationAttr: { 2586 Unit: MemoryUtilizationUnit, 2587 Desc: MemoryUtilizationDesc, 2588 IntNumeratorVal: helper.Int64ToPtr(1), 2589 }, 2590 EncoderUtilizationAttr: { 2591 Unit: EncoderUtilizationUnit, 2592 Desc: EncoderUtilizationDesc, 2593 IntNumeratorVal: helper.Int64ToPtr(1), 2594 }, 2595 DecoderUtilizationAttr: { 2596 Unit: DecoderUtilizationUnit, 2597 Desc: DecoderUtilizationDesc, 2598 IntNumeratorVal: helper.Int64ToPtr(1), 2599 }, 2600 TemperatureAttr: { 2601 Unit: TemperatureUnit, 2602 Desc: TemperatureDesc, 2603 IntNumeratorVal: helper.Int64ToPtr(1), 2604 }, 2605 MemoryStateAttr: { 2606 Unit: MemoryStateUnit, 2607 Desc: MemoryStateDesc, 2608 IntNumeratorVal: helper.Int64ToPtr(1), 2609 IntDenominatorVal: helper.Int64ToPtr(1), 2610 }, 2611 BAR1StateAttr: { 2612 Unit: BAR1StateUnit, 2613 Desc: BAR1StateDesc, 2614 IntNumeratorVal: helper.Int64ToPtr(1), 2615 IntDenominatorVal: helper.Int64ToPtr(256), 2616 }, 2617 ECCErrorsL1CacheAttr: { 2618 Unit: ECCErrorsL1CacheUnit, 2619 Desc: ECCErrorsL1CacheDesc, 2620 IntNumeratorVal: helper.Int64ToPtr(100), 2621 }, 2622 ECCErrorsL2CacheAttr: { 2623 Unit: ECCErrorsL2CacheUnit, 2624 Desc: ECCErrorsL2CacheDesc, 2625 IntNumeratorVal: helper.Int64ToPtr(100), 2626 }, 2627 ECCErrorsDeviceAttr: { 2628 Unit: ECCErrorsDeviceUnit, 2629 Desc: ECCErrorsDeviceDesc, 2630 IntNumeratorVal: helper.Int64ToPtr(100), 2631 }, 2632 }, 2633 }, 2634 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2635 }, 2636 }, 2637 }, 2638 { 2639 Vendor: vendor, 2640 Type: deviceType, 2641 Name: "DeviceName2", 2642 InstanceStats: map[string]*device.DeviceStats{ 2643 "UUID3": { 2644 Summary: &structs.StatValue{ 2645 Unit: MemoryStateUnit, 2646 Desc: MemoryStateDesc, 2647 IntNumeratorVal: helper.Int64ToPtr(3), 2648 IntDenominatorVal: helper.Int64ToPtr(3), 2649 }, 2650 Stats: &structs.StatObject{ 2651 Attributes: map[string]*structs.StatValue{ 2652 PowerUsageAttr: { 2653 Unit: PowerUsageUnit, 2654 Desc: PowerUsageDesc, 2655 IntNumeratorVal: helper.Int64ToPtr(3), 2656 IntDenominatorVal: helper.Int64ToPtr(3), 2657 }, 2658 GPUUtilizationAttr: { 2659 Unit: GPUUtilizationUnit, 2660 Desc: GPUUtilizationDesc, 2661 IntNumeratorVal: helper.Int64ToPtr(3), 2662 }, 2663 MemoryUtilizationAttr: { 2664 Unit: MemoryUtilizationUnit, 2665 Desc: MemoryUtilizationDesc, 2666 IntNumeratorVal: helper.Int64ToPtr(3), 2667 }, 2668 EncoderUtilizationAttr: { 2669 Unit: EncoderUtilizationUnit, 2670 Desc: EncoderUtilizationDesc, 2671 IntNumeratorVal: helper.Int64ToPtr(3), 2672 }, 2673 DecoderUtilizationAttr: { 2674 Unit: DecoderUtilizationUnit, 2675 Desc: DecoderUtilizationDesc, 2676 IntNumeratorVal: helper.Int64ToPtr(3), 2677 }, 2678 TemperatureAttr: { 2679 Unit: TemperatureUnit, 2680 Desc: TemperatureDesc, 2681 IntNumeratorVal: helper.Int64ToPtr(3), 2682 }, 2683 MemoryStateAttr: { 2684 Unit: MemoryStateUnit, 2685 Desc: MemoryStateDesc, 2686 IntNumeratorVal: helper.Int64ToPtr(3), 2687 IntDenominatorVal: helper.Int64ToPtr(3), 2688 }, 2689 BAR1StateAttr: { 2690 Unit: BAR1StateUnit, 2691 Desc: BAR1StateDesc, 2692 IntNumeratorVal: helper.Int64ToPtr(3), 2693 IntDenominatorVal: helper.Int64ToPtr(256), 2694 }, 2695 ECCErrorsL1CacheAttr: { 2696 Unit: ECCErrorsL1CacheUnit, 2697 Desc: ECCErrorsL1CacheDesc, 2698 IntNumeratorVal: helper.Int64ToPtr(300), 2699 }, 2700 ECCErrorsL2CacheAttr: { 2701 Unit: ECCErrorsL2CacheUnit, 2702 Desc: ECCErrorsL2CacheDesc, 2703 IntNumeratorVal: helper.Int64ToPtr(300), 2704 }, 2705 ECCErrorsDeviceAttr: { 2706 Unit: ECCErrorsDeviceUnit, 2707 Desc: ECCErrorsDeviceDesc, 2708 IntNumeratorVal: helper.Int64ToPtr(300), 2709 }, 2710 }, 2711 }, 2712 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2713 }, 2714 "UUID2": { 2715 Summary: &structs.StatValue{ 2716 Unit: MemoryStateUnit, 2717 Desc: MemoryStateDesc, 2718 IntNumeratorVal: helper.Int64ToPtr(2), 2719 IntDenominatorVal: helper.Int64ToPtr(2), 2720 }, 2721 Stats: &structs.StatObject{ 2722 Attributes: map[string]*structs.StatValue{ 2723 PowerUsageAttr: { 2724 Unit: PowerUsageUnit, 2725 Desc: PowerUsageDesc, 2726 IntNumeratorVal: helper.Int64ToPtr(2), 2727 IntDenominatorVal: helper.Int64ToPtr(2), 2728 }, 2729 GPUUtilizationAttr: { 2730 Unit: GPUUtilizationUnit, 2731 Desc: GPUUtilizationDesc, 2732 IntNumeratorVal: helper.Int64ToPtr(2), 2733 }, 2734 MemoryUtilizationAttr: { 2735 Unit: MemoryUtilizationUnit, 2736 Desc: MemoryUtilizationDesc, 2737 IntNumeratorVal: helper.Int64ToPtr(2), 2738 }, 2739 EncoderUtilizationAttr: { 2740 Unit: EncoderUtilizationUnit, 2741 Desc: EncoderUtilizationDesc, 2742 IntNumeratorVal: helper.Int64ToPtr(2), 2743 }, 2744 DecoderUtilizationAttr: { 2745 Unit: DecoderUtilizationUnit, 2746 Desc: DecoderUtilizationDesc, 2747 IntNumeratorVal: helper.Int64ToPtr(2), 2748 }, 2749 TemperatureAttr: { 2750 Unit: TemperatureUnit, 2751 Desc: TemperatureDesc, 2752 IntNumeratorVal: helper.Int64ToPtr(2), 2753 }, 2754 MemoryStateAttr: { 2755 Unit: MemoryStateUnit, 2756 Desc: MemoryStateDesc, 2757 IntNumeratorVal: helper.Int64ToPtr(2), 2758 IntDenominatorVal: helper.Int64ToPtr(2), 2759 }, 2760 BAR1StateAttr: { 2761 Unit: BAR1StateUnit, 2762 Desc: BAR1StateDesc, 2763 IntNumeratorVal: helper.Int64ToPtr(2), 2764 IntDenominatorVal: helper.Int64ToPtr(256), 2765 }, 2766 ECCErrorsL1CacheAttr: { 2767 Unit: ECCErrorsL1CacheUnit, 2768 Desc: ECCErrorsL1CacheDesc, 2769 IntNumeratorVal: helper.Int64ToPtr(200), 2770 }, 2771 ECCErrorsL2CacheAttr: { 2772 Unit: ECCErrorsL2CacheUnit, 2773 Desc: ECCErrorsL2CacheDesc, 2774 IntNumeratorVal: helper.Int64ToPtr(200), 2775 }, 2776 ECCErrorsDeviceAttr: { 2777 Unit: ECCErrorsDeviceUnit, 2778 Desc: ECCErrorsDeviceDesc, 2779 IntNumeratorVal: helper.Int64ToPtr(200), 2780 }, 2781 }, 2782 }, 2783 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2784 }, 2785 }, 2786 }, 2787 }, 2788 }, 2789 }, 2790 { 2791 Name: "Check that only devices from NvidiaDevice.device map stats are reported", 2792 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2793 Device: &NvidiaDevice{ 2794 devices: map[string]struct{}{ 2795 "UUID1": {}, 2796 "UUID2": {}, 2797 }, 2798 nvmlClient: &MockNvmlClient{ 2799 StatsResponseReturned: []*nvml.StatsData{ 2800 { 2801 DeviceData: &nvml.DeviceData{ 2802 UUID: "UUID1", 2803 DeviceName: helper.StringToPtr("DeviceName1"), 2804 MemoryMiB: helper.Uint64ToPtr(1), 2805 PowerW: helper.UintToPtr(1), 2806 BAR1MiB: helper.Uint64ToPtr(256), 2807 }, 2808 PowerUsageW: helper.UintToPtr(1), 2809 GPUUtilization: helper.UintToPtr(1), 2810 MemoryUtilization: helper.UintToPtr(1), 2811 EncoderUtilization: helper.UintToPtr(1), 2812 DecoderUtilization: helper.UintToPtr(1), 2813 TemperatureC: helper.UintToPtr(1), 2814 UsedMemoryMiB: helper.Uint64ToPtr(1), 2815 BAR1UsedMiB: helper.Uint64ToPtr(1), 2816 ECCErrorsL1Cache: helper.Uint64ToPtr(100), 2817 ECCErrorsL2Cache: helper.Uint64ToPtr(100), 2818 ECCErrorsDevice: helper.Uint64ToPtr(100), 2819 }, 2820 { 2821 DeviceData: &nvml.DeviceData{ 2822 UUID: "UUID2", 2823 DeviceName: helper.StringToPtr("DeviceName2"), 2824 MemoryMiB: helper.Uint64ToPtr(2), 2825 PowerW: helper.UintToPtr(2), 2826 BAR1MiB: helper.Uint64ToPtr(256), 2827 }, 2828 PowerUsageW: helper.UintToPtr(2), 2829 GPUUtilization: helper.UintToPtr(2), 2830 MemoryUtilization: helper.UintToPtr(2), 2831 EncoderUtilization: helper.UintToPtr(2), 2832 DecoderUtilization: helper.UintToPtr(2), 2833 TemperatureC: helper.UintToPtr(2), 2834 UsedMemoryMiB: helper.Uint64ToPtr(2), 2835 BAR1UsedMiB: helper.Uint64ToPtr(2), 2836 ECCErrorsL1Cache: helper.Uint64ToPtr(200), 2837 ECCErrorsL2Cache: helper.Uint64ToPtr(200), 2838 ECCErrorsDevice: helper.Uint64ToPtr(200), 2839 }, 2840 { 2841 DeviceData: &nvml.DeviceData{ 2842 UUID: "UUID3", 2843 DeviceName: helper.StringToPtr("DeviceName3"), 2844 MemoryMiB: helper.Uint64ToPtr(3), 2845 PowerW: helper.UintToPtr(3), 2846 BAR1MiB: helper.Uint64ToPtr(256), 2847 }, 2848 PowerUsageW: helper.UintToPtr(3), 2849 GPUUtilization: helper.UintToPtr(3), 2850 MemoryUtilization: helper.UintToPtr(3), 2851 EncoderUtilization: helper.UintToPtr(3), 2852 DecoderUtilization: helper.UintToPtr(3), 2853 TemperatureC: helper.UintToPtr(3), 2854 UsedMemoryMiB: helper.Uint64ToPtr(3), 2855 BAR1UsedMiB: helper.Uint64ToPtr(3), 2856 ECCErrorsL1Cache: helper.Uint64ToPtr(300), 2857 ECCErrorsL2Cache: helper.Uint64ToPtr(300), 2858 ECCErrorsDevice: helper.Uint64ToPtr(300), 2859 }, 2860 }, 2861 }, 2862 logger: hclog.NewNullLogger(), 2863 }, 2864 ExpectedWriteToChannel: &device.StatsResponse{ 2865 Groups: []*device.DeviceGroupStats{ 2866 { 2867 Vendor: vendor, 2868 Type: deviceType, 2869 Name: "DeviceName1", 2870 InstanceStats: map[string]*device.DeviceStats{ 2871 "UUID1": { 2872 Summary: &structs.StatValue{ 2873 Unit: MemoryStateUnit, 2874 Desc: MemoryStateDesc, 2875 IntNumeratorVal: helper.Int64ToPtr(1), 2876 IntDenominatorVal: helper.Int64ToPtr(1), 2877 }, 2878 Stats: &structs.StatObject{ 2879 Attributes: map[string]*structs.StatValue{ 2880 PowerUsageAttr: { 2881 Unit: PowerUsageUnit, 2882 Desc: PowerUsageDesc, 2883 IntNumeratorVal: helper.Int64ToPtr(1), 2884 IntDenominatorVal: helper.Int64ToPtr(1), 2885 }, 2886 GPUUtilizationAttr: { 2887 Unit: GPUUtilizationUnit, 2888 Desc: GPUUtilizationDesc, 2889 IntNumeratorVal: helper.Int64ToPtr(1), 2890 }, 2891 MemoryUtilizationAttr: { 2892 Unit: MemoryUtilizationUnit, 2893 Desc: MemoryUtilizationDesc, 2894 IntNumeratorVal: helper.Int64ToPtr(1), 2895 }, 2896 EncoderUtilizationAttr: { 2897 Unit: EncoderUtilizationUnit, 2898 Desc: EncoderUtilizationDesc, 2899 IntNumeratorVal: helper.Int64ToPtr(1), 2900 }, 2901 DecoderUtilizationAttr: { 2902 Unit: DecoderUtilizationUnit, 2903 Desc: DecoderUtilizationDesc, 2904 IntNumeratorVal: helper.Int64ToPtr(1), 2905 }, 2906 TemperatureAttr: { 2907 Unit: TemperatureUnit, 2908 Desc: TemperatureDesc, 2909 IntNumeratorVal: helper.Int64ToPtr(1), 2910 }, 2911 MemoryStateAttr: { 2912 Unit: MemoryStateUnit, 2913 Desc: MemoryStateDesc, 2914 IntNumeratorVal: helper.Int64ToPtr(1), 2915 IntDenominatorVal: helper.Int64ToPtr(1), 2916 }, 2917 BAR1StateAttr: { 2918 Unit: BAR1StateUnit, 2919 Desc: BAR1StateDesc, 2920 IntNumeratorVal: helper.Int64ToPtr(1), 2921 IntDenominatorVal: helper.Int64ToPtr(256), 2922 }, 2923 ECCErrorsL1CacheAttr: { 2924 Unit: ECCErrorsL1CacheUnit, 2925 Desc: ECCErrorsL1CacheDesc, 2926 IntNumeratorVal: helper.Int64ToPtr(100), 2927 }, 2928 ECCErrorsL2CacheAttr: { 2929 Unit: ECCErrorsL2CacheUnit, 2930 Desc: ECCErrorsL2CacheDesc, 2931 IntNumeratorVal: helper.Int64ToPtr(100), 2932 }, 2933 ECCErrorsDeviceAttr: { 2934 Unit: ECCErrorsDeviceUnit, 2935 Desc: ECCErrorsDeviceDesc, 2936 IntNumeratorVal: helper.Int64ToPtr(100), 2937 }, 2938 }, 2939 }, 2940 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 2941 }, 2942 }, 2943 }, 2944 { 2945 Vendor: vendor, 2946 Type: deviceType, 2947 Name: "DeviceName2", 2948 InstanceStats: map[string]*device.DeviceStats{ 2949 "UUID2": { 2950 Summary: &structs.StatValue{ 2951 Unit: MemoryStateUnit, 2952 Desc: MemoryStateDesc, 2953 IntNumeratorVal: helper.Int64ToPtr(2), 2954 IntDenominatorVal: helper.Int64ToPtr(2), 2955 }, 2956 Stats: &structs.StatObject{ 2957 Attributes: map[string]*structs.StatValue{ 2958 PowerUsageAttr: { 2959 Unit: PowerUsageUnit, 2960 Desc: PowerUsageDesc, 2961 IntNumeratorVal: helper.Int64ToPtr(2), 2962 IntDenominatorVal: helper.Int64ToPtr(2), 2963 }, 2964 GPUUtilizationAttr: { 2965 Unit: GPUUtilizationUnit, 2966 Desc: GPUUtilizationDesc, 2967 IntNumeratorVal: helper.Int64ToPtr(2), 2968 }, 2969 MemoryUtilizationAttr: { 2970 Unit: MemoryUtilizationUnit, 2971 Desc: MemoryUtilizationDesc, 2972 IntNumeratorVal: helper.Int64ToPtr(2), 2973 }, 2974 EncoderUtilizationAttr: { 2975 Unit: EncoderUtilizationUnit, 2976 Desc: EncoderUtilizationDesc, 2977 IntNumeratorVal: helper.Int64ToPtr(2), 2978 }, 2979 DecoderUtilizationAttr: { 2980 Unit: DecoderUtilizationUnit, 2981 Desc: DecoderUtilizationDesc, 2982 IntNumeratorVal: helper.Int64ToPtr(2), 2983 }, 2984 TemperatureAttr: { 2985 Unit: TemperatureUnit, 2986 Desc: TemperatureDesc, 2987 IntNumeratorVal: helper.Int64ToPtr(2), 2988 }, 2989 MemoryStateAttr: { 2990 Unit: MemoryStateUnit, 2991 Desc: MemoryStateDesc, 2992 IntNumeratorVal: helper.Int64ToPtr(2), 2993 IntDenominatorVal: helper.Int64ToPtr(2), 2994 }, 2995 BAR1StateAttr: { 2996 Unit: BAR1StateUnit, 2997 Desc: BAR1StateDesc, 2998 IntNumeratorVal: helper.Int64ToPtr(2), 2999 IntDenominatorVal: helper.Int64ToPtr(256), 3000 }, 3001 ECCErrorsL1CacheAttr: { 3002 Unit: ECCErrorsL1CacheUnit, 3003 Desc: ECCErrorsL1CacheDesc, 3004 IntNumeratorVal: helper.Int64ToPtr(200), 3005 }, 3006 ECCErrorsL2CacheAttr: { 3007 Unit: ECCErrorsL2CacheUnit, 3008 Desc: ECCErrorsL2CacheDesc, 3009 IntNumeratorVal: helper.Int64ToPtr(200), 3010 }, 3011 ECCErrorsDeviceAttr: { 3012 Unit: ECCErrorsDeviceUnit, 3013 Desc: ECCErrorsDeviceDesc, 3014 IntNumeratorVal: helper.Int64ToPtr(200), 3015 }, 3016 }, 3017 }, 3018 Timestamp: time.Date(1974, time.May, 19, 1, 2, 3, 4, time.UTC), 3019 }, 3020 }, 3021 }, 3022 }, 3023 }, 3024 }, 3025 } { 3026 channel := make(chan *device.StatsResponse, 1) 3027 testCase.Device.writeStatsToChannel(channel, testCase.Timestamp) 3028 actualResult := <-channel 3029 // writeStatsToChannel iterates over map keys 3030 // and insterts results to an array, so order of elements in output array 3031 // may be different 3032 // actualResult, expectedWriteToChannel arrays has to be sorted firsted 3033 sort.Slice(actualResult.Groups, func(i, j int) bool { 3034 return actualResult.Groups[i].Name < actualResult.Groups[j].Name 3035 }) 3036 sort.Slice(testCase.ExpectedWriteToChannel.Groups, func(i, j int) bool { 3037 return testCase.ExpectedWriteToChannel.Groups[i].Name < testCase.ExpectedWriteToChannel.Groups[j].Name 3038 }) 3039 require.New(t).Equal(testCase.ExpectedWriteToChannel, actualResult) 3040 } 3041 }