Skip to content

Commit

Permalink
Add Forum v2 request logging (#571)
Browse files Browse the repository at this point in the history
* feat: Add Forum v2 request logging
send request to forum v2 alongside v1
validate both responses and log info in case of diff

* feat: modify comparison and formatting
- compare json objects instead of response objects
- format the added lines of code

---------

Co-authored-by: Taimoor  Ahmed <[email protected]>
Co-authored-by: Muhammad Faraz  Maqsood <[email protected]>
  • Loading branch information
3 people authored and Muhammad Faraz Maqsood committed Sep 16, 2024
1 parent 6a63cfc commit 9f80113
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,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 @@ -4339,6 +4339,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

0 comments on commit 9f80113

Please sign in to comment.