Merge pull request #7261 from edx/cgoldberg/video-cdn-experiment
Added listener and beacon for video cdn eval.
This commit is contained in:
@@ -16,6 +16,7 @@ Examples of html5 videos for manual testing:
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
import random
|
||||
from collections import OrderedDict
|
||||
from operator import itemgetter
|
||||
|
||||
@@ -232,10 +233,26 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers,
|
||||
|
||||
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', {
|
||||
'ajax_url': self.system.ajax_url + '/save_user_state',
|
||||
'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False),
|
||||
'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
|
||||
# isn't on the filesystem
|
||||
'data_dir': getattr(self, 'data_dir', None),
|
||||
|
||||
@@ -29,6 +29,9 @@ class TestVideoYouTube(TestVideo):
|
||||
'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state',
|
||||
'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False),
|
||||
'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),
|
||||
'display_name': u'A Name',
|
||||
'end': 3610.0,
|
||||
@@ -93,6 +96,9 @@ class TestVideoNonYouTube(TestVideo):
|
||||
expected_context = {
|
||||
'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state',
|
||||
'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),
|
||||
'show_captions': 'true',
|
||||
'handout': None,
|
||||
@@ -197,6 +203,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
|
||||
|
||||
expected_context = {
|
||||
'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),
|
||||
'show_captions': 'true',
|
||||
'handout': None,
|
||||
@@ -314,6 +323,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
|
||||
|
||||
initial_context = {
|
||||
'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),
|
||||
'show_captions': 'true',
|
||||
'handout': None,
|
||||
@@ -454,6 +466,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
|
||||
# Video found for edx_video_id
|
||||
initial_context = {
|
||||
'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),
|
||||
'show_captions': 'true',
|
||||
'handout': None,
|
||||
@@ -572,6 +587,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
|
||||
# Video found for edx_video_id
|
||||
initial_context = {
|
||||
'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),
|
||||
'show_captions': 'true',
|
||||
'handout': None,
|
||||
@@ -691,6 +709,9 @@ class TestGetHtmlMethod(BaseTestXmodule):
|
||||
'logo_tag': 'Video hosted by 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),
|
||||
'show_captions': 'true',
|
||||
'handout': None,
|
||||
|
||||
@@ -150,3 +150,28 @@
|
||||
% endif
|
||||
</ul>
|
||||
</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;
|
||||
|
||||
Reference in New Issue
Block a user