Skip to content

Commit

Permalink
Add statsd metric collection in hc.lib.s3.get_object()
Browse files Browse the repository at this point in the history
  • Loading branch information
cuu508 committed Apr 14, 2023
1 parent dc58910 commit dcd174f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.

### Improvements
- Switch from CssAbsoluteFilter to CssRelativeFilter (#822)
- Add statsd metric collection in hc.lib.s3.get_object()

## v2.8.1 - 2023-04-11

Expand Down
4 changes: 4 additions & 0 deletions hc/lib/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from threading import Thread

from django.conf import settings
from statsd.defaults.env import statsd

try:
from minio import Minio, S3Error
Expand Down Expand Up @@ -63,6 +64,7 @@ def enc(n):
return len_inverted + inverted + "-" + s


@statsd.timer("hc.lib.s3.getObjectTime")
def get_object(code, n):
if not settings.S3_BUCKET:
return None
Expand All @@ -73,8 +75,10 @@ def get_object(code, n):
response = client().get_object(settings.S3_BUCKET, key)
return response.read()
except S3Error:
statsd.incr("hc.lib.s3.getObjectErrors")
return None
except HTTPError:
statsd.incr("hc.lib.s3.getObjectErrors")
return None
finally:
if response:
Expand Down

0 comments on commit dcd174f

Please sign in to comment.