1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ use std:: collections:: BTreeMap ;
16+
1517use databend_common_base:: runtime;
1618use databend_common_cloud_control:: billing_client:: BillingClient ;
17- use databend_common_cloud_control:: pb:: BillingHistoryDailyRow ;
18- use databend_common_cloud_control:: pb:: BillingHistoryWarehouseDailyRow ;
19- use databend_common_cloud_control:: pb:: GetBillingHistoryDailyRequest ;
20- use databend_common_cloud_control:: pb:: GetBillingHistoryDailyResponse ;
21- use databend_common_cloud_control:: pb:: GetBillingHistoryWarehouseDailyRequest ;
22- use databend_common_cloud_control:: pb:: GetBillingHistoryWarehouseDailyResponse ;
19+ use databend_common_cloud_control:: pb:: BillingUsageDailyRow ;
20+ use databend_common_cloud_control:: pb:: GetBillingUsageDailyRequest ;
21+ use databend_common_cloud_control:: pb:: GetBillingUsageDailyResponse ;
2322use databend_common_cloud_control:: pb:: billing_service_server:: BillingService ;
2423use databend_common_cloud_control:: pb:: billing_service_server:: BillingServiceServer ;
2524use hyper_util:: rt:: TokioIo ;
@@ -37,27 +36,24 @@ pub struct MockBillingService {}
3736
3837#[ tonic:: async_trait]
3938impl BillingService for MockBillingService {
40- async fn get_billing_history_daily (
41- & self ,
42- request : Request < GetBillingHistoryDailyRequest > ,
43- ) -> std:: result:: Result < Response < GetBillingHistoryDailyResponse > , Status > {
44- Ok ( Response :: new ( GetBillingHistoryDailyResponse {
45- rows : vec ! [ BillingHistoryDailyRow {
46- date: request. into_inner( ) . billing_month,
47- ..Default :: default ( )
48- } ] ,
49- error : None ,
50- } ) )
51- }
52-
53- async fn get_billing_history_warehouse_daily (
39+ async fn get_billing_usage_daily (
5440 & self ,
55- request : Request < GetBillingHistoryWarehouseDailyRequest > ,
56- ) -> std:: result:: Result < Response < GetBillingHistoryWarehouseDailyResponse > , Status > {
57- Ok ( Response :: new ( GetBillingHistoryWarehouseDailyResponse {
58- rows : vec ! [ BillingHistoryWarehouseDailyRow {
59- warehouse_name: request. into_inner( ) . billing_month,
60- ..Default :: default ( )
41+ request : Request < GetBillingUsageDailyRequest > ,
42+ ) -> std:: result:: Result < Response < GetBillingUsageDailyResponse > , Status > {
43+ Ok ( Response :: new ( GetBillingUsageDailyResponse {
44+ rows : vec ! [ BillingUsageDailyRow {
45+ usage_date: request. into_inner( ) . billing_month,
46+ usage_type: "compute" . to_string( ) ,
47+ service_type: "WAREHOUSE_METERING" . to_string( ) ,
48+ resource_name: "default" . to_string( ) ,
49+ usage: "2653" . to_string( ) ,
50+ usage_unit: "second" . to_string( ) ,
51+ rate: "0.0002777777777778" . to_string( ) ,
52+ rate_unit: "second" . to_string( ) ,
53+ usage_in_currency: "0.737" . to_string( ) ,
54+ currency: "USD" . to_string( ) ,
55+ tags: BTreeMap :: from( [ ( "env" . to_string( ) , "test" . to_string( ) ) ] ) ,
56+ details: "{\" cluster_name\" :\" cl-00000\" }" . to_string( ) ,
6157 } ] ,
6258 error : None ,
6359 } ) )
@@ -95,27 +91,18 @@ async fn test_billing_client_success_cases() -> anyhow::Result<()> {
9591
9692 let client = BillingClient :: new ( channel) . await ?;
9793
98- let daily_resp = client
99- . get_billing_history_daily ( Request :: new ( GetBillingHistoryDailyRequest {
94+ let resp = client
95+ . get_billing_usage_daily ( Request :: new ( GetBillingUsageDailyRequest {
10096 tenant_id : "tenant" . to_string ( ) ,
10197 billing_month : "2026-03" . to_string ( ) ,
10298 sql_user : "root" . to_string ( ) ,
10399 query_id : "query-1" . to_string ( ) ,
104100 } ) )
105101 . await ?;
106- assert_eq ! ( daily_resp. rows. len( ) , 1 ) ;
107- assert_eq ! ( daily_resp. rows[ 0 ] . date, "2026-03" ) ;
108-
109- let warehouse_resp = client
110- . get_billing_history_warehouse_daily ( Request :: new ( GetBillingHistoryWarehouseDailyRequest {
111- tenant_id : "tenant" . to_string ( ) ,
112- billing_month : "2026-04" . to_string ( ) ,
113- sql_user : "root" . to_string ( ) ,
114- query_id : "query-2" . to_string ( ) ,
115- } ) )
116- . await ?;
117- assert_eq ! ( warehouse_resp. rows. len( ) , 1 ) ;
118- assert_eq ! ( warehouse_resp. rows[ 0 ] . warehouse_name, "2026-04" ) ;
102+ assert_eq ! ( resp. rows. len( ) , 1 ) ;
103+ assert_eq ! ( resp. rows[ 0 ] . usage_date, "2026-03" ) ;
104+ assert_eq ! ( resp. rows[ 0 ] . usage_type, "compute" ) ;
105+ assert_eq ! ( resp. rows[ 0 ] . resource_name, "default" ) ;
119106
120107 Ok ( ( ) )
121108}
0 commit comments