Skip to content

Commit

Permalink
Merge pull request #3467 from GSA-TTS/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jadudm authored Mar 1, 2024
2 parents 390488f + b14e6e5 commit aa2d63c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion backend/audit/validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import json
import logging

from jsonschema import Draft7Validator, FormatChecker, validate
from jsonschema.exceptions import ValidationError as JSONSchemaValidationError

Expand All @@ -12,7 +13,6 @@
from openpyxl import load_workbook
from pypdf import PdfReader


from audit.intakelib import (
additional_ueis_named_ranges,
additional_eins_named_ranges,
Expand All @@ -33,6 +33,7 @@
SECONDARY_AUDITORS_TEMPLATE_DEFINITION,
NOTES_TO_SEFA_TEMPLATE_DEFINITION,
)
from support.decorators import newrelic_timing_metric


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -392,6 +393,7 @@ def _scan_file(file):
)


@newrelic_timing_metric("validate_file_infection")
def validate_file_infection(file):
"""Files must pass an AV scan"""
logger.info(f"Attempting to scan file: {file}.")
Expand Down
2 changes: 2 additions & 0 deletions backend/dissemination/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
OneTimeAccess,
)
from dissemination.summary_reports import generate_summary_report
from support.decorators import newrelic_timing_metric

from users.permissions import can_read_tribal

Expand Down Expand Up @@ -128,6 +129,7 @@ def get(self, request, *args, **kwargs):
},
)

@newrelic_timing_metric("search")
def post(self, request, *args, **kwargs):
"""
When accessing the search page through post, run a search and display the results.
Expand Down
24 changes: 24 additions & 0 deletions backend/support/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import functools
import logging
import time

import newrelic.agent

logger = logging.getLogger(__name__)


def newrelic_timing_metric(metric_name):
def 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 inner

0 comments on commit aa2d63c

Please sign in to comment.