Skip to content

Commit

Permalink
Merge branch 'main' into COST-4670/pandas-cow
Browse files Browse the repository at this point in the history
  • Loading branch information
esebesto committed Mar 27, 2024
2 parents 6370b1b + 5c7647f commit f3d043d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
11 changes: 9 additions & 2 deletions koku/api/report/ocp/provider_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from api.models import Provider
from api.report.provider_map import ProviderMap
from masu.processor import is_feature_cost_3083_all_labels_enabled
from providers.provider_access import ProviderAccessor
from reporting.models import OCPUsageLineItemDailySummary
from reporting.provider.ocp.models import OCPCostSummaryByNodeP
Expand All @@ -34,6 +35,12 @@
class OCPProviderMap(ProviderMap):
"""OCP Provider Map."""

@cached_property
def check_unleash_for_tag_column_cost_3038(self):
if is_feature_cost_3083_all_labels_enabled(self._schema_name):
return "all_labels"
return "pod_labels"

def __cost_model_cost(self, cost_model_rate_type=None):
"""Return ORM term for cost model cost"""
if cost_model_rate_type:
Expand Down Expand Up @@ -165,7 +172,7 @@ def __init__(self, provider, report_type, schema_name):
"tag_column": "pod_labels", # default for if a report type does not have a tag_column
"report_type": {
"costs": {
"tag_column": "all_labels",
"tag_column": self.check_unleash_for_tag_column_cost_3038,
"tables": {"query": OCPUsageLineItemDailySummary},
"aggregates": {
"sup_raw": Sum(Value(0, output_field=DecimalField())),
Expand Down Expand Up @@ -215,7 +222,7 @@ def __init__(self, provider, report_type, schema_name):
"sum_columns": ["cost_total", "infra_total", "sup_total"],
},
"costs_by_project": {
"tag_column": "all_labels",
"tag_column": self.check_unleash_for_tag_column_cost_3038,
"tables": {"query": OCPUsageLineItemDailySummary},
"aggregates": {
"sup_raw": Sum(Value(0, output_field=DecimalField())),
Expand Down
3 changes: 2 additions & 1 deletion koku/api/report/test/ocp/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,8 @@ def test_execute_query_with_tag_filter(self):
result = data_totals.get(key, {}).get("value")
self.assertEqual(result, expected)

def test_execute_costs_query_with_tag_filter(self):
@patch("api.report.ocp.provider_map.is_feature_cost_3083_all_labels_enabled", return_value=True)
def test_execute_costs_query_with_tag_filter(self, mock_unleash):
"""Test that data is filtered by tag key."""
url = "?filter[type]=pod&filter[time_scope_value]=-10&filter[enabled]=true"
query_params = self.mocked_query_params(url, OCPTagView)
Expand Down
8 changes: 8 additions & 0 deletions koku/masu/processor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,11 @@ def is_feature_cost_3592_tag_mapping_enabled(account):
account = convert_account(account)
context = {"schema": account}
return UNLEASH_CLIENT.is_enabled(unleash_flag, context, fallback_development_true)


def is_feature_cost_3083_all_labels_enabled(account):
"""Should all labels column be enabled."""
unleash_flag = "cost-management.backend.feature-cost-3083-all-labels"
account = convert_account(account)
context = {"schema": account}
return UNLEASH_CLIENT.is_enabled(unleash_flag, context, fallback_development_true)
2 changes: 1 addition & 1 deletion koku/providers/provider_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ProviderErrors:
"The provided client secret keys for this source are expired. "
"In Azure, refresh your client secret and try again."
)
AZURE_INCORRECT_CLIENT_SECRET_MESSAGE = (
AZURE_CLIENT_SECRET_INCORRECT_MESSAGE = (
"A problem has been detected with the Azure client secret for this source. "
"Refer to the Microsoft Azure troubleshooting guide in the cost management documentation for details."
)
Expand Down
2 changes: 1 addition & 1 deletion koku/sources/sources_error_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def azure_client_errors(self, message):
"""Azure client error messages."""
scrubbed_message = ProviderErrors.AZURE_GENERAL_CLIENT_ERROR_MESSAGE
if any(test in message for test in ["http error: 401", "Authentication failed", "(401) Unauthorized"]):
scrubbed_message = ProviderErrors.AZURE_INCORRECT_CLIENT_SECRET_MESSAGE
scrubbed_message = ProviderErrors.AZURE_CLIENT_SECRET_INCORRECT_MESSAGE
if "AADSTS700016" in message:
scrubbed_message = ProviderErrors.AZURE_INCORRECT_CLIENT_ID_MESSAGE
if "AADSTS90002" in message:
Expand Down
6 changes: 3 additions & 3 deletions koku/sources/test/test_sources_error_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ def test_azure_errors(self):
{
"key": ProviderErrors.AZURE_CLIENT_ERROR,
"internal_message": ", AdalError: Get Token request returned http error: 401 and server response:",
"expected_message": ProviderErrors.AZURE_INCORRECT_CLIENT_SECRET_MESSAGE,
"expected_message": ProviderErrors.AZURE_CLIENT_SECRET_INCORRECT_MESSAGE,
},
{
"key": ProviderErrors.AZURE_CLIENT_ERROR,
"internal_message": "Authentication failed",
"expected_message": ProviderErrors.AZURE_INCORRECT_CLIENT_SECRET_MESSAGE,
"expected_message": ProviderErrors.AZURE_CLIENT_SECRET_INCORRECT_MESSAGE,
},
{
"key": ProviderErrors.AZURE_CLIENT_ERROR,
"internal_message": (
"(401) Unauthorized. Request ID: cca1a5a4-4107-4e7a-b3b4-b88f31e6a674\n"
"Code: 401\nMessage: Unauthorized. Request ID: cca1a5a4-4107-4e7a-b3b4-b88f31e6a674"
),
"expected_message": ProviderErrors.AZURE_INCORRECT_CLIENT_SECRET_MESSAGE,
"expected_message": ProviderErrors.AZURE_CLIENT_SECRET_INCORRECT_MESSAGE,
},
{
"key": ProviderErrors.AZURE_CLIENT_ERROR,
Expand Down

0 comments on commit f3d043d

Please sign in to comment.