Skip to content

Commit

Permalink
Merge pull request #332 from 4dn-dcic/cost_estimate_force
Browse files Browse the repository at this point in the history
Add --force to the cost_estimate command
  • Loading branch information
SooLee committed May 20, 2021
2 parents 9af7b6f + 2264304 commit 506afd8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions docs/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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


2 changes: 1 addition & 1 deletion docs/execution_json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions tibanna/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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})')


Expand Down
15 changes: 8 additions & 7 deletions tibanna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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'
Expand Down
1 change: 0 additions & 1 deletion tibanna/pricing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 506afd8

Please sign in to comment.