Uploaded image for project: 'Cost Management'
  1. Cost Management
  2. COST-5288

Incorrect distributed cost when cloud and OCP currencies differ

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Normal Normal
    • 2024-Aug-09
    • None
    • Data Pipeline
    • None
    • 1
    • False
    • None
    • False

      When we have different currency for cloud data and OCP data, the distributed worker unallocated cost and distributed Platform cost is incorrect.

      Most likely this will be also the case for unattributed networking cost and we should double check it for unattributed storage cost.

      myersco  suggested that the possible cause of this could be that the worker unallocated / Platform piece is not getting the currency conversion - causing us to add an unconverted cost to a converted total cost making it appear that the cost is not fully distributed. He saw similar issue with azure storage unattributed cost.

      Most likely, this is also the root cause of COST-4979 - once we fix this issue, we  should check whether COST-4979 is also fixed

       

      In addition to the steps to reproduce described below, there is also a new IQE branch with added coverage for distribution of infra cost: cost5302_infra_cost_distribution

      branch name: cost5302_infra_cost_distribution
      tests reproducing the issue:
      AWS provider:
      - test_api_cost_model_ocp_on_aws_cost_distribution_user_projects_cpu_all
      - test_api_cost_model_ocp_on_aws_cost_distribution_user_projects_memory_all
      
      Azure provider:
      - test_api_ocp_on_azure_source_raw_calc
      
      GCP provider:
      - test_api_ocp_on_gcp_source_raw_calc
      
      COMMAND to execute them all at once:
      ENV_FOR_DYNACONF=local iqe tests plugin cost_management -k "ocp_ingest_source_ratio_ or cost_model_ocp_on_aws_cost_distribution_user_projects or ocp_on_azure_source_raw_calc or ocp_on_gcp_source_raw_calc" -vv --pdb
       
      All these tests are currently failing because of the bug -> reproducing the issue. They are passing when OCP and cloud uses the same currency - but still there could be some accidental issue in the test that was overlooked. Thus if you feel like you already fixed the bug and still see the test failure, please reach out to esebesto :)

       

      Steps to reproduce:

      1. use iqe branch: esebesto/reproducer_currency_distribution

      2. run test_api_reproduce_currency_cost_distribution_issue_worker_unallocated test

      ENV_FOR_DYNACONF=local iqe tests plugin cost_management -k "test_api_reproduce_currency_cost_distribution_issue_worker_unallocated" -vv --pdb
       

      The test will ingest:

      • OCP data for current month in USD currency with 1 user project and Worker unallocated cost
      • correlated AWS data for current month in NOK currency

      3. once ingestion finish, request OCP report grouped by project - you can filter worker unallocated project for clarity and limit the results to a single day

      http://localhost:8000/api/cost-management/v1/reports/openshift/costs/?group_by[project]=*&filter[project]=unallocated&start_date=2024-07-17&end_date=2024-07-17&limit=12345

       

      You will see that worker unallocated cost is not fully distributed and the final distributed cost is even negative (-$87052), meaning that we have distributed higher cost than we had.

       

      "cost": {
                                      "raw": {
                                          "value": 8947.409920552593,
                                          "units": "USD"
                                      },
                                      "markup": {
                                          "value": 0.0,
                                          "units": "USD"
                                      },
                                      "usage": {
                                          "value": 25.44,
                                          "units": "USD"
                                      },
                                      "platform_distributed": {
                                          "value": 0.0,
                                          "units": "USD"
                                      },
                                      "worker_unallocated_distributed": {
                                          "value": -96025.44,
                                          "units": "USD"
                                      },
                                      "storage_unattributed_distributed": {
                                          "value": 0.0,
                                          "units": "USD"
                                      },
                                      "distributed": {
                                          "value": -87052.59007944741,
                                          "units": "USD"
                                      },
                                      "total": {
                                          "value": 8972.849920552591,
                                          "units": "USD"
                                      }
                                  } 

       

      4. When you look at "worker_unallocated_distributed" value you will see that we have distributed a total of $96025.44. When we subtract usage cost of $25.44, it is exactly $96000, which actually orresponds to our infrastructure cost $8947.409920552593 converted to NOK currency (NOK currency was used for cloud provider). This means that we have distributed infrastructure cost value without applying respective currency exchange rate.

      To double check that, we can request the report in NOK currency and check the infra cost:

      http://localhost:8000/api/cost-management/v1/reports/openshift/costs/?group_by[project]=*&filter[project]=unallocated&start_date=2024-07-17&end_date=2024-07-17&limit=3456&currency=NOK 

      you will see the infrastructure cost of NOK 96000 confirming the issue

      "date": "2024-07-17",
                                  "project": "Worker unallocated",
                                  "clusters": [
                                      "test_cost_ocp_on_aws_cluster_reproducer"
                                  ],
                                  "source_uuid": [
                                      "27eddd3e-3a70-4b82-a5d5-629208485378"
                                  ],
                                  "cost_group": null,
                                  "classification": "unallocated",
                                  "infrastructure": {
                                      "raw": {
                                          "value": 96000.0,
                                          "units": "NOK"
                                      },
                                      "markup": {
                                          "value": 0.0,
                                          "units": "NOK"
                                      },
                                      "usage": {
                                          "value": 0.0,
                                          "units": "NOK"
                                      },
                                      "total": {
                                          "value": 96000.0,
                                          "units": "NOK"
                                      }
                                  }, 

       

      5. type "c" to finish the test

      6. the same holds for distribution from default (Platform) projects and Platform unallocated cost -> you can run test_api_reproduce_currency_cost_distribution_issue_platform_unallocated test if you want to try it (note that the test is a bit artificial by using user project on infra node, but that shouldn't matter for this purpose)

      ENV_FOR_DYNACONF=local iqe tests plugin cost_management -k "test_api_reproduce_currency_cost_distribution_issue_platform_unallocated" -vv --pdb
       

       

      7. to verify OCP on prem cost distribution with non-default currency, run

      ENV_FOR_DYNACONF=local iqe tests plugin cost_management -k "test_api_ocp_cost_distribution or test_api_cost_model_ocp_cost_distribution" -vv --pdb
      
      • the test should pass

            myersco Cody Myers
            rhn-support-esebesto Eva Šebestová
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: