Skip to content

Commit

Permalink
Stop logging proxied 5XX Graphite errors
Browse files Browse the repository at this point in the history
This adds what amounts to a dirty hack to the graphite-web proxy
view (i.e. it reaches into Django internals) to prevent Django from
doing a full error response log when proxying 5xx class errors from
graphite-web.  It does so by tricking `django.utils.log.log_response()`
into thinking that the response has already been logged (since our
view function has no other control over how its return values are
logged by Django).

The reason for the 5xx response codes are not bugs in our view code,
and does not need to trigger site admin e-mails.
  • Loading branch information
lunkwill42 committed Dec 20, 2024
1 parent 35b0f71 commit f847310
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/nav/web/graphite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def index(request, uri):
else:
response = HttpResponse(output, content_type=content_type, status=status)

# Dirty hack to prevent logging of 5XX errors. More specifically, this prevents
# a full Django error mail from being sent when Graphite is down or otherwise
# failing. (I.e. we're just proxying the status code, there is no error in our
# application that needs to be mailed to anyone).
if status >= 500:
# Tricks Django into thinking this response has already been logged:
response._has_been_logged = True

response['X-Where-Am-I'] = request.get_full_path()
return response

Expand Down

0 comments on commit f847310

Please sign in to comment.