Fix silent 100-row cap in API-key analytics and summary - #295
Open
nicolasgutierrezdev wants to merge 1 commit into
Open
nicolasgutierrezdev wants to merge 1 commit into
nicolasgutierrezdev wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_user_summaryandget_usage_analyticsadded up usage rows in Python, working from the result of fastcrud'sget_multi. That call returns at most 100 rows by default, so every metric was silently wrong once a key or user had more than 100 usage rows.get_multi. That call returns at most 100 rows by default, so every metric was silently wrong once a key or user had more than 100 usage rows.Changes
get_user_summary:total_cost_microcentsnow comes from a SQLSUM(newsum_user_usage_cost). It used to cover only 100 rows whiletotal_requestscounted all of them.get_usage_analytics: totals, the top endpoints, the error breakdown and daily usage are now computed in SQL withCOUNT,SUM,AVGandGROUP BY.api_keys/utils.py: removed, since nothing uses the Python aggregation helpers any more.Testing
I added 150 usage rows to one key and comparode, in unit tests and on both versions ofthe app running live:
total_cost_microcentstotal_requestsfailed_requestserror_breakdown{}{"500": 50}usage_by_dayFollow-up (not in this PR)
get_user_summarygets keys throughget_user_api_keys, which returns at most 50. That capstotal_keysandactive_keysat 50.