Skip to content

Commit

Permalink
fiddling with nr metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
timoballard committed Feb 29, 2024
1 parent 91aeb9b commit aaab76e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
22 changes: 22 additions & 0 deletions backend/audit/decorators.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions backend/audit/validators.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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}.")
Expand Down

0 comments on commit aaab76e

Please sign in to comment.