Skip to content

Commit a528e23

Browse files
authored
Pull request update/250129
1ce46d9 OSN-584. Handle 409 on create arcee token f773a09 OSN-506. Added missing region + fixed logging 060e20c OSN-172. Improved getting regions from Alibaba expenses
2 parents c968560 + 1ce46d9 commit a528e23

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

diworker/diworker/importers/azure.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"AE North": "UAE North",
2121
"US East 2": "East US 2",
2222
"EU North": "North Europe",
23+
"IN Central": "Central India",
2324
"NorthCentralUs": "North Central US",
2425
"SouthCentralUS": "South Central US",
2526
"WestUS": "West US",
@@ -413,8 +414,10 @@ def get_resource_info_from_expenses(self, expenses):
413414
else:
414415
region = None
415416
if region_set:
416-
LOG.warning('Unable to find regions %s in map', region_set)
417417
region = region_set.pop()
418+
if region not in regions_map.values():
419+
LOG.warning('Unable to find regions %s in map',
420+
region_set)
418421
tags = self.extract_tags(expenses[-1].get('tags', {}))
419422
service = expenses[-1].get('consumed_service')
420423

rest_api/rest_api_server/handlers/v2/profiling/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import hashlib
2+
from requests.exceptions import HTTPError
23
from tools.optscale_exceptions.http_exc import OptHTTPError
34
from rest_api.rest_api_server.exceptions import Err
45
from rest_api.rest_api_server.utils import run_task
@@ -7,8 +8,13 @@
78

89
class ProfilingHandler(BaseHandler):
910
async def _get_profiling_token(self, organization_id):
10-
res = await run_task(
11-
self.controller.get_profiling_token, organization_id)
11+
try:
12+
res = await run_task(
13+
self.controller.get_profiling_token, organization_id)
14+
except HTTPError as ex:
15+
if ex.response.status_code == 409:
16+
raise OptHTTPError(409, Err.OE0526, [organization_id])
17+
raise
1218
return res
1319

1420
async def check_md5_profiling_token(

tools/cloud_adapter/clouds/azure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,8 @@ def _get_coordinates_map(self):
11591159
'name': 'North Europe', 'alias': 'Europe',
11601160
'longitude': -6.2597, 'latitude': 53.3478},
11611161
'uksouth': {
1162-
'name': 'UK South', 'longitude': -0.799, 'latitude': 50.941},
1162+
'name': 'UK South',
1163+
'longitude': -0.799, 'latitude': 50.941},
11631164
'eastus': {
11641165
'name': 'East US', 'alias': 'US East',
11651166
'longitude': -79.8164, 'latitude': 37.3719},

trapper/trapper_worker/processor.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,43 @@ class AlibabaTrafficExpenseProcessor(BaseTrafficExpenseProcessor):
233233
]
234234

235235
@staticmethod
236-
def extract_locations_and_usage(e):
237-
_from = e.get('Zone') or e.get('Region') or 'Unknown'
236+
def _zone_to_region(zone):
237+
"""
238+
Converts zone name from expenses to region name.
239+
240+
Examples:
241+
ap-southeast-5a -> ap-southeast-5
242+
eu-central-a -> eu-central-1
243+
cn-beijing-f -> cn-beijing
244+
245+
:param zone: (str) zone name
246+
:return: (str) region name or zone name
247+
"""
248+
parts = zone.split("-")
249+
if len(parts) == 3 and parts[0] == "cn":
250+
zone = "-".join(parts[:2])
251+
elif len(parts) >= 3 and parts[0] != "cn":
252+
# region name should ends with integer, ex.: eu-central-1
253+
last = parts.pop(-1)
254+
try:
255+
int(last)
256+
except ValueError:
257+
# try to get region number from the last part
258+
number = ''.join(x for x in last if x.isdigit())
259+
if not number:
260+
# fix region name for zones without number, ex.:
261+
# eu-central-a -> eu-central-1
262+
number = "1"
263+
parts.append(number)
264+
zone = "-".join(parts)
265+
return zone
266+
267+
def extract_locations_and_usage(self, e):
268+
zone = e.get('Zone')
269+
region = e.get('Region')
270+
if not region and zone:
271+
zone = self._zone_to_region(zone)
272+
_from = region or zone or 'Unknown'
238273
_to = 'Unknown' if e.get('InternetIP') else 'External'
239274
_usage = float(e.get('Usage') or 0)
240275
return _from, _to, _usage

0 commit comments

Comments
 (0)