fix(oauth2): log database token failures - #42644
Conversation
|
The logging changes in this pull request are designed to avoid logging sensitive information by using structured logging that captures only metadata, such as superset/commands/database/oauth2.py |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42644 +/- ##
==========================================
- Coverage 65.43% 65.42% -0.01%
==========================================
Files 2810 2810
Lines 159460 159385 -75
Branches 36396 36367 -29
==========================================
- Hits 104342 104282 -60
+ Misses 53075 53060 -15
Partials 2043 2043
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| return self.response_404() | ||
|
|
||
| @expose("/oauth2/", methods=["GET"]) | ||
| @statsd_metrics |
There was a problem hiding this comment.
Suggestion: The newly added statsd_metrics wrapper emits the failure counter from its exception handler without protecting self.incr_stats(...). If the configured StatsD client fails while recording an OAuth2 error, that secondary exception replaces the original callback failure and can change the response and traceback presented to the client. Make metric emission best-effort so observability failures cannot mask the OAuth2 exception. [error handling]
Severity Level: Minor 🧹
- ❌ OAuth2 failure responses can expose a StatsD error instead.
- ⚠️ Original token-exchange diagnostics can be lost.
- ⚠️ Callback error handling depends on StatsD availability.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/databases/api.py
**Line:** 1457:1457
**Comment:**
*Error Handling: The newly added `statsd_metrics` wrapper emits the failure counter from its exception handler without protecting `self.incr_stats(...)`. If the configured StatsD client fails while recording an OAuth2 error, that secondary exception replaces the original callback failure and can change the response and traceback presented to the client. Make metric emission best-effort so observability failures cannot mask the OAuth2 exception.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
SUMMARY
Why
OAuth2 database token exchange and refresh failures lacked queryable context, and the callback emitted an outcome-neutral event metric that did not represent failures.
What
database_id, engine, and exception type while excluding OAuth codes, tokens, and provider payloads.DatabaseRestApi.oauth2.success,.warning, and.erroroutcomes are distinguishable, while disabling the old duplicate unqualified event counter.Blast radius
Limited to OAuth2 database token exchange/refresh error handling and callback observability. Existing exceptions and token cleanup behavior are preserved.
TESTING INSTRUCTIONS
The OAuth2 test selection passes with 39 tests. All changed-file pre-commit hooks pass.
A full-repository pre-commit run was also attempted; it reaches unrelated existing mypy errors in version-restore tests and frontend custom-rule checks cannot load the uninstalled
globpackage in this worktree.RISK & ROLLBACK
Low risk: no success-path or persistence semantics change. Roll back this commit to restore the prior logging and metric behavior.
REVIEW GUIDANCE
Please focus on log-field usefulness/redaction and the callback decorator ordering, which ensures outcome metrics wrap transaction completion.
ADDITIONAL INFORMATION