Fix allocation count in CSI volumes table (#9515)

This closes #9495. As detailed in there, the collection query GET
/v1/volumes?type=csi doesn’t return ReadAllocs and WriteAllocs, so the #
Allocs cell was always showing 0 upon first load because it was derived
from the lengths of those arrays. This uses the heretofore-ignored
CurrentReaders and CurrentWriters values to calculate the total instead.

The single-resource query GET /v1/volume/csi%2F:id doesn’t return
CurrentReaders and CurrentWriters that absence doesn’t override the
stored values when visiting an individual item.

Thanks to @apollo13 for reporting this and to @tgross for the API logs
and suggestion.
This commit is contained in:
Buck Doyle 2020-12-07 08:51:41 -06:00 committed by GitHub
parent 2d344179d3
commit 543fb24764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -18,6 +18,14 @@ export default class Volume extends Model {
return [...this.writeAllocations.toArray(), ...this.readAllocations.toArray()];
}
@attr('number') currentWriters;
@attr('number') currentReaders;
@computed('currentWriters', 'currentReaders')
get allocationCount() {
return this.currentWriters + this.currentReaders;
}
@attr('string') externalId;
@attr() topologies;
@attr('string') accessMode;

View File

@ -62,7 +62,7 @@
({{row.model.nodesHealthy}}/{{row.model.nodesExpected}})
</td>
<td data-test-volume-provider>{{row.model.provider}}</td>
<td data-test-volume-allocations>{{row.model.allocations.length}}</td>
<td data-test-volume-allocations>{{row.model.allocationCount}}</td>
</tr>
</t.body>
</ListTable>

View File

@ -14,7 +14,7 @@ export default ApplicationSerializer.extend({
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
if (json instanceof Array) {
json.forEach(serializeVolume);
json.forEach(serializeVolumeFromArray);
} else {
serializeVolume(json);
}
@ -22,6 +22,14 @@ export default ApplicationSerializer.extend({
},
});
function serializeVolumeFromArray(volume) {
volume.CurrentWriters = volume.WriteAllocs.length;
delete volume.WriteAllocs;
volume.CurrentReaders = volume.ReadAllocs.length;
delete volume.ReadAllocs;
}
function serializeVolume(volume) {
volume.WriteAllocs = groupBy(volume.WriteAllocs, 'ID');
volume.ReadAllocs = groupBy(volume.ReadAllocs, 'ID');