-
Notifications
You must be signed in to change notification settings - Fork 126
[COST-7401] Wasted Cost Fix #6029
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
Open
myersCody
wants to merge
23
commits into
main
Choose a base branch
from
wasted_cost_solutions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7b8aabb
[COST-7401] Potential wasted cost solutions
myersCody 23fe591
Merge branch 'main' into wasted_cost_solutions
myersCody ccd9e83
Fix mermaid graphs
myersCody 3ef6432
Implement s1a
myersCody 4536352
Update docs
myersCody d098bd1
Save current approach
myersCody e17d95b
Reset architecture docs
myersCody e497a58
Back out provider map changes
myersCody be2d96c
Merge branch 'main' into wasted_cost_solutions
myersCody e07d577
Make the provider map easy to read
myersCody a294088
Turn off wasted_cost
myersCody 89ace5a
Save current approach
myersCody 9d6f693
Moved logic into provider map
myersCody 705ed91
Clean up provider map
myersCody 6193697
Remove unused code from query handler
myersCody 23b8550
Unify the packing strategy for wasted cost
myersCody ea8a3ea
Improve readability
myersCody bec1298
Merge branch 'main' into wasted_cost_solutions
myersCody 966c527
Fix unittests
myersCody e833d43
Merge branch 'main' into wasted_cost_solutions
myersCody 31ae100
Add format logic for clean test pass
myersCody fed3075
Fix key error for total_score
myersCody 20ca1bf
Merge branch 'main' into wasted_cost_solutions
myersCody File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -112,6 +112,14 @@ def __init__(self, parameters): | |||||||||||||||
| ocp_pack_definitions["compute"] = {"keys": ["compute"], "units": "mig_compute_units"} | ||||||||||||||||
| ocp_pack_definitions["memory"] = {"keys": ["memory"], "units": "mig_memory_units"} | ||||||||||||||||
| ocp_pack_definitions["gpu_count"] = {"keys": ["gpu_count"], "units": "gpu_count_units"} | ||||||||||||||||
| ocp_pack_definitions["score_efficiency"] = { | ||||||||||||||||
| "keys": {"usage_efficiency": {"key": "usage_efficiency_percent", "group": "score"}}, | ||||||||||||||||
| "units": None, | ||||||||||||||||
| } | ||||||||||||||||
| ocp_pack_definitions["score_wasted"] = { | ||||||||||||||||
| "keys": {"wasted_cost": {"key": "wasted_cost", "group": "score"}}, | ||||||||||||||||
| "units": "wasted_cost_units", | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| # super() needs to be called after _mapper and _limit is set | ||||||||||||||||
| super().__init__(parameters) | ||||||||||||||||
|
|
@@ -229,30 +237,14 @@ def _format_query_response(self): | |||||||||||||||
|
|
||||||||||||||||
| output["data"] = self.query_data | ||||||||||||||||
| self.query_sum = self._pack_data_object(self.query_sum, **self._mapper.PACK_DEFINITIONS) | ||||||||||||||||
| if "score" in self.query_sum: | ||||||||||||||||
| self.query_sum["total_score"] = self.query_sum.pop("score") | ||||||||||||||||
| self.query_sum["total_score"] = self.query_sum.pop("score", {}) | ||||||||||||||||
| output["total"] = self.query_sum | ||||||||||||||||
|
|
||||||||||||||||
| if self._delta: | ||||||||||||||||
| output["delta"] = self.query_delta | ||||||||||||||||
|
|
||||||||||||||||
| return output | ||||||||||||||||
|
|
||||||||||||||||
| def _pack_score(self, row, should_compute): | ||||||||||||||||
| """Shape efficiency annotations into the score response object.""" | ||||||||||||||||
| if should_compute: | ||||||||||||||||
| row["score"] = { | ||||||||||||||||
| "usage_efficiency_percent": row.pop("usage_efficiency", 0), | ||||||||||||||||
| "wasted_cost": { | ||||||||||||||||
| "value": row.pop("wasted_cost", Decimal(0)), | ||||||||||||||||
| "units": self.currency, | ||||||||||||||||
| }, | ||||||||||||||||
| } | ||||||||||||||||
| else: | ||||||||||||||||
| row.pop("usage_efficiency", None) | ||||||||||||||||
| row.pop("wasted_cost", None) | ||||||||||||||||
| row["score"] = {} | ||||||||||||||||
|
|
||||||||||||||||
| def execute_query(self): # noqa: C901 | ||||||||||||||||
| """Execute query and return provided data. | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -273,9 +265,8 @@ def execute_query(self): # noqa: C901 | |||||||||||||||
| query_group_by = ["date"] + group_by_value | ||||||||||||||||
| query_order_by = ["-date", self.order] | ||||||||||||||||
|
|
||||||||||||||||
| query_data = query.values(*query_group_by).annotate( | ||||||||||||||||
| **{k: v for k, v in self.report_annotations.items() if k not in group_by_value} | ||||||||||||||||
| ) | ||||||||||||||||
| row_annotations = {k: v for k, v in self.report_annotations.items() if k not in group_by_value} | ||||||||||||||||
| query_data = query.values(*query_group_by).annotate(**row_annotations) | ||||||||||||||||
|
|
||||||||||||||||
| if is_grouped_by_project(self.parameters): | ||||||||||||||||
| query_data = self._project_classification_annotation(query_data) | ||||||||||||||||
|
|
@@ -303,16 +294,23 @@ def execute_query(self): # noqa: C901 | |||||||||||||||
| if self._report_type in ("cpu", "memory"): | ||||||||||||||||
| has_tag_interaction = self._tag_group_by or self.get_tag_filter_keys() | ||||||||||||||||
| should_compute = not has_tag_interaction and len(group_by_value) <= 1 | ||||||||||||||||
| self._pack_score(query_sum, should_compute) | ||||||||||||||||
| if should_compute: | ||||||||||||||||
| query_sum["wasted_cost_units"] = self.currency | ||||||||||||||||
| else: | ||||||||||||||||
| query_sum.pop("usage_efficiency", None) | ||||||||||||||||
| query_sum.pop("wasted_cost", None) | ||||||||||||||||
| query_sum.pop("wasted_cost_units", None) | ||||||||||||||||
|
Comment on lines
+299
to
+302
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| if self._delta: | ||||||||||||||||
| query_data = self.add_deltas(query_data, query_sum) | ||||||||||||||||
|
|
||||||||||||||||
| query_data = self.order_by(query_data, query_order_by) | ||||||||||||||||
|
|
||||||||||||||||
| if self._report_type in ("cpu", "memory"): | ||||||||||||||||
| if self._report_type in ("cpu", "memory") and not should_compute: | ||||||||||||||||
| for row in query_data: | ||||||||||||||||
| self._pack_score(row, should_compute) | ||||||||||||||||
| row.pop("usage_efficiency", None) | ||||||||||||||||
| row.pop("wasted_cost", None) | ||||||||||||||||
| row.pop("wasted_cost_units", None) | ||||||||||||||||
|
|
||||||||||||||||
| for row in query_data: | ||||||||||||||||
| if tag_iterable := row.get("tags"): | ||||||||||||||||
|
|
@@ -324,6 +322,12 @@ def execute_query(self): # noqa: C901 | |||||||||||||||
| data = [{"date": date_string, "vm_names": query_data}] | ||||||||||||||||
| else: | ||||||||||||||||
| data = list(query_data) | ||||||||||||||||
| if self._report_type in ("cpu", "memory"): | ||||||||||||||||
| # Pack score fields so the CSV renderer emits score.usage_efficiency_percent | ||||||||||||||||
| # and score.wasted_cost.* columns to match the JSON response structure. | ||||||||||||||||
| score_pack = {k: v for k, v in self._mapper.PACK_DEFINITIONS.items() if k.startswith("score_")} | ||||||||||||||||
| for row in data: | ||||||||||||||||
| self._pack_data_object(row, **score_pack) | ||||||||||||||||
| else: | ||||||||||||||||
| # Pass in a copy of the group by without the added | ||||||||||||||||
| # tag column name prefix | ||||||||||||||||
|
|
||||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
total_scoremust only be injected for compute (cpu/memory) reports. Cost and volume reports have no efficiency score, so this key should be absent entirely.