-
-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a distribution tab to visualize request time distributions over time #281
Open
danielbradburn
wants to merge
17
commits into
jazzband:master
Choose a base branch
from
crunchr:add-distribution-tab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1475408
add .venv* to .gitignore
moagstar 7dddd0e
Merge branch 'master' of https://github.com/jazzband/silk
moagstar 15bdb19
Merge branch 'master' of https://github.com/jazzband/silk
moagstar 8584a5f
Merge branch 'master' of https://github.com/jazzband/silk
moagstar 65de365
Merge branch 'master' of https://github.com/jazzband/silk
moagstar 2a72e12
Added a distribution tab to silk which can be used to get a visualiza…
moagstar cd8fef3
Added link on last level of distribution view to requests filtered to…
moagstar b7c903d
fixed typo in time filters where seconds were referred to, but the fi…
moagstar 3bfb00e
added feature flag to opt in to distribution tab and added info to re…
moagstar 6905851
merge upstream master
danielbradburn b2a73d8
use box plot to improve performance with lots of samples
danielbradburn 1ae7775
fix bug in clear_db where context was not passed
danielbradburn c9719ae
fix migration conflict
danielbradburn 4465479
fix filtering of requests
danielbradburn 2d9ac63
fixed filtering on requests page
danielbradburn 4fa0574
Remove FilterableRequestsView - merged that functionality back into R…
danielbradburn ee6d6cb
Merge branch 'master' into add-distribution-tab
auvipy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,3 +128,5 @@ | |
# SILKY_AUTHENTICATION = True | ||
# SILKY_AUTHORISATION = True | ||
|
||
SILKY_DISTRIBUTION_TAB = True | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.3 on 2017-12-08 12:52 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import silk.storage | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('silk', '0007_sqlquery_identifier'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='request', | ||
name='revision', | ||
field=models.TextField(blank=True, default=''), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,16 +206,21 @@ def __init__(self, value): | |
super(MethodFilter, self).__init__(value, method=value) | ||
|
||
|
||
def filters_from_request(request): | ||
class RevisionFilter(BaseFilter): | ||
def __init__(self, value): | ||
super(RevisionFilter, self).__init__(value, revision=value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need of expliclit RevisionFilter, self) in super() |
||
|
||
|
||
def filters_from_query_dict(query_dict): | ||
raw_filters = {} | ||
for key in request.POST: | ||
for key in query_dict: | ||
splt = key.split('-') | ||
if splt[0].startswith('filter'): | ||
ident = splt[1] | ||
typ = splt[2] | ||
if ident not in raw_filters: | ||
raw_filters[ident] = {} | ||
raw_filters[ident][typ] = request.POST[key] | ||
raw_filters[ident][typ] = query_dict[key] | ||
filters = {} | ||
for ident, raw_filter in raw_filters.items(): | ||
value = raw_filter.get('value', '') | ||
|
@@ -228,4 +233,29 @@ def filters_from_request(request): | |
filters[ident] = f | ||
except FilterValidationError: | ||
logger.warn('Validation error when processing filter %s(%s)' % (typ, value)) | ||
return filters | ||
|
||
|
||
def get_path_and_filters(request, session_key_request_filters): | ||
path = request.GET.get('path', None) | ||
raw_filters = request.session.get(session_key_request_filters, {}) | ||
|
||
filter_classes = set(x.__name__ for x in BaseFilter.__subclasses__()) | ||
|
||
def get_filter_class_parameter(filter_class): | ||
without_filter = filter_class.replace('Filter', '') | ||
result = without_filter[0].lower() + without_filter[1:] | ||
return result | ||
|
||
url_filters = { | ||
filter_class: dict(typ=filter_class, value=url_filter) | ||
for filter_class in filter_classes | ||
for filter_class_parameter in [get_filter_class_parameter(filter_class)] | ||
for url_filter in [request.GET.get(filter_class_parameter, None)] | ||
if url_filter is not None | ||
} | ||
|
||
def make_filters(raw_filters): | ||
return [BaseFilter.from_dict(x) for _, x in raw_filters.items()] | ||
|
||
filters = make_filters(dict(raw_filters, **url_filters)) | ||
return path, raw_filters, filters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/** | ||
* Get the view name filter param dictionary for use in generating uri query parameters. | ||
* @param viewName | ||
*/ | ||
function viewNameFilter(viewName) { | ||
return { | ||
'viewName': viewName | ||
} | ||
} | ||
|
||
/** | ||
* Get the revision filter param dictionary for use in generating uri query parameters. | ||
* @param revision The revision to filter by. | ||
*/ | ||
function revisionFilter(revision) { | ||
return { | ||
'revision': revision | ||
} | ||
} | ||
|
||
/** | ||
* Get the date filter param dictionary for use in generating uri query parameters. | ||
* @param date The date to filter by. | ||
*/ | ||
function dateFilter(date) { | ||
date = new Date(date); | ||
return { | ||
'afterDate': strftime('%Y/%m/%d 00:00', date), | ||
'beforeDate': strftime('%Y/%m/%d 23:59', date) | ||
} | ||
} | ||
|
||
/** | ||
* Get the group-by parameter dictionary for use in generating uri query parameters. | ||
* @param group The attribute which should be used for grouping distribution charts. | ||
* @returns {{group-by: *}} | ||
*/ | ||
function groupBy(group) { | ||
return {'group-by': group} | ||
} | ||
|
||
// mapping of filter by parameters to function for generating filter query parameters | ||
var filterFunctions = { | ||
'view_name': viewNameFilter, | ||
'date': dateFilter, | ||
'revision': revisionFilter | ||
}; | ||
|
||
/** | ||
* Make URI parameters from a dictionary. | ||
* @param obj dictionary to convert to parameters. | ||
* @returns {string} | ||
*/ | ||
function makeURIParameters(obj) { | ||
var str = []; | ||
for (var p in obj) { | ||
if (obj.hasOwnProperty(p)) { | ||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); | ||
} | ||
} | ||
return str.join("&"); | ||
} | ||
|
||
/** | ||
* Initialise the distribution chart. | ||
* @param distributionUrl | ||
*/ | ||
function initChart(distributionUrl) { | ||
|
||
var inputURIParams = $.url('?'); | ||
var groupByParam = inputURIParams === undefined ? 'date' : inputURIParams.group_by || 'date'; | ||
var level = inputURIParams === undefined ? 0 : parseInt(inputURIParams.level) || 0; | ||
var locationWithoutQuery = location.href.split("?")[0]; | ||
var filterParams = {}; | ||
var filterName = ''; | ||
var filterParamValue = ''; | ||
|
||
// parse the input uri parameters to get the filter to apply | ||
for (var paramName in inputURIParams) { | ||
if (paramName in filterFunctions) { | ||
filterName = paramName; | ||
var filter = filterFunctions[paramName]; | ||
filterParamValue = inputURIParams[paramName]; | ||
filterValue = filter(filterParamValue); | ||
filterParams = Object.assign(filterParams, filterValue); | ||
} | ||
} | ||
|
||
// generate the chart title | ||
var viewTitleValue = 'all'; | ||
var groupTitleValue = 'all'; | ||
var groupTitle = groupByParam; | ||
if (level === 1) { | ||
groupTitle = filterName; | ||
groupTitleValue = filterParamValue; | ||
} else if (level === 2) { | ||
viewTitleValue = filterParamValue; | ||
} | ||
var title = 'view: <i>' + viewTitleValue + '</i> | ' + | ||
groupTitle + ': <i>' + groupTitleValue + '</i>' | ||
; | ||
$('#title').html(title); | ||
|
||
var groupParams = groupBy(groupByParam); | ||
var outputURIParams = makeURIParameters(Object.assign(filterParams, groupParams)); | ||
var url = [distributionUrl, outputURIParams].join("?"); | ||
|
||
d3.csv(url, function (error, data) { | ||
|
||
var maxValue = 0; | ||
|
||
data.forEach(function (d) { | ||
d.value = +d.value; | ||
if (d.value > maxValue) { | ||
maxValue = d.value; | ||
} | ||
}); | ||
|
||
var chart = makeDistroChart({ | ||
data: data, | ||
xName: 'group', | ||
yName: 'value', | ||
axisLabels: {xAxis: null, yAxis: 'Time Taken (ms)'}, | ||
selector: "#chart-distro1", | ||
chartSize: {height: window.innerHeight - 110, width: window.innerWidth}, | ||
constrainExtremes: false, | ||
margin: {top: 20, right: 20, bottom: 80, left: 60} | ||
|
||
}); | ||
|
||
for (const groupName in chart.groupObjs) { | ||
const groupObj = chart.groupObjs[groupName]; | ||
groupObj.g | ||
.on('mouseover.opacity', function () { | ||
groupObj.g.transition().duration(300).attr('opacity', 0.5).style('cursor', 'pointer'); | ||
}) | ||
.on('mouseout.opacity', function () { | ||
groupObj.g.transition().duration(300).attr('opacity', 1).style('cursor', 'default'); | ||
return false; | ||
}) | ||
.on('click.opacity', function () { | ||
var outputLinkParams = Object.assign({}, inputURIParams); | ||
outputLinkParams[groupByParam] = groupName; | ||
if (level === 0) { | ||
outputLinkParams['group_by'] = 'view_name'; | ||
outputLinkParams['level'] = 1; | ||
window.location = [locationWithoutQuery, makeURIParameters(outputLinkParams)].join('?'); | ||
} | ||
else if (level === 1) { | ||
outputLinkParams['group_by'] = filterName; | ||
outputLinkParams['level'] = 2; | ||
delete outputLinkParams[filterName]; | ||
window.location = [locationWithoutQuery, makeURIParameters(outputLinkParams)].join('?'); | ||
} | ||
else { | ||
// go to normal silk view | ||
outputLinkParams = { | ||
viewName: filterParamValue | ||
}; | ||
if (groupParams['group-by'] === 'date') { | ||
outputLinkParams['afterDate'] = strftime('%Y/%m/%d 00:00', new Date(groupName)); | ||
outputLinkParams['beforeDate'] = strftime('%Y/%m/%d 23:59', new Date(groupName)); | ||
} | ||
else if (groupParams['group-by'] === 'revision') { | ||
outputLinkParams['revision'] = groupName; | ||
} | ||
window.location = ['/silk/requests', makeURIParameters(outputLinkParams)].join('?'); | ||
} | ||
}) | ||
; | ||
} | ||
|
||
chart.renderBoxPlot(); | ||
|
||
// TODO: Maybe a linear regression to show a simple trend line? | ||
}); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this migrations and regen again with django 2.2+ only.