Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
Bug 936164 fix for platform failure rate calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sashakruglov authored and dminor committed Nov 8, 2013
1 parent fe7660c commit 1e1c277
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 25 deletions.
35 changes: 29 additions & 6 deletions src/server.py
Expand Up @@ -171,13 +171,21 @@ def run_resultstimeseries_query(query_dict):
def run_slaves_query(query_dict):
start_date, end_date = clean_date_params(query_dict)

days_to_show = (end_date - start_date).days
if days_to_show <= 8:
jobs = 5
else:
jobs = int(round(days_to_show * 0.4))

info = '''Only slaves with more than %d jobs are displayed.''' % jobs

db = create_db_connnection()
cursor = db.cursor()
cursor.execute("""select slave, result, date from testjobs
where result in
("retry", "testfailed", "success", "busted", "exception")
and date between "%s" and "%s"
order by slave;""" % (start_date, end_date))
and date between "{0}" and "{1}"
order by slave;""".format(start_date, end_date))

query_results = cursor.fetchall()
cursor.close()
Expand Down Expand Up @@ -205,8 +213,12 @@ def run_slaves_query(query_dict):
data[name]['total'] += 1
dates.append(date)

# calculate failure rate for slaves
for slave, results in data.iteritems():
# filter slaves
slave_list = [slave for slave in data if data[slave]['total'] > jobs]

# calculate failure rate only for slaves that we're going to display
for slave in slave_list:
results = data[slave]
fail_rates = calculate_fail_rate(results['success'],
results['retry'],
results['total'])
Expand All @@ -217,9 +229,14 @@ def run_slaves_query(query_dict):
# group slaves by platform and calculate platform failure rate
slaves = sorted(data.keys())
for platform, slave_group in groupby(slaves, lambda x: x.rsplit('-', 1)[0]):
slaves = list(slave_group)

# don't calculate failure rate for platform we're not going to show
if not any(slave in slaves for slave in slave_list):
continue

platforms[platform] = {}
results = {}
slaves = list(slave_group)

for label in ['success', 'retry', 'total']:
r = reduce(lambda x, y: x + y,
Expand All @@ -231,9 +248,15 @@ def run_slaves_query(query_dict):
results['total'])
platforms[platform].update(fail_rates)

# remove data that we don't need
for slave in data.keys():
if slave not in slave_list:
del data[slave]

return {'slaves': data,
'platforms': platforms,
'dates': get_date_range(dates)}
'dates': get_date_range(dates),
'disclaimer': info}


@json_response
Expand Down
47 changes: 28 additions & 19 deletions static/js/slaves.js
Expand Up @@ -32,7 +32,7 @@ $(function() {
function showHidden() {
$('.hidden').toggle(
$('#showHidden').is(':checked'));
};
}


function fetchData(queryString) {
Expand All @@ -44,39 +44,48 @@ function fetchData(queryString) {
var errMsg = 'Ajax request failed';
handleError(errMsg);
});
};
}


function handleError(errMsg) {
$('.reportDates').hide();
clearResultsTable();
$('#error').text(errMsg).show();
};
}


function clearResultsTable() {
var rows = $('#results tr').slice(1);
if (rows.length > 1) {
if (rows.length > 0) {
rows.remove();
};
};
}
}


function insertDates(dates) {
$('.reportDates').show();
$('#startDate').text(dates.startDate);
$('#endDate').text(dates.endDate);
}


function insertData(json) {
// handling errors in response
if (json.error) {
handleError(json.error);
return;
};
}

var slaves_data = json.slaves;
var platform_data = json.platforms;
var dates = json.dates;
var slaves_data = json.slaves,
platform_data = json.platforms,
dates = json.dates,
info = json.disclaimer;

// insert dates
$('.reportDates').show();
$('#startDate').text(dates.startDate);
$('#endDate').text(dates.endDate);
insertDates(dates);

// insert disclaimer
$('#info').text(info);

// globally used variables
var tbl = $('#results');
Expand All @@ -100,9 +109,9 @@ function insertData(json) {
// get platform failure rate
$.each(platform_data, function(index, value) {
var re = RegExp("^" + index + "-.*");
if (results['slave'].match(re) != null) {
if (results['slave'].match(re) !== null) {
results['pfr'] = value;
};
}
});

// insert rows
Expand Down Expand Up @@ -136,12 +145,12 @@ function insertData(json) {
// make table sortable
sorttable.makeSortable(tbl[0]);

};
}


function switchFailRates() {
var isChecked = $('#includeRetries').is(':checked');
var attrToUse = isChecked == true ? 'withRetries' : 'noRetries';
var attrToUse = isChecked === true ? 'withRetries' : 'noRetries';

var tblRows = $('#results').find('tr').slice(1);
var labels = getTableColumns();
Expand All @@ -163,7 +172,7 @@ function switchFailRates() {
sfrCell.removeClass('alert');
}
});
};
}


function getTableColumns() {
Expand All @@ -172,4 +181,4 @@ function getTableColumns() {
labels.push(this.dataset['type']);
});
return labels;
};
}
1 change: 1 addition & 0 deletions static/slave_failures.html
Expand Up @@ -26,6 +26,7 @@ <h1>Slave failures</h1>
<input type="text" id="to" size="10" name="endDate"/>
<input type="submit" value="Get data"/>
</form>
<p id="info"></p>
<p>
By default slaves that have no failures or retries are not shown</br>
Toggle checkbox to see results for all slaves
Expand Down

0 comments on commit 1e1c277

Please sign in to comment.