Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cost (for methods cromwell), add explicit example #278

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ Cromshell is a CLI for submitting workflows to a Cromwell server and monitoring/
* Requires the `bq_cost_table` key to exist in the cromshell
configuration file and have a value equal to the BigQuery cost table
for your GCP billing project.
* For example, your `~/.cromshell/cromshell_config.json` should contain:
```json
{
"cromwell_server": "<cromwell_server_url>",
"requests_timeout": 5,
"bq_cost_table": "<table_name>"
}
```
where `<table_name>` can be found by navigating to [BigQuery](https://console.cloud.google.com/bigquery), selecting the appropriate google project, and locating the table containing cost information.

<img src="developer_docs/img/bq_cost_table.png" alt="BigQuery example image" width="500"/>

Clicking on the table and opening the "DETAILS" tab, you'll find the exact path to the table in the "Table ID" section. Everything after the google project name (after the first `.`) should be included in `<table_name>`.
* `-c/--color` Color outliers in task level cost results.
* `-d/--detailed` Get the cost for a workflow at the task level.

Expand Down
Binary file added developer_docs/img/bq_cost_table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/cromshell/cost/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ def create_bq_query(detailed: bool, bq_cost_table: str) -> str:
AND task.key LIKE "wdl-task-name"
AND wfid.key LIKE "cromwell-workflow-id"
AND wfid.value like @workflow_id
AND partition_time BETWEEN @start_date AND @end_date
AND export_time BETWEEN @start_date AND @end_date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at our cost tabe and do see this key in it, instead of the partition_time key. But I wonder why it was partition_time at the beginning, starting from the shell version. Did Google change things underneath us?

export_time is documented here, but not partition_time
https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables/detailed-usage

And confusing the situation, even more, are the two other *time values: usage_start_time and usage_end_time. And now I wonder, should we use them instead of export_time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good questions. I do remember some email about google changing things. I think this is what happened, but I can't verify it.

Not sure about usage_end_time versus export_time

GROUP BY 1,2,3
ORDER BY 4 DESC
"""
else:
return f"""
SELECT sum(cost) as cost
FROM {bq_cost_table}, UNNEST(labels)
WHERE value LIKE @workflow_id AND partition_time BETWEEN @start_date AND @end_date
WHERE value LIKE @workflow_id AND export_time BETWEEN @start_date AND @end_date
"""


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestCost:
AND task.key LIKE "wdl-task-name"
AND wfid.key LIKE "cromwell-workflow-id"
AND wfid.value like @workflow_id
AND partition_time BETWEEN @start_date AND @end_date
AND export_time BETWEEN @start_date AND @end_date
GROUP BY 1,2,3
ORDER BY 4 DESC
""",
Expand All @@ -34,7 +34,7 @@ class TestCost:
"""
SELECT sum(cost) as cost
FROM cost:table1, UNNEST(labels)
WHERE value LIKE @workflow_id AND partition_time BETWEEN @start_date AND @end_date
WHERE value LIKE @workflow_id AND export_time BETWEEN @start_date AND @end_date
""",
],
],
Expand Down
Loading