feat(query): add billing_usage_daily table function#19784
feat(query): add billing_usage_daily table function#19784smallfish wants to merge 6 commits intodatabendlabs:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9a3c0dc727
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
6106bfe to
84b5ef8
Compare
84b5ef8 to
b89528c
Compare
bohutang
left a comment
There was a problem hiding this comment.
Thanks for the PR. I found a few design concerns from the Databend side:
- Billing should not be coupled to task-support / task config
billing_usage_daily is registered under #[cfg(feature = "task-support")] and inside if !config.task.on, and the implementation also lives in the task_support crate.
Billing usage is a cloud-control/account-level capability and does not seem task-specific. This makes the availability of billing_usage_daily depend on task-support and task server configuration, which is surprising from a Databend user/operator perspective.
Could we move this out of task_support or register it based on cloud-control/billing availability instead of the task config?
- Use typed columns instead of strings for core billing fields
The result schema exposes core billing fields as strings:
usage_dateusagerateusage_in_currency
These are expected to be queried with SQL predicates and aggregations, e.g. date filtering, ordering, SUM(usage_in_currency), etc. Returning them as String makes users cast them manually and can produce incorrect lexical ordering/filtering if they forget.
Even if the cloud-control proto keeps decimal values as strings to avoid precision loss, the query layer should convert them into Databend native types, e.g. Date for usage_date and Decimal for usage/currency fields.
- Do not mask non-permission errors as
PermissionDenied
ensure_billing_usage_privilege currently treats any error from validate_privilege as a permission denial:
if ctx
.validate_privilege(&GrantObject::Global, UserPrivilegeType::Super, false)
.await
.is_ok()
{
return Ok(());
}
Err(ErrorCode::PermissionDenied(...))This can hide non-permission failures such as invalid role state or meta-store errors and report them as PermissionDenied, which makes troubleshooting harder.
Could we match on the error code instead: return Ok(()) on success, customize only PERMISSION_DENIED, and propagate all other errors unchanged?
cc @bohutang |
…-billing-history-table-functions-clean
🤖 CI Job Analysis
📊 Summary
❌ NO RETRY NEEDEDAll failures appear to be code/test issues requiring manual fixes. 🔍 Job Details
🤖 AboutAutomated analysis using job annotations to distinguish infrastructure issues (auto-retried) from code/test issues (manual fixes needed). |
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
This PR adds a new Databend Cloud table function:
billing_usage_daily(start_date => 'YYYY-MM-DD', end_date => 'YYYY-MM-DD')It returns unified daily billing usage rows for compute, storage, and cloud services.
The table function exposes common billing fields such as usage date, usage category, service type, resource name, usage quantity, billing amount, and currency. It also includes
tagsanddetailsas JSONB-backedVariantcolumns for resource-specific metadata, so new billing categories or detail fields can be added without changing the SQL surface.rate_unitis retained as the billing dimension descriptor.rateis reserved for future use and is currently returned asNULLwhen undisclosed.This PR also adds the corresponding cloud-control gRPC billing contract and client wiring.
Example
Example output:
tags and details are abbreviated in the example.
Field Definitions
Details Examples
Notes
Tests
Type of change
This change is