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

Pull request update/240905 #394

Merged
merged 3 commits into from
Sep 5, 2024
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
2 changes: 1 addition & 1 deletion diworker/diworker/importers/alibaba.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get_update_fields(self, optscale_f_incl=True):
'InstanceSpec',
'InstanceConfig'
] + self.get_cost_related_fields()
optscale_fields = ['cost']
optscale_fields = ['cost', 'report_identity']
if optscale_f_incl:
return cloud_fields + optscale_fields
else:
Expand Down
24 changes: 19 additions & 5 deletions rest_api/rest_api_server/controllers/live_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pymongo import UpdateOne

from optscale_client.config_client.client import etcd
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from sqlalchemy import and_, true

from tools.cloud_adapter.model import ResourceTypes
Expand Down Expand Up @@ -52,6 +52,8 @@
RECOMMENDATION_MULTIPLIED_FIELDS = ['saving', 'annually_monthly_saving',
'monthly_saving']
PREPARED_DEMO_LIFETIME_DAYS = 3
CLOUD_ACCOUNT_TS_OFFSET_HRS = 1
SEC_IN_HR = 60 * 60
CLICKHOUSE_TABLE_DB_MAP = {
'average_metrics': 'default',
'k8s_metrics': 'default',
Expand Down Expand Up @@ -488,6 +490,15 @@ def recover_objects(self, objects_group, preset, **kwargs):
res.append(obj)
return res

@staticmethod
def set_now_ts(keys: list, obj: dict):
date_ts = int((datetime.now(tz=timezone.utc) - timedelta(
hours=CLOUD_ACCOUNT_TS_OFFSET_HRS)).timestamp())
for key in keys:
obj.pop('%s_offset' % key, None)
obj[key] = date_ts
return obj

@staticmethod
def offsets_to_timestamps(keys, now, obj):
for key in keys:
Expand Down Expand Up @@ -590,8 +601,11 @@ def build_cloud_account(self, obj, objects_group, now,
obj['config'] = encode_config(config)
obj['organization_id'] = organization_id
obj['account_id'] = gen_id()
obj = self.offsets_to_timestamps(
['created_at', 'last_import_at'], now, obj)
obj = self.offsets_to_timestamps(['created_at'], now, obj)
obj = self.set_now_ts(
['last_import_at', 'last_import_attempt_at',
'last_import_modified_at', 'last_getting_metrics_at',
'last_getting_metric_attempt_at'], obj)
return CloudAccount(**obj)

def build_checklist(self, obj, now, organization_id, **kwargs):
Expand Down Expand Up @@ -811,10 +825,10 @@ def build_limit_hit(self, obj, now, organization_id, **kwargs):
return ConstraintLimitHit(**obj)

def build_discovery_info(self, obj, now, **kwargs):
obj = self.offsets_to_timestamps(
['created_at', 'last_discovery_at'], now, obj)
obj = self.offsets_to_timestamps(['created_at'], now, obj)
obj = self.refresh_relations(['cloud_account_id'], obj)
obj['resource_type'] = getattr(ResourceTypes, obj['resource_type'])
obj = self.set_now_ts(['last_discovery_at'], obj)
return DiscoveryInfo(**obj)

def build_node(self, obj, now, **kwargs):
Expand Down
5 changes: 4 additions & 1 deletion tools/cloud_adapter/clouds/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def _get_billing_info(self):
subscription_type = self._guess_subscription_type(
self._subscription_id)
warnings = []
usage_detail = None
try:
range_end = datetime.datetime.utcnow()
range_start = range_end - datetime.timedelta(days=DAYS_IN_MONTH)
Expand Down Expand Up @@ -481,7 +482,9 @@ def _get_billing_info(self):
else:
raise

if subscription_type == 'EnterpriseAgreement':
if (subscription_type == 'EnterpriseAgreement' and
not (getattr(usage_detail, 'cost', None) or
getattr(usage_detail, 'cost_in_billing_currency', None))):
consumption_api_supported = False

return {
Expand Down
Loading