diff --git a/docs/api.rst b/docs/api.rst index d38733bc..727db5b7 100755 --- a/docs/api.rst +++ b/docs/api.rst @@ -586,3 +586,5 @@ Retrieve a cost estimate for a specific job. This will be available as soon as t update_tsv This flag specifies wether to update the cost in the tsv file that stores metrics information on the S3 bucket +force Return the estimate, even if the actual cost is available + diff --git a/docs/commands.rst b/docs/commands.rst index 18d61feb..468bbd77 100755 --- a/docs/commands.rst +++ b/docs/commands.rst @@ -591,4 +591,6 @@ This function requires a (deployed) Tibanna version >=1.0.6. -u|--update-tsv Update with the cost the tsv file that stores metrics information on the S3 bucket + -f|--force Return the estimate, even if the actual cost is available + diff --git a/docs/execution_json.rst b/docs/execution_json.rst index 8700679c..871b57d5 100755 --- a/docs/execution_json.rst +++ b/docs/execution_json.rst @@ -556,7 +556,7 @@ The ``config`` field describes execution configuration. - optional (default: unset) :ebs_throughput: - - Provisioned throughput of the gp3 type EBS (MiB/s). Must be an integer betweem 125 and 1000. + - Provisioned throughput of the gp3 type EBS (MiB/s). Must be an integer between 125 and 1000. - optional (default: unset) :ebs_type: diff --git a/tibanna/__main__.py b/tibanna/__main__.py index 5c12a8fd..5e6a61af 100755 --- a/tibanna/__main__.py +++ b/tibanna/__main__.py @@ -310,7 +310,10 @@ def args(self): 'help': "job id of the specific job to log (alternative to --exec-arn/-e)"}, {'flag': ["-u", "--update-tsv"], 'help': "update estimated cost in the metric tsv file on S3", - 'action': "store_true"}], + 'action': "store_true"}, + {'flag': ["-f", "--force"], + 'action': "store_true", + 'help': "returns the estimate, even if the actual cost is available"}], 'cleanup': [{'flag': ["-g", "--usergroup"], 'help': "Tibanna usergroup that shares the permission to access buckets and run jobs"}, @@ -475,9 +478,9 @@ def cost(job_id, sfn=TIBANNA_DEFAULT_STEP_FUNCTION_NAME, update_tsv=False): """print out cost of a specific job""" print(API().cost(job_id=job_id, sfn=sfn, update_tsv=update_tsv)) -def cost_estimate(job_id, update_tsv=False): +def cost_estimate(job_id, update_tsv=False, force=False): """print out estimated cost of a specific job""" - cost_estimate, cost_estimate_type = API().cost_estimate(job_id=job_id, update_tsv=update_tsv) + cost_estimate, cost_estimate_type = API().cost_estimate(job_id=job_id, update_tsv=update_tsv, force=force) print(f'{cost_estimate} ({cost_estimate_type})') diff --git a/tibanna/core.py b/tibanna/core.py index 4d7c269a..5b55dcca 100755 --- a/tibanna/core.py +++ b/tibanna/core.py @@ -1046,7 +1046,7 @@ def plot_metrics(self, job_id, sfn=None, directory='.', open_browser=True, force if open_browser: webbrowser.open(METRICS_URL(log_bucket, job_id)) - def cost_estimate(self, job_id, update_tsv=False): + def cost_estimate(self, job_id, update_tsv=False, force=False): postrunjsonstr = self.log(job_id=job_id, postrunjson=True) if not postrunjsonstr: logger.info("Cost estimation error: postrunjson not found") @@ -1055,12 +1055,13 @@ def cost_estimate(self, job_id, update_tsv=False): postrunjson = AwsemPostRunJson(**postrunjsonobj) log_bucket = postrunjson.config.log_bucket - # We return the real cost, if it is availble, but don't automatically update the Cost row in the tsv - precise_cost = self.cost(job_id, update_tsv=False) - if(precise_cost and precise_cost > 0.0): - if update_tsv: - update_cost_estimate_in_tsv(log_bucket, job_id, precise_cost, cost_estimate_type="actual cost") - return precise_cost, "actual cost" + # We return the real cost, if it is available, but don't automatically update the Cost row in the tsv + if not force: + precise_cost = self.cost(job_id, update_tsv=False) + if(precise_cost and precise_cost > 0.0): + if update_tsv: + update_cost_estimate_in_tsv(log_bucket, job_id, precise_cost, cost_estimate_type="actual cost") + return precise_cost, "actual cost" # awsf_image was added in 1.0.0. We use that to get the correct ebs root type ebs_root_type = 'gp3' if 'awsf_image' in postrunjsonobj['config'] else 'gp2' diff --git a/tibanna/pricing_utils.py b/tibanna/pricing_utils.py index 78549f1a..18a04b6a 100755 --- a/tibanna/pricing_utils.py +++ b/tibanna/pricing_utils.py @@ -243,7 +243,6 @@ def get_cost_estimate(postrunjson, ebs_root_type = "gp3", aws_price_overwrite = free_tier = 125 ebs_throughput_cost = ebs_throughput_price * max(cfg.ebs_throughput - free_tier, 0) * job_duration / (24.0*30.0) - print(ebs_throughput_cost) estimated_cost = estimated_cost + ebs_throughput_cost else: