Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bigquery): Add extra logging for BigQuery exceptions so we can have better insight on exceptions #22024

Merged
merged 5 commits into from
Nov 10, 2022

Conversation

Antonio-RiveroMartnez
Copy link
Member

SUMMARY

Some BigQuery exceptions are not being logged with enough information, so we need to add some extra method that parses the original exception and logs the correct message. We also add some unit tests to the new method.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

After:
test

TESTING INSTRUCTIONS

  1. Connect Locally to a BigQuery DB
  2. Run an invalid SQL statement so you get a BigQuery exception
  3. Check you are logging the correct message out of the original exception

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Nov 3, 2022

Codecov Report

Merging #22024 (afa7200) into master (aa48cae) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master   #22024   +/-   ##
=======================================
  Coverage   67.07%   67.07%           
=======================================
  Files        1815     1815           
  Lines       69575    69581    +6     
  Branches     7486     7486           
=======================================
+ Hits        46665    46673    +8     
+ Misses      20974    20972    -2     
  Partials     1936     1936           
Flag Coverage Δ
hive 52.83% <60.00%> (+<0.01%) ⬆️
mysql 78.39% <60.00%> (-0.01%) ⬇️
postgres 78.46% <60.00%> (-0.01%) ⬇️
presto 52.73% <40.00%> (-0.01%) ⬇️
python 81.57% <100.00%> (+<0.01%) ⬆️
sqlite 76.92% <60.00%> (-0.01%) ⬇️
unit 51.21% <80.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/db_engine_specs/base.py 89.21% <100.00%> (+0.05%) ⬆️
superset/db_engine_specs/bigquery.py 82.58% <100.00%> (+0.53%) ⬆️
superset/db_engine_specs/druid.py 83.33% <0.00%> (+2.38%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

superset/db_engine_specs/base.py Outdated Show resolved Hide resolved
superset/db_engine_specs/bigquery.py Outdated Show resolved Hide resolved
superset/utils/core.py Outdated Show resolved Hide resolved
Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at inheritance.. come back to this

- Add new method to parse unknown exception in BigQuery engines. This method is going to shed some light so we can show correct messages later using our regex
    - Use new EngineType enum instead of raw string
    - Add better exception handling for new parse_error_exception method in case anything fails during the parsing
    - Add test to back the exception handling
- parse_error_exception returns an exception with the parsed message, because of that we can skip the compare with Bigquery and instead just make use of the existing logger upstream (sql_lab)
| . | . | . | . | . | . | . | . | . | . | . | . | . | . | . |


bigquery error: 400 Table \"case_detail_all_suites\" must be qualified with a dataset (e.g. dataset.table).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make all the test work with this example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 👍

- Update our method and tests so bigquery error: portion doesn't appear in the message
@hughhhh hughhhh requested a review from eschutho November 8, 2022 22:20
try:
return Exception(
str(exception) # pylint: disable=use-maxsplit-arg
.rsplit("\n")[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also use .splitlines()[0] here

.rsplit(":")[1]
.strip()
)
except Exception: # pylint: disable=broad-except
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to get this to raise an exception and wasn't able to. I believe as long as the return value is a string, you should be able to perform all of the operations and don't need to put it in a try catch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm if for some unknown reason the Exception has no : for example, accessing the [1] would cause a: IndexError: list index out of range. Just adding the try/catch there in case anything like that happens with the message we get.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok I tried it with no new line. That makes sense.

- Use splitlines instead and avoid ignoring pylint rules
Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @Antonio-RiveroMartnez!

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants