Skip to content

Commit

Permalink
Provide numeric value for dates for easier analysis later (#332)
Browse files Browse the repository at this point in the history
* Feature/ratelimiter update (#330)

* updated request_is_limited algorithm

* Strip out numbers from paths

  This is so we can better aggregate by path in cloudwatch

* Provide numeric value for dates for easier analysis later

---------

Co-authored-by: Russ Biggs <[email protected]>
  • Loading branch information
caparker and russbiggs authored Feb 10, 2024
1 parent abffc15 commit d58697b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion openaq_api/openaq_api/models/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from humps import camelize
from pydantic import BaseModel, ConfigDict, Field, computed_field
import re
from dateutil.parser import parse

class LogType(StrEnum):
SUCCESS = "SUCCESS"
Expand Down Expand Up @@ -120,7 +121,17 @@ def params(self) -> str:
@property
def params_obj(self) -> dict:
"""dict: returns URL query params as key values from request"""
return dict(x.split("=", 1) for x in self.params.split("&") if "=" in x)
params = dict(x.split("=", 1) for x in self.params.split("&") if "=" in x)
try:
# if bad strings make it past our validation than this will protect the log
if 'date_from' in params.keys():
params['date_from_epoch'] = parse(params['date_from']).timestamp()
if 'date_to' in params.keys():
params['date_to_epoch'] = parse(params['date_to']).timestamp()
except Exception:
pass

return params

@computed_field(return_type=list)
@property
Expand Down

0 comments on commit d58697b

Please sign in to comment.