From cba20d8cd1d2fea7e29801122cc00baf7b474105 Mon Sep 17 00:00:00 2001 From: Giacomo Marciani Date: Mon, 15 Jul 2024 16:31:46 +0200 Subject: [PATCH] [Accounting] Fix issues that were breaking the rendering of accounting info. In particular: 1. fix the retrieval of compute nodes instance type to determine price estimate; 2. fix the generation of job properties rendered in the job accounting modal. --- api/PclusterApiHandler.py | 15 ++++++++++++++- frontend/src/old-pages/Clusters/Accounting.tsx | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/PclusterApiHandler.py b/api/PclusterApiHandler.py index 737c81e9..9d7f78f8 100644 --- a/api/PclusterApiHandler.py +++ b/api/PclusterApiHandler.py @@ -282,6 +282,16 @@ def ssm_command(region, instance_id, user, run_command): output = status["StandardOutputContent"] return output + +def _get_instance_types_for_compute_resource(compute_resource): + if "Instances" in compute_resource: + return [instance["InstanceType"] for instance in compute_resource["Instances"]] + elif "InstanceType" in compute_resource: + return [compute_resource["InstanceType"]] + else: + raise Exception("Cannot find instance types for compute resource: %s".format(compute_resource)) + + def _price_estimate(cluster_name, region, queue_name): config_text = get_cluster_config_text(cluster_name, region) config_data = yaml.safe_load(config_text) @@ -289,7 +299,10 @@ def _price_estimate(cluster_name, region, queue_name): queue = queues[queue_name] if len(queue["ComputeResources"]) == 1: - instance_type = queue["ComputeResources"][0]["InstanceType"] + instance_types = _get_instance_types_for_compute_resource(compute_resource=queue["ComputeResources"][0]) + if len(instance_types) > 1: + return {"message": "Cost estimate not available for compute resources with multiple instance types."}, 400 + instance_type = instance_types[0] pricing_filters = [ {"Field": "tenancy", "Value": "shared", "Type": "TERM_MATCH"}, {"Field": "instanceType", "Value": instance_type, "Type": "TERM_MATCH"}, diff --git a/frontend/src/old-pages/Clusters/Accounting.tsx b/frontend/src/old-pages/Clusters/Accounting.tsx index efce7392..910a218d 100644 --- a/frontend/src/old-pages/Clusters/Accounting.tsx +++ b/frontend/src/old-pages/Clusters/Accounting.tsx @@ -294,7 +294,7 @@ function JobProperties({job}: any) { {job.partition} - {getIn(job, ['exit_code', 'return_code'])} + {getIn(job, ['exit_code', 'return_code', 'number'])} { @@ -384,7 +384,7 @@ export default function ClusterAccounting() { clusterName, 'accounting', 'jobs', - ]) + ]) || [] React.useEffect(() => { refreshAccounting({}, null, true)