Skip to content

Commit

Permalink
feat: Add Forum v2 request logging
Browse files Browse the repository at this point in the history
send request to forum v2 alongside v1
validate both responses and log info in case of diff
  • Loading branch information
Taimoor Ahmed authored and Taimoor Ahmed committed Jul 30, 2024
1 parent 8d0ada5 commit 1fff44e
Show file tree
Hide file tree
Showing 6 changed files with 31 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 @@ -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 + '/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,20 @@ 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
)
if response_v2 != response:
log.error(f"Forum v2 diff for endpoint {url} with params={params}. \
Expected: {response}. Got: {response_v2}.")

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 1fff44e

Please sign in to comment.