Skip to content

Commit

Permalink
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 29, 2024
1 parent e9e4a3d commit da64227
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
SERVICE_HOST = 'http://localhost:4567'

PREFIX = SERVICE_HOST + '/api/v1'

# V2 url support for differential logging
SERVICE_HOST_V2 = 'http://localhost:8000'
PREFIX_V2 = SERVICE_HOST_V2 + '/api/v2'
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,19 @@ 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 da64227

Please sign in to comment.