Improve handling of dstat load failures.

This tweaks how Dstat data is loaded to handle errors more cleanly.
Attempts to load dstat data for datasets that don't have it configured
will fail early and avoid making a request, and 404 errors are now
handled appropriately. Also, the Dstat parser now validates
headers to make sure it is actually parsing Dstat CSV data. Lastly,
the chart is now hidden until data is loaded successfully, removing
the large blank area previously shown for missing datasets.

Change-Id: I96b8d038af1cc718ae9c43a078679a04533fddc5
This commit is contained in:
Tim Buckley
2016-01-27 16:54:38 -07:00
parent 6fab4c7e3f
commit d42aed0935
4 changed files with 25 additions and 9 deletions

View File

@@ -85,7 +85,8 @@ function timelineDstat() {
var chart = d3.select(el[0])
.append('svg')
.attr('width', timelineController.width + margin.left + margin.right)
.attr('height', height);
.attr('height', height)
.style('display', 'none');
var main = chart.append('g')
.attr('transform', 'translate(' + margin.left + ',0)');
@@ -177,6 +178,8 @@ function timelineDstat() {
y.domain([0, lanes.length]).range([0, height]);
lanes.forEach(initLane);
chart.style('display', 'block');
});
scope.$on('update', function() {

View File

@@ -252,11 +252,11 @@ function timeline($log, datasetService, progressService) {
var raw = parseDstat(response.data, firstDate.getYear());
initDstat(raw);
}).catch(function(ex) {
$log.warn(ex);
}).finally(function() {
$scope.$broadcast('update');
progressService.done();
}).catch(function(ex) {
$log.error(ex);
});
});

View File

@@ -59,10 +59,17 @@ function DatasetService($q, $http) {
};
service.dstat = function(dataset) {
return $http({
cache: true,
url: "data/" + dataset.dstat,
method: 'GET'
return $q(function(resolve, reject) {
if (!dataset.dstat) {
reject({ status: -1, statusText: 'Dstat not available for dataset.' });
return;
}
resolve($http({
cache: true,
url: "data/" + dataset.dstat,
method: 'GET'
}));
});
};

View File

@@ -41,7 +41,13 @@ var parseDstat = function(data, year) {
var dateFormat = d3.time.format.utc("%d-%m %H:%M:%S");
var parsed = d3.csv.parseRows(data, function(row, i) {
if (i <= 4) { // header rows - ignore
if (i === 0) {
if (row.length !== 1 ||
!row[0].startsWith('Dstat') ||
!row[0].endsWith('CSV output')) {
throw new Error('Invalid Dstat CSV');
}
} else if (i <= 4) { // header rows - ignore
return null;
} else if (i === 5) { // primary
primaryNames = row;