Skip to content

Commit

Permalink
Add Python dependencies, format constants, extend help text
Browse files Browse the repository at this point in the history
  • Loading branch information
ahenroid committed Feb 14, 2024
1 parent dd9c1a4 commit 16014f6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
34 changes: 18 additions & 16 deletions omics/analyzer/omics-run-analyzer
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Options:
Examples:
# Show workflow runs that were running in the last 5 days
omics-run-analyzer -t5d
# (supported time units include minutes, hours, days, weeks, or years)
omics-run-analyzer --time=5days
# Retrieve and analyze a specific workflow run by ID
omics-run-analyzer 1234567 -o run-1234567.csv
# Retrieve and analyze a specific workflow run by ID and UUID
Expand All @@ -44,9 +45,10 @@ import dateutil
import docopt

exename = os.path.basename(sys.argv[0])
omics_log_group = "/aws/omics/WorkflowLog"
omics_service_code = "AmazonOmics"
pricing_aws_region = "us-east-1" # Pricing service endpoint
OMICS_LOG_GROUP = "/aws/omics/WorkflowLog"
OMICS_SERVICE_CODE = "AmazonOmics"
PRICING_AWS_REGION = "us-east-1" # Pricing service endpoint
SECS_PER_HOUR = 3600.0


def die(msg):
Expand All @@ -62,10 +64,10 @@ def parse_time_str(s, utc=True):

def parse_time_delta(s):
"""Parse time delta string"""
m = re.match(r"(\d+)\s*(m|min|minutes?|h|hours?|d|days?|w|weeks?)$", s)
m = re.match(r"(\d+)\s*(m|min|minutes?|h|hours?|d|days?|w|weeks?|y|years?)$", s)
if not m:
die("unrecognized time interval format '{}'".format(s))
secs = {"m": 60, "h": 3600, "d": 86400, "w": 604800}
secs = {"m": 60, "h": 3600, "d": 86400, "w": 604800, "y": 220752000}
delta = int(m.group(1)) * secs[m.group(2)[0]]
return datetime.timedelta(seconds=delta)

Expand Down Expand Up @@ -116,7 +118,7 @@ def get_pricing(pricing, resource, region, hours):
{"Type": "TERM_MATCH", "Field": "resourceType", "Value": resource},
{"Type": "TERM_MATCH", "Field": "regionCode", "Value": region},
]
rqst = {"ServiceCode": omics_service_code, "Filters": filters}
rqst = {"ServiceCode": OMICS_SERVICE_CODE, "Filters": filters}
for page in pricing.get_paginator("get_products").paginate(**rqst):
for item in page["PriceList"]:
entry = json.loads(item)
Expand Down Expand Up @@ -176,7 +178,7 @@ def get_runs(logs, runs, opts):
else:
prefix = f"manifest/run/{run[-1]}/"
rqst = {
"logGroupName": omics_log_group,
"logGroupName": OMICS_LOG_GROUP,
"logStreamNamePrefix": prefix,
}
streams.extend(get_streams(logs, rqst))
Expand All @@ -185,7 +187,7 @@ def get_runs(logs, runs, opts):
start_time = datetime.datetime.now() - parse_time_delta(opts["--time"])
start_time = start_time.timestamp() * 1000.0
rqst = {
"logGroupName": omics_log_group,
"logGroupName": OMICS_LOG_GROUP,
"orderBy": "LastEventTime",
"descending": True,
}
Expand All @@ -197,7 +199,7 @@ def get_runs(logs, runs, opts):
def get_run_resources(logs, run):
"""Get workflow run/task details"""
rqst = {
"logGroupName": omics_log_group,
"logGroupName": OMICS_LOG_GROUP,
"logStreamName": run["logStreamName"],
"startFromHead": True,
}
Expand Down Expand Up @@ -317,27 +319,27 @@ def add_metrics(res, resources, pricing):
if rtype == "run":
capacity = get_storage_gib(res.get("storageCapacity"))
metrics["sizeReserved"] = f"{capacity} GiB"
gib_hrs = capacity * running / 3600.0
gib_hrs = capacity * running / SECS_PER_HOUR
price = get_pricing(pricing, "Run Storage", region, gib_hrs)
if price:
metrics["estimatedUSD"] = price
if store_max:
capacity = get_storage_gib(store_max)
metrics["sizeMinimum"] = f"{capacity} GiB"
gib_hrs = capacity * running / 3600.0
gib_hrs = capacity * running / SECS_PER_HOUR
price = get_pricing(pricing, "Run Storage", region, gib_hrs)
if price:
metrics["minimumUSD"] = price
elif "instanceType" in res:
itype = res["instanceType"]
metrics["sizeReserved"] = itype
price = get_pricing(pricing, itype, region, running / 3600.0)
price = get_pricing(pricing, itype, region, running / SECS_PER_HOUR)
if price:
metrics["estimatedUSD"] = price
if cpus_max and mem_max and not gpus_res:
itype = get_instance(cpus_max, mem_max)
metrics["sizeMinimum"] = itype
price = get_pricing(pricing, itype, region, running / 3600.0)
price = get_pricing(pricing, itype, region, running / SECS_PER_HOUR)
if price:
metrics["minimumUSD"] = price

Expand Down Expand Up @@ -370,8 +372,8 @@ if __name__ == "__main__":
session = boto3.Session(
profile_name=opts["--profile"], region_name=opts["--region"]
)
pricing = session.client("pricing", region_name=pricing_aws_region)
pricing.describe_services(ServiceCode=omics_service_code)
pricing = session.client("pricing", region_name=PRICING_AWS_REGION)
pricing.describe_services(ServiceCode=OMICS_SERVICE_CODE)
except Exception as e:
die(e)

Expand Down
14 changes: 12 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ s3transfer = "^0.7.0"
boto3 = "^1.28.83"
mypy-boto3-omics = "^1.28.83"
botocore-stubs = "^1.31.83"
docopt = "^0.6.2"
python-dateutil = "^2.8.2"

[tool.poetry.group.dev.dependencies]
black = "^22.8.0"
Expand Down

0 comments on commit 16014f6

Please sign in to comment.