Skip to content

Commit 6be0feb

Browse files
1101-1aquamatthias
andauthored
[azure][feat] Add machine learning resources collection (#2174)
Co-authored-by: Matthias Veit <matthias_veit@yahoo.de> Co-authored-by: Matthias Veit <aquamatthias@users.noreply.github.com>
1 parent 70cee4c commit 6be0feb

32 files changed

+3991
-8
lines changed

plugins/azure/fix_plugin_azure/azure_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def is_retryable_exception(e: Exception) -> bool:
4343
return True
4444
if isinstance(e, HttpResponseError):
4545
error_code = getattr(e.error, "code", None)
46-
status_code = getattr(e.response, "status_code", None)
46+
status_code = getattr(e, "status_code", None)
4747

4848
if error_code == "TooManyRequests" or status_code == 429:
4949
log.debug(f"Azure API request limit exceeded or throttling, retrying with exponential backoff: {e}")

plugins/azure/fix_plugin_azure/collector.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
)
5050
from fix_plugin_azure.resource.storage import AzureStorageAccountUsage, AzureStorageSku, resources as storage_resources
5151
from fix_plugin_azure.resource.web import resources as web_resources
52+
from fix_plugin_azure.resource.machinelearning import (
53+
AzureMachineLearningUsage,
54+
AzureMachineLearningVirtualMachineSize,
55+
resources as ml_resources,
56+
)
5257
from fixlib.baseresources import Cloud, GraphRoot, BaseAccount, BaseRegion
5358
from fixlib.core.actions import CoreFeedback, ErrorAccumulator
5459
from fixlib.graph import Graph
@@ -80,6 +85,7 @@ def resource_with_params(clazz: Type[MicrosoftResource], param: str) -> bool:
8085
+ sql_resources
8186
+ storage_resources
8287
+ web_resources
88+
+ ml_resources
8389
)
8490
all_resources = subscription_resources + graph_resources # defines all resource kinds. used in model check
8591

@@ -241,7 +247,7 @@ def rm_nodes(cls, ignore_kinds: Optional[Type[Any]] = None, check_pred: bool = T
241247

242248
def remove_usage_zero_value() -> None:
243249
for node in self.graph.nodes:
244-
if not isinstance(node, (AzureNetworkUsage, AzureStorageAccountUsage)):
250+
if not isinstance(node, (AzureNetworkUsage, AzureStorageAccountUsage, AzureMachineLearningUsage)):
245251
continue
246252
# Azure Usage just keep info about how many kind of resources on account exists
247253
# Check if the current usage value of the Azure Usage node is 0
@@ -254,6 +260,7 @@ def remove_usage_zero_value() -> None:
254260
rm_nodes(AzureExpressRoutePortsLocation, AzureSubscription)
255261
rm_nodes(AzureNetworkVirtualApplianceSku, AzureSubscription)
256262
rm_nodes(AzureDiskType, AzureSubscription)
263+
rm_nodes(AzureMachineLearningVirtualMachineSize, AzureLocation)
257264
rm_nodes(AzureStorageSku, AzureLocation)
258265
rm_nodes(AzureMysqlServerType, AzureSubscription)
259266
rm_nodes(AzurePostgresqlServerType, AzureSubscription)

plugins/azure/fix_plugin_azure/resource/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ class AzureTrackedResource:
611611
"location": S("location"),
612612
"system_data": S("systemData") >> Bend(AzureSystemData.mapping),
613613
"type": S("type"),
614+
"ctime": S("systemData", "createdAt"),
615+
"mtime": S("systemData", "lastModifiedAt"),
614616
}
615617
location: Optional[str] = field(default=None, metadata={'description': 'The geo-location where the resource lives'}) # fmt: skip
616618
system_data: Optional[AzureSystemData] = field(default=None, metadata={'description': 'Metadata pertaining to creation and last modification of the resource.'}) # fmt: skip
@@ -623,6 +625,8 @@ class AzureProxyResource:
623625
mapping: ClassVar[Dict[str, Bender]] = {
624626
"system_data": S("systemData") >> Bend(AzureSystemData.mapping),
625627
"type": S("type"),
628+
"ctime": S("systemData", "createdAt"),
629+
"mtime": S("systemData", "lastModifiedAt"),
626630
}
627631
system_data: Optional[AzureSystemData] = field(default=None, metadata={'description': 'Metadata pertaining to creation and last modification of the resource.'}) # fmt: skip
628632
type: Optional[str] = field(default=None, metadata={'description': 'The type of the resource. E.g. Microsoft.Compute/virtualMachines or Microsoft.Storage/storageAccounts '}) # fmt: skip
@@ -828,9 +832,9 @@ def add_node(self, node: MicrosoftResourceType, source: Optional[Json] = None) -
828832
# add edge from location to resource
829833
if self.location:
830834
last_edge_key = self.add_edge(self.location, node=node)
831-
elif source and "location" in source:
835+
elif (source) and (source_location := source.get("location")):
832836
# reference the location node if available
833-
if location := self.location_lookup.get(source["location"]):
837+
if location := self.location_lookup.get(source_location):
834838
node._region = location
835839
last_edge_key = self.add_edge(location, node=node)
836840
if source and "locations" in source:

0 commit comments

Comments
 (0)