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

Prod 2435: bq connection test #5138

Merged
merged 12 commits into from
Jul 31, 2024
Merged

Conversation

thingscouldbeworse
Copy link
Contributor

@thingscouldbeworse thingscouldbeworse commented Jul 30, 2024

Closes #PROD-2435

Description Of Changes

A more reliable connection test for bigquery

Code Changes

  • Override the base test_connection function of Bigquery connectors to run list_all_projects and return failure on an empty return value.

Steps to Confirm

  • Create any integration for a Bigquery data source and click "test integration"
  • On a dev instance manually force an exception (raise, i =1/0, etc) inside the try/except
  • Manually set all_projects to [] and confirm the test fails

Pre-Merge Checklist

  • All CI Pipelines Succeeded
  • Documentation:
    • documentation complete, PR opened in fidesdocs
    • documentation issue created in fidesdocs
    • if there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
  • Issue Requirements are Met
  • Relevant Follow-Up Issues Created
  • Update CHANGELOG.md
  • For API changes, the Postman collection has been updated
  • If there are any database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!

Copy link

vercel bot commented Jul 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fides-plus-nightly ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2024 6:24pm

Copy link

cypress bot commented Jul 30, 2024



Test summary

4 0 0 0


Run details

Project fides
Status Passed
Commit 5387765cc1 ℹ️
Started Jul 31, 2024 6:33 PM
Ended Jul 31, 2024 6:33 PM
Duration 00:36 💡
OS Linux Ubuntu -
Browser Electron 106

View run in Cypress Cloud ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 86.48%. Comparing base (681b39c) to head (2bd07b6).
Report is 1 commits behind head on main.

Files Patch % Lines
src/fides/api/service/connectors/sql_connector.py 8.33% 11 Missing ⚠️
...ction_configuration/connection_secrets_bigquery.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5138      +/-   ##
==========================================
- Coverage   86.52%   86.48%   -0.05%     
==========================================
  Files         359      359              
  Lines       22470    22485      +15     
  Branches     2978     2980       +2     
==========================================
+ Hits        19443    19446       +3     
- Misses       2494     2506      +12     
  Partials      533      533              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -323,6 +324,26 @@ def connection_status(
) -> TestStatusMessage:
"""Connect, verify with a trivial query or API request, and report the status."""

# test if this is a Bigquery connection
if connection_config.connection_type == ConnectionType.bigquery:
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm. this will probably work, but i think there may be a cleaner way to inject the "custom" bigquery logic.

what i'd lean toward is implementing an overridden test_connection method in the BigQueryConnector class that's a subclass of the SQLConnector (this is the bigquery "DSR connector"): https://github.com/ethyca/fides/blob/main/src/fides/api/service/connectors/sql_connector.py#L476

that allows us to keep all the generic wrapping logic in tact, and it puts in the "custom" bigquery logic into a class specifically scoped toward bigquery. this will pave the road nicely for when we move the BigQueryConnector to leverage the python bigquery client, as is currently used in the d&d workflow.

@thingscouldbeworse thingscouldbeworse marked this pull request as ready for review July 30, 2024 14:26
Copy link
Contributor

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

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

@thingscouldbeworse this looks good to me! just a few things that i think we could polish up here to get it as clean as possible, but generally this is how i was imagining this would work - nice job!

also, i assume you've done some manual testing? i didn't get to do any yet. if you've done that, could you please list out the manual steps you've taken to confirm in the PR description? i think it would be good for at least one of us to manually test out some of the error cases locally and make sure this is working as we expect - if you've done that, then great

if all_projects:
return ConnectionTestStatus.succeeded
else:
raise ConnectionException("No datasets found with the provided credentials.")
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nice handling! just a tweak on the wording:

Suggested change
raise ConnectionException("No datasets found with the provided credentials.")
raise ConnectionException("No bigquery projects found with the provided credentials.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

else:
raise ConnectionException("No datasets found with the provided credentials.")
except Exception as e:
raise ConnectionException(f"Connection error: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

this is solid for the exception that's raised up (and hopefully gets to the UI?) in addition, it might be nice to log the exception here too, ideally with a full stack trace - since this endpoint is specifically for troubleshooting, giving as much error information as possible can be helpful.

you can use logger.exception - i think that may give you a stack trace, or you may need to still specify some args/options to get a full stack trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

logger exception here: 16d65db#diff-15895ed412c26a8f5c097a7eddfa11273da29a8d999e7c342bdeb475224fff8aR537 I do see the exception in logs if I induce one

Comment on lines +514 to +515
# Overrides SQLConnector.test_connection
def test_connection(self) -> Optional[ConnectionTestStatus]:
Copy link
Contributor

Choose a reason for hiding this comment

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

may be a question of preference, but i tend to put these sort of comments as proper method docstrings, and that plays nicely with many IDEs. i would note here that we're specifically testing with the native bigquery python client that's used for the d&d workflows, even though it is not yet used for the DSR workflows. something like this?

Suggested change
# Overrides SQLConnector.test_connection
def test_connection(self) -> Optional[ConnectionTestStatus]:
def test_connection(self) -> Optional[ConnectionTestStatus]:
"""
Overrides SQLConnector.test_connection with a BigQuery-specific connection test.
The connection is tested using the native python client for BigQuery, since that is what's used
by the detection and discovery workflows/codepaths. We will eventually look to migrate the
rest of this class, used for DSR execution, to also make use of the native bigquery client.
"""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thingscouldbeworse thingscouldbeworse changed the title Prod 2435 bq connection test Prod 2435: bq connection test Jul 31, 2024
Copy link
Contributor

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

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

looks good @thingscouldbeworse, thanks for making the requested updates! 👍

@thingscouldbeworse thingscouldbeworse merged commit ee89e38 into main Jul 31, 2024
44 of 45 checks passed
@thingscouldbeworse thingscouldbeworse deleted the PROD-2435_bq-connection-test branch July 31, 2024 19:47
Copy link

cypress bot commented Jul 31, 2024



Test summary

4 0 0 0


Run details

Project fides
Status Passed
Commit ee89e38
Started Jul 31, 2024 8:00 PM
Ended Jul 31, 2024 8:00 PM
Duration 00:37 💡
OS Linux Ubuntu -
Browser Electron 106

View run in Cypress Cloud ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants