Commit 1fc9c837 by Corey Goldberg Committed by alawibaba

Added listener and beacon for video cdn eval.

parent 3604e2dd
...@@ -16,6 +16,7 @@ Examples of html5 videos for manual testing: ...@@ -16,6 +16,7 @@ Examples of html5 videos for manual testing:
import copy import copy
import json import json
import logging import logging
import random
from collections import OrderedDict from collections import OrderedDict
from operator import itemgetter from operator import itemgetter
...@@ -232,10 +233,26 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers, ...@@ -232,10 +233,26 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers,
track_url, transcript_language, sorted_languages = self.get_transcripts_for_student() track_url, transcript_language, sorted_languages = self.get_transcripts_for_student()
# CDN_VIDEO_URLS is only to be used here and will be deleted
# TODO(ali@edx.org): Delete this after the CDN experiment has completed.
if getattr(settings, 'PERFORMANCE_GRAPHITE_URL', '') != '' and \
self.system.user_location == 'CN' and \
getattr(settings, 'ENABLE_VIDEO_BEACON', False) and \
self.edx_video_id in getattr(settings, 'CDN_VIDEO_URLS', {}).keys():
cdn_urls = getattr(settings, 'CDN_VIDEO_URLS', {})[self.edx_video_id]
cdn_exp_group, sources[0] = random.choice(zip(range(len(cdn_urls)), cdn_urls))
cdn_eval = True
else:
cdn_eval = False
cdn_exp_group = None
return self.system.render_template('video.html', { return self.system.render_template('video.html', {
'ajax_url': self.system.ajax_url + '/save_user_state', 'ajax_url': self.system.ajax_url + '/save_user_state',
'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False), 'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False),
'branding_info': branding_info, 'branding_info': branding_info,
'cdn_eval': cdn_eval,
'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''),
'cdn_exp_group': cdn_exp_group,
# This won't work when we move to data that # This won't work when we move to data that
# isn't on the filesystem # isn't on the filesystem
'data_dir': getattr(self, 'data_dir', None), 'data_dir': getattr(self, 'data_dir', None),
......
...@@ -29,6 +29,9 @@ class TestVideoYouTube(TestVideo): ...@@ -29,6 +29,9 @@ class TestVideoYouTube(TestVideo):
'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state', 'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state',
'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False), 'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False),
'branding_info': None, 'branding_info': None,
'cdn_eval': False,
'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''),
'cdn_exp_group': None,
'data_dir': getattr(self, 'data_dir', None), 'data_dir': getattr(self, 'data_dir', None),
'display_name': u'A Name', 'display_name': u'A Name',
'end': 3610.0, 'end': 3610.0,
...@@ -93,6 +96,9 @@ class TestVideoNonYouTube(TestVideo): ...@@ -93,6 +96,9 @@ class TestVideoNonYouTube(TestVideo):
expected_context = { expected_context = {
'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state', 'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state',
'branding_info': None, 'branding_info': None,
'cdn_eval': False,
'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''),
'cdn_exp_group': None,
'data_dir': getattr(self, 'data_dir', None), 'data_dir': getattr(self, 'data_dir', None),
'show_captions': 'true', 'show_captions': 'true',
'handout': None, 'handout': None,
...@@ -197,6 +203,9 @@ class TestGetHtmlMethod(BaseTestXmodule): ...@@ -197,6 +203,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
expected_context = { expected_context = {
'branding_info': None, 'branding_info': None,
'cdn_eval': False,
'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''),
'cdn_exp_group': None,
'data_dir': getattr(self, 'data_dir', None), 'data_dir': getattr(self, 'data_dir', None),
'show_captions': 'true', 'show_captions': 'true',
'handout': None, 'handout': None,
...@@ -314,6 +323,9 @@ class TestGetHtmlMethod(BaseTestXmodule): ...@@ -314,6 +323,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
initial_context = { initial_context = {
'branding_info': None, 'branding_info': None,
'cdn_eval': False,
'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''),
'cdn_exp_group': None,
'data_dir': getattr(self, 'data_dir', None), 'data_dir': getattr(self, 'data_dir', None),
'show_captions': 'true', 'show_captions': 'true',
'handout': None, 'handout': None,
...@@ -454,6 +466,9 @@ class TestGetHtmlMethod(BaseTestXmodule): ...@@ -454,6 +466,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
# Video found for edx_video_id # Video found for edx_video_id
initial_context = { initial_context = {
'branding_info': None, 'branding_info': None,
'cdn_eval': False,
'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''),
'cdn_exp_group': None,
'data_dir': getattr(self, 'data_dir', None), 'data_dir': getattr(self, 'data_dir', None),
'show_captions': 'true', 'show_captions': 'true',
'handout': None, 'handout': None,
...@@ -572,6 +587,9 @@ class TestGetHtmlMethod(BaseTestXmodule): ...@@ -572,6 +587,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
# Video found for edx_video_id # Video found for edx_video_id
initial_context = { initial_context = {
'branding_info': None, 'branding_info': None,
'cdn_eval': False,
'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''),
'cdn_exp_group': None,
'data_dir': getattr(self, 'data_dir', None), 'data_dir': getattr(self, 'data_dir', None),
'show_captions': 'true', 'show_captions': 'true',
'handout': None, 'handout': None,
...@@ -691,6 +709,9 @@ class TestGetHtmlMethod(BaseTestXmodule): ...@@ -691,6 +709,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
'logo_tag': 'Video hosted by XuetangX.com', 'logo_tag': 'Video hosted by XuetangX.com',
'url': 'http://www.xuetangx.com' 'url': 'http://www.xuetangx.com'
}, },
'cdn_eval': False,
'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''),
'cdn_exp_group': None,
'data_dir': getattr(self, 'data_dir', None), 'data_dir': getattr(self, 'data_dir', None),
'show_captions': 'true', 'show_captions': 'true',
'handout': None, 'handout': None,
......
...@@ -150,3 +150,28 @@ ...@@ -150,3 +150,28 @@
% endif % endif
</ul> </ul>
</div> </div>
% if cdn_eval:
<script>
function sendMetricToGraphite(metricName, value) {
var url = "${cdn_eval_endpoint}";
var request = new XMLHttpRequest();
request.open("POST", url, true); // send asynchronously
request.send(metricName + " " + value);
};
var cdnStartTime, beaconSent = false;
function initializeCDNExperiment() {
cdnStartTime = Date.now();
$("#video_${id}").bind("html5:canplaythrough", null, function() {
if (!beaconSent) {
timeElapsed = Date.now() - cdnStartTime;
sendMetricToGraphite("loadtime_${cdn_exp_group}", timeElapsed);
}
beaconSent = true;
});
}
$("#video_${id}").bind("initialize", null, initializeCDNExperiment);
if ($("#video_${id}").hasClass("is-initialized")) {
initializeCDNExperiment();
}
</script>
% endif;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment