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-3794] Add new API for managing custom cost groups #4401

Merged
merged 48 commits into from
Dec 12, 2023

Conversation

samdoran
Copy link
Contributor

@samdoran samdoran commented May 30, 2023

Jira Ticket

COST-3794

Description

Add new API with PUT/GET/DELETE methods to control what projects belong to which cost groups. Currently there is only one cost group, Platform. In the future, we will all customers to create custom cost groups and add projects to them.

Testing

Get current cost groups

curl -sSL localhost:8000/api/cost-management/v1/settings/cost-groups/

Get just non-default projects

curl -gsSL 'localhost:8000/api/cost-management/v1/settings/cost-groups/?filter[default]=false'

Add new projects to platform projects:

curl -X "PUT" "http://localhost:8000/api/cost-management/v1/settings/cost-groups/" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '[
    {
        "project_name": "analytics",
        "group": "Platform"
    }
]'

Delete projects from cost groups. Default projects will not be deleted.

curl -X "DELETE" "http://localhost:8000/api/cost-management/v1/settings/cost-groups/" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '[
    {
        "project_name": "analytics",
        "group": "Platform"
    }
]'

@sonarcloud
Copy link

sonarcloud bot commented Jun 7, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

48.5% 48.5% Coverage
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Jun 7, 2023

Codecov Report

Merging #4401 (84482fb) into main (d758158) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files
@@          Coverage Diff           @@
##            main   #4401    +/-   ##
======================================
  Coverage   93.9%   94.0%            
======================================
  Files        361     364     +3     
  Lines      29900   30132   +232     
  Branches    3562    3589    +27     
======================================
+ Hits       28079   28310   +231     
  Misses      1161    1161            
- Partials     660     661     +1     

@samdoran samdoran force-pushed the COST-3394/project-api-update branch 3 times, most recently from afaa832 to e30a80d Compare October 12, 2023 20:01
@samdoran samdoran added the smoke-tests pr_check will build the image and run minimal required smokes label Oct 12, 2023
@samdoran samdoran marked this pull request as ready for review October 13, 2023 20:08
@samdoran samdoran requested review from a team as code owners October 13, 2023 20:08
@samdoran samdoran force-pushed the COST-3394/project-api-update branch 2 times, most recently from 5450485 to 07bd994 Compare October 16, 2023 13:51
@sonarcloud
Copy link

sonarcloud bot commented Oct 16, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@lcouzens
Copy link
Contributor

So the initial code looks good for the most part. I think we need some updated testing instructions though (Might be because this is still WIP? But it is not in draft so 🤷) The other part we are still missing is the re-summary step, to trigger a re-summary task for the openshfit provider/source. That will populate the category_id and thus update the platform cost distribution.

I did manually test this out locally and it did seem to work so great job there! In short after you add/remove a project to the platform category we just need to trigger update_summary_tables task.

@samdoran samdoran marked this pull request as draft October 27, 2023 03:23
@samdoran
Copy link
Contributor Author

samdoran commented Oct 27, 2023

I think we need some updated testing instructions though

I added instructions for testing GET, PUT, and DELETE. Sorry I didn't add those before.

The other part we are still missing is the re-summary step

I added resummarization on PUT or DELETE. update_summary_tables requires schema_name, provider_type, and provider_uuid. The schema name is readily available from the request. I used Provider.PROVIDER_OCP for provider_type though I'm not sure that's correct. I was even less clear on how to get the provider UUID(s). I ran a query to get provider UUIDs based on the customer and provider type.

I could use some help making sure I'm scheduling this task correctly..

@samdoran samdoran force-pushed the COST-3394/project-api-update branch 2 times, most recently from f1c354b to 2a738d5 Compare November 1, 2023 21:50
@samdoran samdoran changed the title [COST-3794] Add new API for managing platform cost categories [COST-3794] Add new API for managing custom cost groups Nov 1, 2023
@samdoran samdoran force-pushed the COST-3394/project-api-update branch 2 times, most recently from 4c0fe6e to 591bc30 Compare November 16, 2023 14:44
@myersCody myersCody removed the smoke-tests pr_check will build the image and run minimal required smokes label Nov 28, 2023
@samdoran samdoran force-pushed the COST-3394/project-api-update branch 4 times, most recently from 3d2b22e to 9961b9e Compare December 1, 2023 22:10
samdoran and others added 25 commits December 12, 2023 11:07
Cache list of default projects to prevent multiple database queries.

Co-authored-by: Cody Myers <[email protected]>
Since this is a class var, make it immutable to make this class thread safe.
- Add docstring
- Use a frozenset for allowlist since that better matches how it is used
This mathches our custom query param syntax with the behavior of Django and DRF.

Increase test coverage.
I tried to use a sub test but was having problems with duplicate key violations
for some reason.
Copy link

sonarcloud bot commented Dec 12, 2023

@samdoran samdoran merged commit 5fdf225 into main Dec 12, 2023
10 checks passed
@samdoran samdoran deleted the COST-3394/project-api-update branch December 12, 2023 20:50
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.

3 participants