Skip to content

Add Consumed Service field from azure raws data #105

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

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM cloudforet/python-core:2

ENV PYTHONUNBUFFERED 1
ENV SPACEONE_PORT 50051
ENV SERVER_TYPE grpc
ENV PKG_DIR /tmp/pkg
ENV SRC_DIR /tmp/src
ENV PYTHONUNBUFFERED=1
ENV SPACEONE_PORT=50051
ENV SERVER_TYPE=grpc
ENV PKG_DIR=/tmp/pkg
ENV SRC_DIR=/tmp/src

RUN apt update && apt upgrade -y

Expand All @@ -15,7 +15,7 @@ RUN pip install --upgrade pip && \

ARG CACHEBUST=1
RUN pip install --upgrade spaceone-api && \
pip install --upgrade --pre spaceone-cost-analysis==2.0.dev161
pip install --upgrade --pre spaceone-cost-analysis==2.0.dev207



Expand All @@ -27,4 +27,4 @@ RUN python3 setup.py install && \
EXPOSE ${SPACEONE_PORT}

ENTRYPOINT ["spaceone"]
CMD ["run", "plugin-server", "cloudforet.cost_analysis"]
CMD ["run", "plugin-server", "cloudforet.cost_analysis", "-w", "12"]
6 changes: 1 addition & 5 deletions src/cloudforet/cost_analysis/conf/cost_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
{"type": "Dimension", "name": "ReservationName"},
{"type": "Dimension", "name": "ChargeType"},
{"type": "Dimension", "name": "MeterCategory"},
{"type": "Dimension", "name": "ConsumedService"},
]

BENEFIT_GROUPING_MPA = [
Expand All @@ -53,11 +54,6 @@
{"type": "Dimension", "name": "TenantId"},
]

GROUPING_EA_AGREEMENT_OPTION = [
{"type": "Dimension", "name": "DepartmentName"},
{"type": "Dimension", "name": "EnrollmentAccountName"},
]

REGION_MAP = {
"global": "Global",
"unknown": "Unknown",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def query_usage_http(
"dataset": {
"granularity": GRANULARITY,
"aggregation": AGGREGATION,
"grouping": BENEFIT_GROUPING,
"filter": BENEFIT_FILTER,
},
}
Expand Down
9 changes: 9 additions & 0 deletions src/cloudforet/cost_analysis/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
from typing import Generator

from spaceone.core.error import ERROR_INVALID_PARAMETER_TYPE
from spaceone.cost_analysis.plugin.data_source.lib.server import DataSourcePluginServer

from .manager import CostManager, DataSourceManager, JobManager
Expand Down Expand Up @@ -187,6 +189,13 @@ def __remove_duplicate_list_of_dict(changed: list) -> list:
return unique_list


def __check_secret_data(secret_data: dict):
customer_tenants = secret_data.get("customer_tenants", []) or []

if not isinstance(customer_tenants, list):
raise ERROR_INVALID_PARAMETER_TYPE(key="customer_tenants", type="list")


def __get_secret_data(secret_data: dict, task_options: dict) -> dict:
secrets = secret_data.get("secrets", [secret_data])
if len(secrets) == 1:
Expand Down
33 changes: 20 additions & 13 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import time
import pandas as pd
from typing import Union, Tuple
from typing import Union, Tuple, Any, Generator
from datetime import datetime, timezone

from spaceone.core.error import *
Expand Down Expand Up @@ -321,6 +321,9 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
if result.get("metername") != "" and result.get("metername"):
additional_info["Meter Name"] = result["metername"]

if result.get("consumedservice") != "" and result.get("consumedservice"):
additional_info["Consumed Service"] = result["consumedservice"]

if result.get("term") != "" and result.get("term"):
term = result.get("term")
if isinstance(term, str):
Expand Down Expand Up @@ -424,24 +427,28 @@ def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
"Charge Type": result.get("ChargeType"),
}

if result.get("SubscriptionId"):
additional_info["Subscription Id"] = result.get("SubscriptionId")
if subscription_id := result.get("SubscriptionId"):
additional_info["Subscription Id"] = subscription_id

if result.get("CustomerName"):
additional_info["Customer Name"] = result.get("CustomerName")
if customer_name := result.get("CustomerName"):
additional_info["Customer Name"] = customer_name

if result.get("CustomerTenantId"):
additional_info["Tenant Id"] = result.get("CustomerTenantId")
if customer_id := result.get("CustomerTenantId"):
additional_info["Tenant Id"] = customer_id
elif result.get("TenantId"):
additional_info["Tenant Id"] = result.get("TenantId")

if result.get("DepartmentName"):
additional_info["Department Name"] = result.get("DepartmentName")
if department_name := result.get("DepartmentName"):
additional_info["Department Name"] = department_name

if result.get("EnrollmentAccountName"):
additional_info["Enrollment Account Name"] = result.get(
"EnrollmentAccountName"
)
if enrollment_account_name := result.get("EnrollmentAccountName"):
additional_info["Enrollment Account Name"] = enrollment_account_name

if service_family := result.get("ServiceFamily"):
additional_info["Service Family"] = service_family

if consumed_service := result.get("ConsumedService"):
additional_info["Consumed Service"] = consumed_service

usage_quantity = self._convert_str_to_float_format(
result.get("UsageQuantity", 0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"Reservation Id": {"name": "Reservation Id", "visible": False},
"Reservation Name": {"name": "Reservation Name", "visible": False},
"Service Family": {"name": "Service Family", "visible": True},
"Consumed Service": {"name": "Consumed Service", "visible": True},
"Term": {"name": "Term", "visible": False},
"Usage Type Details": {"name": "Usage Type Details", "visible": True},
"Exchange Rate": {"name": "Exchange Rate", "visible": False},
Expand Down
5 changes: 4 additions & 1 deletion src/cloudforet/cost_analysis/manager/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def get_tasks(
else:
raise ERROR_INVALID_SECRET_TYPE(secret_type=options.get("secret_type"))

_LOGGER.debug(f"[get_tasks] tasks: {tasks}")
_LOGGER.debug(f"[get_tasks] changed: {changed}")
_LOGGER.debug(f"[get_tasks] synced_accounts: {synced_accounts}")
tasks = {"tasks": tasks, "changed": changed, "synced_accounts": synced_accounts}
return tasks

Expand Down Expand Up @@ -265,7 +268,7 @@ def _get_customer_tenants(
self, secret_data: dict, linked_accounts: list = None
) -> Tuple[list, list]:
first_sync_customer_tenants = []
customer_tenants = secret_data.get(
customer_tenants: list = secret_data.get(
"customer_tenants", self._get_tenants_from_billing_account()
)
if len(customer_tenants) == 0:
Expand Down
Loading