def extract_key(path, arg_items, cache_prefix_override=None): # filter out query-params with 'None' values filtered_arg_items = filter(lambda x: x[1] is not None, arg_items) req_args = stringify_query_params(filtered_arg_items) prefix = cache_prefix_override if cache_prefix_override else cache_prefix key = f"{prefix}:{path}:{req_args}" return key
def extract_route_key(): """ Extracts the route redis key and hash from the request The key should be of format: <metrics_prefix>:<metrics_routes>:<rounded_date_time_format> ie: "API_METRICS:routes:2020/08/04:14" The hash should be of format: <path><sorted_query_params> ie: "/v1/tracks/search?genre=rap&query=best" """ path = request.path req_args = request.args.items() req_args = stringify_query_params(req_args) route = f"{path}?{req_args}" if req_args else path date_time = get_rounded_date_time().strftime(datetime_format) route_key = f"{metrics_prefix}:{metrics_routes}:{date_time}" return (route_key, route)
def extract_route_key(): """ Extracts the route redis key and hash from the request The key should be of format: <metrics_prefix>:<metrics_routes>:<ip>:<rounded_date_time_format> ie: "API_METRICS:routes:192.168.0.1:2020/08/04:14" The hash should be of format: <path><sorted_query_params> ie: "/v1/tracks/search?genre=rap&query=best" """ path = request.path req_args = request.args.items() req_args = stringify_query_params(req_args) route = f"{path}?{req_args}" if req_args else path ip = request.headers.get('X-Forwarded-For', request.remote_addr) ip = ip.split(',')[0].strip() date_time = get_rounded_date_time().strftime(datetime_format) route_key = f"{metrics_prefix}:{metrics_routes}:{ip}:{date_time}" return (route_key, route)
def extract_key(path, arg_items): # filter out query-params with 'None' values filtered_arg_items = filter(lambda x: x[1] is not None, arg_items) req_args = stringify_query_params(filtered_arg_items) key = f"{cache_prefix}:{path}:{req_args}" return key
def extract_key(): path = request.path req_args = request.args.items() req_args = stringify_query_params(req_args) key = f"{cache_prefix}:{path}:{req_args}" return key