Commit 5f159591 by David Ormsbee Committed by GitHub

Merge pull request #12784 from edx/release

Release to Master (2016-06-16 hotfix)
parents fdc6d915 53712a60
"""
Admin for managing the connection to the Forums backend service.
"""
from django.contrib import admin
from .models import ForumsConfig
admin.site.register(ForumsConfig)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('django_comment_common', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='ForumsConfig',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')),
('enabled', models.BooleanField(default=False, verbose_name='Enabled')),
('connection_timeout', models.FloatField(default=5.0)),
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')),
],
options={
'ordering': ('-change_date',),
'abstract': False,
},
),
]
...@@ -7,6 +7,7 @@ from django.dispatch import receiver ...@@ -7,6 +7,7 @@ from django.dispatch import receiver
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.utils.translation import ugettext_noop from django.utils.translation import ugettext_noop
from config_models.models import ConfigurationModel
from student.models import CourseEnrollment from student.models import CourseEnrollment
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
...@@ -137,3 +138,14 @@ def all_permissions_for_user_in_course(user, course_id): # pylint: disable=inva ...@@ -137,3 +138,14 @@ def all_permissions_for_user_in_course(user, course_id): # pylint: disable=inva
if not permission_blacked_out(course, all_roles, permission.name) if not permission_blacked_out(course, all_roles, permission.name)
} }
return permissions return permissions
class ForumsConfig(ConfigurationModel):
"""Config for the connection to the cs_comments_service forums backend."""
# For now, just tweak the connection timeout settings. We can add more later.
connection_timeout = models.FloatField(default=5.0)
def __unicode__(self):
"""Simple representation so the admin screen looks less ugly."""
return u"ForumsConfig: timeout={}".format(self.connection_timeout)
...@@ -372,8 +372,8 @@ class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSet ...@@ -372,8 +372,8 @@ class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSet
return inner return inner
@ddt.data( @ddt.data(
(ModuleStoreEnum.Type.mongo, 3, 4, 29), (ModuleStoreEnum.Type.mongo, 3, 4, 30),
(ModuleStoreEnum.Type.split, 3, 13, 29), (ModuleStoreEnum.Type.split, 3, 13, 30),
) )
@ddt.unpack @ddt.unpack
@count_queries @count_queries
...@@ -381,8 +381,8 @@ class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSet ...@@ -381,8 +381,8 @@ class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSet
self.create_thread_helper(mock_request) self.create_thread_helper(mock_request)
@ddt.data( @ddt.data(
(ModuleStoreEnum.Type.mongo, 3, 3, 23), (ModuleStoreEnum.Type.mongo, 3, 3, 24),
(ModuleStoreEnum.Type.split, 3, 10, 23), (ModuleStoreEnum.Type.split, 3, 10, 24),
) )
@ddt.unpack @ddt.unpack
@count_queries @count_queries
......
...@@ -342,11 +342,11 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase): ...@@ -342,11 +342,11 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase):
@ddt.data( @ddt.data(
# old mongo with cache # old mongo with cache
(ModuleStoreEnum.Type.mongo, 1, 6, 4, 16, 8), (ModuleStoreEnum.Type.mongo, 1, 6, 4, 18, 10),
(ModuleStoreEnum.Type.mongo, 50, 6, 4, 16, 8), (ModuleStoreEnum.Type.mongo, 50, 6, 4, 18, 10),
# split mongo: 3 queries, regardless of thread response size. # split mongo: 3 queries, regardless of thread response size.
(ModuleStoreEnum.Type.split, 1, 3, 3, 16, 8), (ModuleStoreEnum.Type.split, 1, 3, 3, 18, 10),
(ModuleStoreEnum.Type.split, 50, 3, 3, 16, 8), (ModuleStoreEnum.Type.split, 50, 3, 3, 18, 10),
) )
@ddt.unpack @ddt.unpack
def test_number_of_mongo_queries( def test_number_of_mongo_queries(
......
...@@ -53,6 +53,8 @@ def request_timer(request_id, method, url, tags=None): ...@@ -53,6 +53,8 @@ def request_timer(request_id, method, url, tags=None):
def perform_request(method, url, data_or_params=None, raw=False, def perform_request(method, url, data_or_params=None, raw=False,
metric_action=None, metric_tags=None, paged_results=False): metric_action=None, metric_tags=None, paged_results=False):
# To avoid dependency conflict
from django_comment_common.models import ForumsConfig
if metric_tags is None: if metric_tags is None:
metric_tags = [] metric_tags = []
...@@ -77,13 +79,14 @@ def perform_request(method, url, data_or_params=None, raw=False, ...@@ -77,13 +79,14 @@ def perform_request(method, url, data_or_params=None, raw=False,
data = None data = None
params = merge_dict(data_or_params, request_id_dict) params = merge_dict(data_or_params, request_id_dict)
with request_timer(request_id, method, url, metric_tags): with request_timer(request_id, method, url, metric_tags):
config = ForumsConfig.current()
response = requests.request( response = requests.request(
method, method,
url, url,
data=data, data=data,
params=params, params=params,
headers=headers, headers=headers,
timeout=5 timeout=config.connection_timeout
) )
metric_tags.append(u'status_code:{}'.format(response.status_code)) metric_tags.append(u'status_code:{}'.format(response.status_code))
......
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