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-2231] Upgrade to Django 4 #4844

Merged
merged 11 commits into from
Feb 19, 2024
Merged

[COST-2231] Upgrade to Django 4 #4844

merged 11 commits into from
Feb 19, 2024

Conversation

djnakabaale
Copy link
Contributor

@djnakabaale djnakabaale commented Dec 20, 2023

Jira Ticket

COST-2231

Description

This change will:

Testing

  1. Stop server containers

    docker compose stop koku-server masu-server worker
    
  2. Update template schema and clone_schema SQL function

    python koku/manage.py migrate_serial_to_identity_columns --schema template0 --write
    

    Or update all schemas

    python koku/manage.py migrate_serial_to_identity_columns --write
    
  3. Rebuild and start server contaiters

    make docker-up-min
    
  4. Create test customer and load data. You may need to delete existing sources first.

    make create-test-customer
    make load-test-customer-data
    
  5. Observe data processing

    make docker-logs
    
  6. Verify sources were created and cost data was loaded

    http://localhost:8000/api/cost-management/v1/reports/oci/costs/
    http://localhost:8000/api/cost-management/v1/reports/azure/costs/
    http://localhost:8000/api/cost-management/v1/reports/aws/costs/
    # etc.
    
  7. Verify template schema was correctly updated in database. Look for the ID column to be generated as identity. Do this on as many tables as you wish.

    psql --host $POSTGRES_SQL_SERVICE_HOST \
         --port $POSTGRES_SQL_SERVICE_PORT \
         --username $DATABASE_ADMIN \
         --password $DATABASE_PASSWORD
         
    \d template0.reporting_ocp_cost_category
    Table "template0.reporting_ocp_cost_category"
         Column     |  Type   | Collation | Nullable |             Default
    ----------------+---------+-----------+----------+----------------------------------
     id             | integer |           | not null | generated by default as identity
     ...
    
  8. Verify the clone_schema SQL function was updated

    psql --host $POSTGRES_SQL_SERVICE_HOST \
     --port $POSTGRES_SQL_SERVICE_PORT \
     --username $DATABASE_ADMIN \
     --password $DATABASE_PASSWORD
     
     \sf clone_schema
     
     [compare the output to db_functions/clone_schema.sql]
    
  9. Run tests

     tox -r -e py39
    

@djnakabaale djnakabaale added the smoke-tests pr_check will build the image and run minimal required smokes label Dec 20, 2023
Copy link

codecov bot commented Dec 20, 2023

Codecov Report

Merging #4844 (7060573) into main (a7d38ed) will decrease coverage by 0.0%.
The diff coverage is 85.5%.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #4844     +/-   ##
=======================================
- Coverage   94.0%   94.0%   -0.0%     
=======================================
  Files        374     374             
  Lines      30838   30841      +3     
  Branches    3663    3663             
=======================================
  Hits       28978   28978             
- Misses      1196    1199      +3     
  Partials     664     664             

Copy link

sonarcloud bot commented Dec 20, 2023

@samdoran samdoran force-pushed the cost-2231-django-4 branch 4 times, most recently from 2aead84 to c382291 Compare February 2, 2024 16:48
@samdoran samdoran force-pushed the cost-2231-django-4 branch 3 times, most recently from 441f4f1 to 4f62011 Compare February 13, 2024 20:42
@samdoran
Copy link
Contributor

/retest

@samdoran samdoran marked this pull request as ready for review February 14, 2024 22:13
@samdoran samdoran requested review from a team as code owners February 14, 2024 22:13
@samdoran samdoran changed the title [COST-2231] Upgrade to Django 4.x [COST-2231] Upgrade to Django 4 Feb 15, 2024
@project-koku project-koku deleted a comment from sonarcloud bot Feb 15, 2024
koku/api/deprecated_settings/view.py Outdated Show resolved Hide resolved
koku/api/migrations/0062_update_clone_schema_function.py Outdated Show resolved Hide resolved
koku/masu/test/util/aws/test_common.py Outdated Show resolved Hide resolved
@@ -0,0 +1,20 @@
MIT License
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow the thinking about adding this new license file. Yes, we added a file that uses the MIT license, but could we not just add it to the single file that uses it?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not necessary but it makes it far easier to communicate the licenses used by the project. Otherwise it's necessary to inspect every file in the project to see how they are licensed.

licenses/MIT.txt Outdated Show resolved Hide resolved
samdoran and others added 7 commits February 16, 2024 12:55
* Remove gettext alias
* Mocks for get_response required by middlewaremixin
* Use method_decorator to apply neevr_cache on class method
* Method set_context deprecated in DRF 3.12 in favor of requires_context
* User Django RedisCache and remove django_redis library
* Update deprecated ‘warn’ method
* Remove deprecated test case method
* Remove deprecated Series.bool method
* Correct docstring and class attribute name
* Cleanup file handle
* Fix flaky test

  This assert statement will always fail since the template schema does not yet
  exists. This test will only pass if another test runs before this test creates
  the template schema.

* Update clone_schema.sql

  Do not define a custom sequence object since that is no longer required with the
  move to identity columns.

  Do not define a custom sequence object since that is no longer required with the
  move to identity columns.

* Avoid unnecessary globals
* Add management command to migrate serial ID columns to identity

* Update license information

  Add correct copyright and license information to management command.

  Create project level licenses to reflect the use of multiple licenses within
  the project.

* Improvements to serial to identity management command

  Use SQL composition rather than format strings to protect against SQL injection
  attacks. The risk is quite low, but it’s best to just do the right thing.
  Reorganize the code to avoid a nested function definiton and an unnecessary
  global variable that only needed to be local.

* Add migration to update clone_schema function

---------

Co-authored-by: Sam Doran <[email protected]>
Co-authored-by: Michael Skarbek <[email protected]>
Co-authored-by: David Nakabaale <[email protected]>
* Clean up unittest  test_execute_query_with_group_by_tag_and_limit
* Move Window after aggregation in group_by annotation

  Since the Window is used only to provide row numbers and there is no additional
  filtering done on the data in the Window, moving it after the ArrayAgg fixes the
  error encountered in Django 4.2 and returns the same data in the same order.

* Check correct log level in test
  This works in Python 3.9 due to a bug in unittest.

* Use test database name from settings instead of hard coding it
* Use consistent name for test database
* Correct patching in test
Currently we are relying on Django’s internal test setup to add a `test_` prefix
to the default database name. This works fine most of the time but it’s better
to be explicit.
This prevents tripping up flake8 and the need for an ignore or parenthesis
@samdoran samdoran force-pushed the cost-2231-django-4 branch 2 times, most recently from 2a4040e to 0a2b01d Compare February 16, 2024 18:09
@samdoran
Copy link
Contributor

/retest

@samdoran samdoran merged commit f1fbe8d into main Feb 19, 2024
11 checks passed
@samdoran samdoran deleted the cost-2231-django-4 branch February 19, 2024 16:43
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
3 participants