mirror of https://github.com/zulip/zulip.git
urls: Move the report endpoints to be API-style routes.
This commit is contained in:
parent
9234abbd59
commit
5515a075ec
|
@ -128,7 +128,7 @@ function report_error(msg, stack, opts) {
|
||||||
// setup is done or do it ourselves and then retry.
|
// setup is done or do it ourselves and then retry.
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/json/report_error',
|
url: '/json/report/error',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: { message: msg,
|
data: { message: msg,
|
||||||
stacktrace: stack,
|
stacktrace: stack,
|
||||||
|
|
|
@ -6,7 +6,7 @@ var unnarrow_times;
|
||||||
|
|
||||||
function report_narrow_time(initial_core_time, initial_free_time, network_time) {
|
function report_narrow_time(initial_core_time, initial_free_time, network_time) {
|
||||||
channel.post({
|
channel.post({
|
||||||
url: '/json/report_narrow_time',
|
url: '/json/report/narrow_times',
|
||||||
data: {initial_core: initial_core_time.toString(),
|
data: {initial_core: initial_core_time.toString(),
|
||||||
initial_free: initial_free_time.toString(),
|
initial_free: initial_free_time.toString(),
|
||||||
network: network_time.toString()},
|
network: network_time.toString()},
|
||||||
|
@ -36,7 +36,7 @@ function report_unnarrow_time() {
|
||||||
var initial_free_time = unnarrow_times.initial_free_time - unnarrow_times.start_time;
|
var initial_free_time = unnarrow_times.initial_free_time - unnarrow_times.start_time;
|
||||||
|
|
||||||
channel.post({
|
channel.post({
|
||||||
url: '/json/report_unnarrow_time',
|
url: '/json/report/unnarrow_times',
|
||||||
data: {initial_core: initial_core_time.toString(),
|
data: {initial_core: initial_core_time.toString(),
|
||||||
initial_free: initial_free_time.toString()},
|
initial_free: initial_free_time.toString()},
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ function report_send_time(send_time, receive_time,
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.post({
|
channel.post({
|
||||||
url: '/json/report_send_time',
|
url: '/json/report/send_times',
|
||||||
data: data,
|
data: data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ def is_slow_query(time_delta, path):
|
||||||
if time_delta < 1.2:
|
if time_delta < 1.2:
|
||||||
return False
|
return False
|
||||||
is_exempt = \
|
is_exempt = \
|
||||||
path in ["/activity", "/json/report_error",
|
path in ["/activity", "/json/report/error",
|
||||||
"/api/v1/deployments/report_error"] \
|
"/api/v1/deployments/report_error"] \
|
||||||
or path.startswith("/realm_activity/") \
|
or path.startswith("/realm_activity/") \
|
||||||
or path.startswith("/user_activity/")
|
or path.startswith("/user_activity/")
|
||||||
|
|
|
@ -10,7 +10,7 @@ class SlowQueryTest(TestCase):
|
||||||
self.assertTrue(is_slow_query(2, '/some/random/url'))
|
self.assertTrue(is_slow_query(2, '/some/random/url'))
|
||||||
self.assertTrue(is_slow_query(5.1, '/activity'))
|
self.assertTrue(is_slow_query(5.1, '/activity'))
|
||||||
self.assertFalse(is_slow_query(2, '/activity'))
|
self.assertFalse(is_slow_query(2, '/activity'))
|
||||||
self.assertFalse(is_slow_query(2, '/json/report_error'))
|
self.assertFalse(is_slow_query(2, '/json/report/error'))
|
||||||
self.assertFalse(is_slow_query(2, '/api/v1/deployments/report_error'))
|
self.assertFalse(is_slow_query(2, '/api/v1/deployments/report_error'))
|
||||||
self.assertFalse(is_slow_query(2, '/realm_activity/whatever'))
|
self.assertFalse(is_slow_query(2, '/realm_activity/whatever'))
|
||||||
self.assertFalse(is_slow_query(2, '/user_activity/whatever'))
|
self.assertFalse(is_slow_query(2, '/user_activity/whatever'))
|
||||||
|
|
|
@ -50,7 +50,7 @@ class TestReport(ZulipTestCase):
|
||||||
|
|
||||||
stats_mock = StatsMock(self.settings)
|
stats_mock = StatsMock(self.settings)
|
||||||
with mock.patch('zerver.views.report.statsd', wraps=stats_mock):
|
with mock.patch('zerver.views.report.statsd', wraps=stats_mock):
|
||||||
result = self.client_post("/json/report_send_time", params)
|
result = self.client_post("/json/report/send_times", params)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
expected_calls = [
|
expected_calls = [
|
||||||
|
@ -75,7 +75,7 @@ class TestReport(ZulipTestCase):
|
||||||
|
|
||||||
stats_mock = StatsMock(self.settings)
|
stats_mock = StatsMock(self.settings)
|
||||||
with mock.patch('zerver.views.report.statsd', wraps=stats_mock):
|
with mock.patch('zerver.views.report.statsd', wraps=stats_mock):
|
||||||
result = self.client_post("/json/report_narrow_time", params)
|
result = self.client_post("/json/report/narrow_times", params)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
expected_calls = [
|
expected_calls = [
|
||||||
|
@ -97,7 +97,7 @@ class TestReport(ZulipTestCase):
|
||||||
|
|
||||||
stats_mock = StatsMock(self.settings)
|
stats_mock = StatsMock(self.settings)
|
||||||
with mock.patch('zerver.views.report.statsd', wraps=stats_mock):
|
with mock.patch('zerver.views.report.statsd', wraps=stats_mock):
|
||||||
result = self.client_post("/json/report_unnarrow_time", params)
|
result = self.client_post("/json/report/unnarrow_times", params)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
expected_calls = [
|
expected_calls = [
|
||||||
|
@ -128,7 +128,7 @@ class TestReport(ZulipTestCase):
|
||||||
side_effect=KeyError('foo')
|
side_effect=KeyError('foo')
|
||||||
)
|
)
|
||||||
with publish_mock as m, subprocess_mock:
|
with publish_mock as m, subprocess_mock:
|
||||||
result = self.client_post("/json/report_error", params)
|
result = self.client_post("/json/report/error", params)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
report = m.call_args[0][1]['report']
|
report = m.call_args[0][1]['report']
|
||||||
|
@ -141,11 +141,11 @@ class TestReport(ZulipTestCase):
|
||||||
# Teset with no more_info
|
# Teset with no more_info
|
||||||
del params['more_info']
|
del params['more_info']
|
||||||
with publish_mock as m, subprocess_mock:
|
with publish_mock as m, subprocess_mock:
|
||||||
result = self.client_post("/json/report_error", params)
|
result = self.client_post("/json/report/error", params)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
with self.settings(BROWSER_ERROR_REPORTING=False):
|
with self.settings(BROWSER_ERROR_REPORTING=False):
|
||||||
result = self.client_post("/json/report_error", params)
|
result = self.client_post("/json/report/error", params)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
# If js_source_map is present, then the stack trace should be annotated.
|
# If js_source_map is present, then the stack trace should be annotated.
|
||||||
|
@ -154,7 +154,7 @@ class TestReport(ZulipTestCase):
|
||||||
with \
|
with \
|
||||||
self.settings(DEVELOPMENT=False, TEST_SUITE=False), \
|
self.settings(DEVELOPMENT=False, TEST_SUITE=False), \
|
||||||
mock.patch('zerver.lib.unminify.SourceMap.annotate_stacktrace') as annotate:
|
mock.patch('zerver.lib.unminify.SourceMap.annotate_stacktrace') as annotate:
|
||||||
result = self.client_post("/json/report_error", params)
|
result = self.client_post("/json/report/error", params)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
# fix_params (see above) adds quotes when JSON encoding.
|
# fix_params (see above) adds quotes when JSON encoding.
|
||||||
annotate.assert_called_once_with('"trace"')
|
annotate.assert_called_once_with('"trace"')
|
||||||
|
|
|
@ -31,14 +31,13 @@ def get_js_source_map():
|
||||||
])
|
])
|
||||||
return js_source_map
|
return js_source_map
|
||||||
|
|
||||||
@authenticated_json_post_view
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def json_report_send_time(request, user_profile,
|
def report_send_times(request, user_profile,
|
||||||
time=REQ(converter=to_non_negative_int),
|
time=REQ(converter=to_non_negative_int),
|
||||||
received=REQ(converter=to_non_negative_int, default="(unknown)"),
|
received=REQ(converter=to_non_negative_int, default="(unknown)"),
|
||||||
displayed=REQ(converter=to_non_negative_int, default="(unknown)"),
|
displayed=REQ(converter=to_non_negative_int, default="(unknown)"),
|
||||||
locally_echoed=REQ(validator=check_bool, default=False),
|
locally_echoed=REQ(validator=check_bool, default=False),
|
||||||
rendered_content_disparity=REQ(validator=check_bool, default=False)):
|
rendered_content_disparity=REQ(validator=check_bool, default=False)):
|
||||||
# type: (HttpRequest, UserProfile, int, int, int, bool, bool) -> HttpResponse
|
# type: (HttpRequest, UserProfile, int, int, int, bool, bool) -> HttpResponse
|
||||||
request._log_data["extra"] = "[%sms/%sms/%sms/echo:%s/diff:%s]" \
|
request._log_data["extra"] = "[%sms/%sms/%sms/echo:%s/diff:%s]" \
|
||||||
% (time, received, displayed, locally_echoed, rendered_content_disparity)
|
% (time, received, displayed, locally_echoed, rendered_content_disparity)
|
||||||
|
@ -54,12 +53,11 @@ def json_report_send_time(request, user_profile,
|
||||||
statsd.incr('render_disparity')
|
statsd.incr('render_disparity')
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@authenticated_json_post_view
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def json_report_narrow_time(request, user_profile,
|
def report_narrow_times(request, user_profile,
|
||||||
initial_core=REQ(converter=to_non_negative_int),
|
initial_core=REQ(converter=to_non_negative_int),
|
||||||
initial_free=REQ(converter=to_non_negative_int),
|
initial_free=REQ(converter=to_non_negative_int),
|
||||||
network=REQ(converter=to_non_negative_int)):
|
network=REQ(converter=to_non_negative_int)):
|
||||||
# type: (HttpRequest, UserProfile, int, int, int) -> HttpResponse
|
# type: (HttpRequest, UserProfile, int, int, int) -> HttpResponse
|
||||||
request._log_data["extra"] = "[%sms/%sms/%sms]" % (initial_core, initial_free, network)
|
request._log_data["extra"] = "[%sms/%sms/%sms]" % (initial_core, initial_free, network)
|
||||||
base_key = statsd_key(user_profile.realm.string_id, clean_periods=True)
|
base_key = statsd_key(user_profile.realm.string_id, clean_periods=True)
|
||||||
|
@ -68,11 +66,10 @@ def json_report_narrow_time(request, user_profile,
|
||||||
statsd.timing("narrow.network.%s" % (base_key,), network)
|
statsd.timing("narrow.network.%s" % (base_key,), network)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@authenticated_json_post_view
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def json_report_unnarrow_time(request, user_profile,
|
def report_unnarrow_times(request, user_profile,
|
||||||
initial_core=REQ(converter=to_non_negative_int),
|
initial_core=REQ(converter=to_non_negative_int),
|
||||||
initial_free=REQ(converter=to_non_negative_int)):
|
initial_free=REQ(converter=to_non_negative_int)):
|
||||||
# type: (HttpRequest, UserProfile, int, int) -> HttpResponse
|
# type: (HttpRequest, UserProfile, int, int) -> HttpResponse
|
||||||
request._log_data["extra"] = "[%sms/%sms]" % (initial_core, initial_free)
|
request._log_data["extra"] = "[%sms/%sms]" % (initial_core, initial_free)
|
||||||
base_key = statsd_key(user_profile.realm.string_id, clean_periods=True)
|
base_key = statsd_key(user_profile.realm.string_id, clean_periods=True)
|
||||||
|
@ -80,12 +77,11 @@ def json_report_unnarrow_time(request, user_profile,
|
||||||
statsd.timing("unnarrow.initial_free.%s" % (base_key,), initial_free)
|
statsd.timing("unnarrow.initial_free.%s" % (base_key,), initial_free)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@authenticated_json_post_view
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def json_report_error(request, user_profile, message=REQ(), stacktrace=REQ(),
|
def report_error(request, user_profile, message=REQ(), stacktrace=REQ(),
|
||||||
ui_message=REQ(validator=check_bool), user_agent=REQ(),
|
ui_message=REQ(validator=check_bool), user_agent=REQ(),
|
||||||
href=REQ(), log=REQ(),
|
href=REQ(), log=REQ(),
|
||||||
more_info=REQ(validator=check_dict([]), default=None)):
|
more_info=REQ(validator=check_dict([]), default=None)):
|
||||||
# type: (HttpRequest, UserProfile, Text, Text, bool, Text, Text, Text, Optional[Dict[str, Any]]) -> HttpResponse
|
# type: (HttpRequest, UserProfile, Text, Text, bool, Text, Text, Text, Optional[Dict[str, Any]]) -> HttpResponse
|
||||||
"""Accepts an error report and stores in a queue for processing. The
|
"""Accepts an error report and stores in a queue for processing. The
|
||||||
actual error reports are later handled by do_report_error (below)"""
|
actual error reports are later handled by do_report_error (below)"""
|
||||||
|
|
|
@ -18,12 +18,4 @@ legacy_urls = [
|
||||||
url(r'^json/subscriptions/exists$', zerver.views.streams.json_stream_exists),
|
url(r'^json/subscriptions/exists$', zerver.views.streams.json_stream_exists),
|
||||||
|
|
||||||
url(r'^json/fetch_api_key$', zerver.views.auth.json_fetch_api_key),
|
url(r'^json/fetch_api_key$', zerver.views.auth.json_fetch_api_key),
|
||||||
|
|
||||||
# A version of these reporting views may make sense to support in
|
|
||||||
# the API for getting mobile analytics, but we may want something
|
|
||||||
# totally different.
|
|
||||||
url(r'^json/report_error$', zerver.views.report.json_report_error),
|
|
||||||
url(r'^json/report_send_time$', zerver.views.report.json_report_send_time),
|
|
||||||
url(r'^json/report_narrow_time$', zerver.views.report.json_report_narrow_time),
|
|
||||||
url(r'^json/report_unnarrow_time$', zerver.views.report.json_report_unnarrow_time),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -421,6 +421,16 @@ v1_api_and_json_patterns = [
|
||||||
url(r'^events$', rest_dispatch,
|
url(r'^events$', rest_dispatch,
|
||||||
{'GET': 'zerver.tornado.views.get_events_backend',
|
{'GET': 'zerver.tornado.views.get_events_backend',
|
||||||
'DELETE': 'zerver.tornado.views.cleanup_event_queue'}),
|
'DELETE': 'zerver.tornado.views.cleanup_event_queue'}),
|
||||||
|
|
||||||
|
# report -> zerver.views.report
|
||||||
|
url(r'^report/error$', rest_dispatch,
|
||||||
|
{'POST': 'zerver.views.report.report_error'}),
|
||||||
|
url(r'^report/send_times$', rest_dispatch,
|
||||||
|
{'POST': 'zerver.views.report.report_send_times'}),
|
||||||
|
url(r'^report/narrow_times$', rest_dispatch,
|
||||||
|
{'POST': 'zerver.views.report.report_narrow_times'}),
|
||||||
|
url(r'^report/unnarrow_times$', rest_dispatch,
|
||||||
|
{'POST': 'zerver.views.report.report_unnarrow_times'}),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Include the dual-use patterns twice
|
# Include the dual-use patterns twice
|
||||||
|
|
Loading…
Reference in New Issue