Skip to content

Commit

Permalink
metrics: Indicate which user used legacy_api_key_v2 (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Feb 15, 2024
1 parent 6b2e7cf commit bcd4c6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mwdb/core/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def uses_deprecated_api(
feature: DeprecatedFeature,
endpoint: Optional[str] = None,
method: Optional[str] = None,
user: Optional[str] = None,
):
user = g.auth_user.login if g.auth_user is not None else None
if user is None:
user = g.auth_user.login if g.auth_user is not None else None
metric_deprecated_usage.inc(
feature=str(feature.value), endpoint=endpoint, method=method, user=user
)
Expand Down
4 changes: 3 additions & 1 deletion mwdb/model/api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def verify_token(token):
return None
else:
# Note a deprecated usage
uses_deprecated_api(DeprecatedFeature.legacy_api_key_v2)
uses_deprecated_api(
DeprecatedFeature.legacy_api_key_v2, user=data.get("login")
)

try:
api_key_obj = APIKey.query.filter(
Expand Down

0 comments on commit bcd4c6e

Please sign in to comment.