Skip to content
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

Add Forum v2 request logging #571

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,7 @@
ANALYTICS_DASHBOARD_NAME = 'Your Platform Name Here Insights'

COMMENTS_SERVICE_URL = 'http://localhost:18080'
COMMENTS_SERVICE_V2_URL = 'http://localhost:8000'
COMMENTS_SERVICE_KEY = 'password'

EXAMS_SERVICE_URL = 'http://localhost:18740/api/v1'
Expand Down
1 change: 1 addition & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4328,6 +4328,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
CREDENTIALS_PUBLIC_SERVICE_URL = 'http://localhost:8005'

COMMENTS_SERVICE_URL = 'http://localhost:18080'
COMMENTS_SERVICE_V2_URL = 'http://localhost:8000'
COMMENTS_SERVICE_KEY = 'password'

# Reverification checkpoint name pattern
Expand Down
1 change: 1 addition & 0 deletions lms/envs/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing

############## Comments CONFIGURATION SETTINGS ###############
COMMENTS_SERVICE_URL = 'http://edx.devstack.forum:4567'
COMMENTS_SERVICE_V2_URL = 'http://localhost:8000'

############## Credentials CONFIGURATION SETTINGS ###############
CREDENTIALS_INTERNAL_SERVICE_URL = 'http://edx.devstack.credentials:18150'
Expand Down
1 change: 1 addition & 0 deletions lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def get_env_setting(setting):

COURSE_LISTINGS = ENV_TOKENS.get('COURSE_LISTINGS', {})
COMMENTS_SERVICE_URL = ENV_TOKENS.get("COMMENTS_SERVICE_URL", '')
COMMENTS_SERVICE_V2_URL = ENV_TOKENS.get("COMMENTS_SERVICE_V2_URL", '')
COMMENTS_SERVICE_KEY = ENV_TOKENS.get("COMMENTS_SERVICE_KEY", '')
CERT_QUEUE = ENV_TOKENS.get("CERT_QUEUE", 'test-pull')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@
SERVICE_HOST = 'http://localhost:4567'

PREFIX = SERVICE_HOST + '/api/v1'

# V2 url support for differential logging
if hasattr(settings, "COMMENTS_SERVICE_V2_URL"):
SERVICE_HOST_V2 = settings.COMMENTS_SERVICE_V2_URL
else:
SERVICE_HOST_V2 = 'http://localhost:8000'

PREFIX_V2 = SERVICE_HOST_V2 + '/forum/forum_proxy/api/v1'
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import requests
from django.utils.translation import get_language

from .settings import SERVICE_HOST as COMMENTS_SERVICE
from .settings import PREFIX, PREFIX_V2, SERVICE_HOST as COMMENTS_SERVICE

log = logging.getLogger(__name__)

Expand All @@ -30,6 +30,10 @@ def extract(dic, keys):
return strip_none({k: dic.get(k) for k in keys})


def _get_forum_v2_url(url):
return url.replace(PREFIX, PREFIX_V2)


def perform_request(method, url, data_or_params=None, raw=False,
metric_action=None, metric_tags=None, paged_results=False):
# To avoid dependency conflict
Expand Down Expand Up @@ -71,6 +75,24 @@ def perform_request(method, url, data_or_params=None, raw=False,
timeout=config.connection_timeout
)

if method == "get":
forum_v2_url = _get_forum_v2_url(url)
response_v2 = requests.request(
method,
forum_v2_url,
data=data,
params=params,
headers=headers,
timeout=config.connection_timeout,
)
log.info(f"requested forum v1 url: {url}")
log.info(f"requested forum v2 url: {forum_v2_url}")
if response_v2.json() != response.json():
log.error(
f"Forum v2 difference, for endpoint {url} with params={params}. \
Expected: {response.json()}. Got: {response_v2.json()}."
)

metric_tags.append(f'status_code:{response.status_code}')
status_code = int(response.status_code)
if status_code > 200:
Expand Down
Loading