diff --git a/backend/audit/decorators.py b/backend/audit/decorators.py new file mode 100644 index 0000000000..60996ef4f6 --- /dev/null +++ b/backend/audit/decorators.py @@ -0,0 +1,22 @@ +import functools +import logging +import time + +import newrelic.agent + +logger = logging.getLogger(__name__) + + +def profile(metric_name): + def profile_inner(func): + @functools.wraps(func) + def wrapper_timer(*args, **kwargs): + start_time = time.perf_counter() + value = func(*args, **kwargs) + end_time = time.perf_counter() + run_time = end_time - start_time + logger.info(f"{metric_name} executed in {run_time:.4f} secs") + newrelic.agent.record_custom_metric(f"Custom/{metric_name}", run_time) + return value + return wrapper_timer + return profile_inner \ No newline at end of file diff --git a/backend/audit/validators.py b/backend/audit/validators.py index 8bd43bd661..4524ac73e7 100644 --- a/backend/audit/validators.py +++ b/backend/audit/validators.py @@ -1,6 +1,8 @@ import os import json import logging +import time + from jsonschema import Draft7Validator, FormatChecker, validate from jsonschema.exceptions import ValidationError as JSONSchemaValidationError @@ -12,7 +14,7 @@ from openpyxl import load_workbook from pypdf import PdfReader - +from audit.decorators import profile from audit.intakelib import ( additional_ueis_named_ranges, additional_eins_named_ranges, @@ -386,12 +388,12 @@ def _scan_file(file): data={"name": file.name}, timeout=15, ) - except requests.exceptions.ConnectionError: + except requests.exceptions.ConnectionError as e: raise ValidationError( "We were unable to complete a security inspection of the file, please try again or contact support for assistance." ) - +@profile("validate_file_infection") def validate_file_infection(file): """Files must pass an AV scan""" logger.info(f"Attempting to scan file: {file}.")