Skip to content

Commit 506afd8

Browse files
authored
Merge pull request #332 from 4dn-dcic/cost_estimate_force
Add --force to the cost_estimate command
2 parents 9af7b6f + 2264304 commit 506afd8

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

docs/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,3 +586,5 @@ Retrieve a cost estimate for a specific job. This will be available as soon as t
586586
update_tsv This flag specifies wether to update the cost in the tsv file that
587587
stores metrics information on the S3 bucket
588588

589+
force Return the estimate, even if the actual cost is available
590+

docs/commands.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,4 +591,6 @@ This function requires a (deployed) Tibanna version >=1.0.6.
591591
-u|--update-tsv Update with the cost the tsv file that stores metrics
592592
information on the S3 bucket
593593

594+
-f|--force Return the estimate, even if the actual cost is available
595+
594596

docs/execution_json.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ The ``config`` field describes execution configuration.
556556
- optional (default: unset)
557557

558558
:ebs_throughput:
559-
- Provisioned throughput of the gp3 type EBS (MiB/s). Must be an integer betweem 125 and 1000.
559+
- Provisioned throughput of the gp3 type EBS (MiB/s). Must be an integer between 125 and 1000.
560560
- optional (default: unset)
561561

562562
:ebs_type:

tibanna/__main__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ def args(self):
310310
'help': "job id of the specific job to log (alternative to --exec-arn/-e)"},
311311
{'flag': ["-u", "--update-tsv"],
312312
'help': "update estimated cost in the metric tsv file on S3",
313-
'action': "store_true"}],
313+
'action': "store_true"},
314+
{'flag': ["-f", "--force"],
315+
'action': "store_true",
316+
'help': "returns the estimate, even if the actual cost is available"}],
314317
'cleanup':
315318
[{'flag': ["-g", "--usergroup"],
316319
'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):
475478
"""print out cost of a specific job"""
476479
print(API().cost(job_id=job_id, sfn=sfn, update_tsv=update_tsv))
477480

478-
def cost_estimate(job_id, update_tsv=False):
481+
def cost_estimate(job_id, update_tsv=False, force=False):
479482
"""print out estimated cost of a specific job"""
480-
cost_estimate, cost_estimate_type = API().cost_estimate(job_id=job_id, update_tsv=update_tsv)
483+
cost_estimate, cost_estimate_type = API().cost_estimate(job_id=job_id, update_tsv=update_tsv, force=force)
481484
print(f'{cost_estimate} ({cost_estimate_type})')
482485

483486

tibanna/core.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def plot_metrics(self, job_id, sfn=None, directory='.', open_browser=True, force
10461046
if open_browser:
10471047
webbrowser.open(METRICS_URL(log_bucket, job_id))
10481048

1049-
def cost_estimate(self, job_id, update_tsv=False):
1049+
def cost_estimate(self, job_id, update_tsv=False, force=False):
10501050
postrunjsonstr = self.log(job_id=job_id, postrunjson=True)
10511051
if not postrunjsonstr:
10521052
logger.info("Cost estimation error: postrunjson not found")
@@ -1055,12 +1055,13 @@ def cost_estimate(self, job_id, update_tsv=False):
10551055
postrunjson = AwsemPostRunJson(**postrunjsonobj)
10561056
log_bucket = postrunjson.config.log_bucket
10571057

1058-
# We return the real cost, if it is availble, but don't automatically update the Cost row in the tsv
1059-
precise_cost = self.cost(job_id, update_tsv=False)
1060-
if(precise_cost and precise_cost > 0.0):
1061-
if update_tsv:
1062-
update_cost_estimate_in_tsv(log_bucket, job_id, precise_cost, cost_estimate_type="actual cost")
1063-
return precise_cost, "actual cost"
1058+
# We return the real cost, if it is available, but don't automatically update the Cost row in the tsv
1059+
if not force:
1060+
precise_cost = self.cost(job_id, update_tsv=False)
1061+
if(precise_cost and precise_cost > 0.0):
1062+
if update_tsv:
1063+
update_cost_estimate_in_tsv(log_bucket, job_id, precise_cost, cost_estimate_type="actual cost")
1064+
return precise_cost, "actual cost"
10641065

10651066
# awsf_image was added in 1.0.0. We use that to get the correct ebs root type
10661067
ebs_root_type = 'gp3' if 'awsf_image' in postrunjsonobj['config'] else 'gp2'

tibanna/pricing_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ def get_cost_estimate(postrunjson, ebs_root_type = "gp3", aws_price_overwrite =
243243

244244
free_tier = 125
245245
ebs_throughput_cost = ebs_throughput_price * max(cfg.ebs_throughput - free_tier, 0) * job_duration / (24.0*30.0)
246-
print(ebs_throughput_cost)
247246
estimated_cost = estimated_cost + ebs_throughput_cost
248247

249248
else:

0 commit comments

Comments
 (0)