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

[COST-4852] Inserting attempts loop to Trino queries #5210

Merged
merged 122 commits into from
Aug 12, 2024

Conversation

bacciotti
Copy link
Contributor

@bacciotti bacciotti commented Jul 9, 2024

Jira Ticket

COST-4852

Description

This change will implement an attempts' logic on Trino queries to avoid some Exceptions raisings.
We are removing the loop from the delete function and inserting in the functions that execute insertion queries.
I've set the attempts to three just for Azure for now. Let's monitor the Exceptions.

Testing

  1. Checkout Branch
  2. Restart Koku
  3. Test local ingestion, specially with Azure
  4. Run tox -e py39 -- hcs.test.database.test_report_db_accessor.TestHCSReportDBAccessor and tox -e py39 -- masu.test.database.test_azure_report_db_accessor.AzureReportDBAccessorTest

Release Notes

  • Improving some Trino queries logic to avoid Exceptions.
* [COST-4582](https://issues.redhat.com/browse/COST-4582) Improving some Trino queries logic to avoid Exceptions.

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 92.47312% with 7 lines in your changes missing coverage. Please review.

Project coverage is 94.1%. Comparing base (58ef74a) to head (268a7f1).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #5210   +/-   ##
=====================================
  Coverage   94.1%   94.1%           
=====================================
  Files        375     375           
  Lines      31411   31422   +11     
  Branches    4627    4627           
=====================================
+ Hits       29545   29560   +15     
+ Misses      1190    1189    -1     
+ Partials     676     673    -3     

@bacciotti bacciotti changed the title [COST-4582] Inserting attempts loop to Trino queries [COST-4852] Inserting attempts loop to Trino queries Jul 9, 2024
@bacciotti bacciotti marked this pull request as ready for review July 9, 2024 15:22
@bacciotti bacciotti requested review from a team as code owners July 9, 2024 15:22
koku/koku/trino_database.py Outdated Show resolved Hide resolved
koku/koku/trino_database.py Outdated Show resolved Hide resolved
koku/masu/database/report_db_accessor_base.py Outdated Show resolved Hide resolved
koku/masu/database/report_db_accessor_base.py Outdated Show resolved Hide resolved
@bacciotti bacciotti requested a review from lcouzens July 10, 2024 12:24
lcouzens
lcouzens previously approved these changes Jul 18, 2024
@bacciotti
Copy link
Contributor Author

/retest

Copy link
Member

@maskarb maskarb left a comment

Choose a reason for hiding this comment

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

Shouldn't we pull the changes in #5237 into this PR?

koku/koku/trino_database.py Outdated Show resolved Hide resolved
koku/hcs/test/database/test_report_db_accessor.py Outdated Show resolved Hide resolved
koku/hcs/test/database/test_report_db_accessor.py Outdated Show resolved Hide resolved
koku/hcs/test/database/test_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_aws_report_db_accessor.py Outdated Show resolved Hide resolved
@samdoran
Copy link
Contributor

samdoran commented Aug 8, 2024

In order to retry only on hive metastore errors, we'll need another exception object.

class TrnioMetastoreError(Exception):
    ...

@retry(retry_on=(TrinoNoSuchKeyException, TrinoHiveMetastoreError)
    try:
        ...
    except TrinoQueryError as trino_exc:
        exc_to_raise = TrinoStatementExecError(
            statement=stmt, statement_number=stmt_num, sql_params=s_params, trino_error=trino_exc
        )
        if "NoSuchKey" in str(trino_exc):
            exc_to_raise = TrinoNoSuchKeyException(
                message=trino_exc.message,
                query_id=trino_exc.query_id,
                error_code=trino_exc.error_code,
            )

        if trino_exc.error_name == "HIVE_METASTORE_ERROR":
            exc_to_raise = TrinoHiveMetastoreError(
                message=trino_exc.message,
                query_id=trino_exc.query_id,
                error_code=trino_exc.error_code,
            )

        LOG.warning(f"{exc_to_raise!s}")
        raise exc_to_raise from trino_exc

You could create an exception class hierarchy if you wanted for these custom exceptions.

koku/masu/database/report_db_accessor_base.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_aws_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_aws_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_azure_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_azure_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_azure_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_gcp_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_gcp_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_ocp_report_db_accessor.py Outdated Show resolved Hide resolved
koku/masu/test/database/test_ocp_report_db_accessor.py Outdated Show resolved Hide resolved
Inspecting the attribute is more precise than relying on the representation
returned by str.
Use “Error” suffix to be more in line with how exception classes are name.
Create a class hierarchy for custom exceptions to better identify errors from
within our code.
Since the retry moved from the caller, patching out the entire method for
testing will no longer work.
Instead, raise an exception within
_execute_trino_raw_sql_query_with_description to better simulate the failures
durnig which the retry behavior is desired.
@samdoran samdoran force-pushed the cost-4582_improving_attempts_functionality branch from 9ee1bdf to 6fea578 Compare August 10, 2024 02:06
@samdoran
Copy link
Contributor

/retest

@bacciotti
Copy link
Contributor Author

/retest

@bacciotti bacciotti enabled auto-merge (squash) August 12, 2024 10:15
@bacciotti bacciotti merged commit 6c9cb86 into main Aug 12, 2024
11 checks passed
@bacciotti bacciotti deleted the cost-4582_improving_attempts_functionality branch August 12, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smoke-tests pr_check will build the image and run minimal required smokes smokes-required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants