|
| 1 | +--- |
| 2 | +layout: 'guide' |
| 3 | +menu: |
| 4 | + docs_menu: |
| 5 | + identifier: billing-and-usage-guide-dbaas-client-billing |
| 6 | + name: DBaaS Client Billing |
| 7 | + parent: billing-and-usage-guide |
| 8 | + weight: 30 |
| 9 | + home_menu: |
| 10 | + identifier: billing-and-usage-guide-dbaas-client-billing |
| 11 | + name: DBaaS Client Billing |
| 12 | + parent: home-billing |
| 13 | + weight: 30 |
| 14 | +menu_name: docs_menu |
| 15 | +section_menu: guides |
| 16 | +--- |
| 17 | + |
| 18 | +### **DBaaS Provider Billing APIs** |
| 19 | + |
| 20 | +This section is intended for DBaaS providers (self-hosted administrators) who manage the platform for end-users. To help providers monitor the resource consumption of their clients, we expose a set of APIs that deliver detailed usage reports for specific namespaces. This is particularly useful for billing, resource planning, and gaining insights into how end-users are utilizing the KubeDB resources within their assigned namespaces. |
| 21 | + |
| 22 | +#### **Prerequisites: Enabling Client Billing** |
| 23 | + |
| 24 | +Before these APIs can be used, the **Client Billing** feature must be enabled in your contract with us. This is a digital agreement that activates the necessary backend services to collect and expose usage data for your clients' namespaces from our central system. |
| 25 | + |
| 26 | +For more information on how to view or modify your contract, please refer to the [official contract management documentation](https://appscode.com/docs/en/guides/license-management/contract.html) or contact [AppsCode administrators](https://appscode.com/contact/). Once **Client Billing** is enabled in your contract, you can proceed to use the API endpoints detailed below. |
| 27 | + |
| 28 | +### **Authentication** |
| 29 | + |
| 30 | +To use these APIs, you must authenticate your requests. Usage information is collected and stored in our central system, and accessing it requires a secure token. |
| 31 | + |
| 32 | +1. **Generate an Access Token:** Create a user-scoped API token from your account. |
| 33 | + - Go to User Settings and open the `Tokens` tab, then click on `Generate Token`. |
| 34 | +  |
| 35 | + - Provide a token name and (optionally) an expiry, then click on `Generate`. |
| 36 | +  |
| 37 | + - Copy the token and store it securely. It’s shown only once. |
| 38 | +  |
| 39 | +2. **Use as a Bearer Token:** This token must be included in the Authorization header of your API requests as a Bearer token. |
| 40 | + |
| 41 | +**Example Header:** Authorization: Bearer <YOUR_ACCESS_TOKEN> |
| 42 | + |
| 43 | +**Note:** Treat this access token as a confidential credential. Do not expose it in client-side code or public repositories. |
| 44 | + |
| 45 | +### **Information Available for Client-Side Billing** |
| 46 | + |
| 47 | +The billing reports expose the following information for use in customer invoicing and internal chargeback. This section describes what you can expect to see; the next section explains how to query it via APIs. |
| 48 | + |
| 49 | +1) Namespace Level |
| 50 | + - **Database Information:** Identifies the type of database deployed in each namespace (for example, MongoDB, PostgreSQL, MySQL), along with the database name as visible to the platform. |
| 51 | + |
| 52 | +2) Database Level |
| 53 | + - **Pod Details:** |
| 54 | + - **Flavor:** CPU and Memory allocation for each pod. |
| 55 | + - **Age of Pod:** Duration since pod creation. |
| 56 | + - **Number of Pods:** Total pod count, including autoscaling pods. |
| 57 | + - Volume Details: |
| 58 | + - **Volume Name:** Name of the persistent volume. |
| 59 | + - **Initial Size:** Initial size of the volume at creation. |
| 60 | + - **Expanded Sizes:** Any volume size increases, including the size and timestamp of each expansion. |
| 61 | + - **Volume Created At:** Timestamp when the volume was created. |
| 62 | + - **Volume Age:** Duration since the volume was created. |
| 63 | + - **Volume Expansion History:** Record of any expansion events, with size and timestamp. |
| 64 | + - **Volume Deleted At:** Timestamp when the volume was deleted (if applicable). |
| 65 | + |
| 66 | +**Notes:** Timestamps are reported in UNIX time. Sizes are returned as strings with Gi units (for example, '10Gi'). |
| 67 | + |
| 68 | +### **API Endpoints** |
| 69 | + |
| 70 | +The following APIs are available to retrieve billing and usage reports. |
| 71 | + |
| 72 | +#### **1. Get Usage Reports for All Namespaces** |
| 73 | + |
| 74 | +This endpoint retrieves a consolidated usage report for all namespaces that are bound to your client organizations. It is ideal for generating auditing reports and getting a high-level overview of resource consumption. |
| 75 | + |
| 76 | +* **Endpoint:** |
| 77 | +> GET https://appscode.com/api/v1/dbaas/billing/reports/namespaces |
| 78 | +* **Description:** Returns a list of usage reports, with each report corresponding to a namespace managed under your DBaaS platform. This endpoint is particularly useful for auditing, billing reconciliation, and high‑level usage analysis. |
| 79 | +* **Query Parameters:** |
| 80 | + * **org** (string, optional): The organization name in the central **appscode.com** platform that owns your billing contract and receives usage from your self-hosted installation. The authenticated user must be a member of this organization. Use this to restrict results to namespaces reported under that org. |
| 81 | +* **Limitations:** |
| 82 | + * The current implementation does not support pagination. As a result, the endpoint returns all available namespaces, which may lead to large response sizes over time. |
| 83 | + * Resources (including namespaces, pods, and volumes) that were deleted more than six months ago are automatically excluded from the response. |
| 84 | +* **Example Response:** The response will contain a list of namespace reports. Each report includes cluster information, namespace details, and a breakdown of the databases running within that namespace. Please see the [Additional Resources](#additional-resources) section below for detailed response schema and example. |
| 85 | + |
| 86 | +#### **2. Get Usage Report for a Specific Namespace** |
| 87 | + |
| 88 | +This endpoint allows you to drill down and retrieve a detailed usage report for a single, specific namespace within a given cluster. This is useful for generating invoices or analyzing the consumption of a particular client. |
| 89 | + |
| 90 | +* **Endpoint:** |
| 91 | +> GET https://appscode.com/api/v1/dbaas/billing/reports/clusters/{clusterID}/namespaces/{namespace} |
| 92 | +* **Description:** Returns a detailed usage report for the specified namespace, including information about the cluster, the namespace itself, and all KubeDB resources deployed within it. |
| 93 | +* **Path Parameters:** |
| 94 | + * **clusterID** (string, required): The unique identifier of the spoke cluster where the namespace is located. |
| 95 | + * **namespace** (string, required): The name of the namespace for which the report is being requested. |
| 96 | +* **Query Parameters:** |
| 97 | + * **org** (string, optional): The organization name in the central **appscode.com** platform that owns your billing contract and to which your self-hosted app reports usage. The authenticated user must be a member of this organization. Provide the org created for your DBaaS customer to target the correct data. |
| 98 | +* **Cautions:** |
| 99 | + * The namespace name provided in the path should be unique within the specified cluster, or unique across all clusters if you need to ensure you are targeting the correct one. |
| 100 | + * In the self-hosted platform, each **client organization** (client-org) name must be unique because the DBaaS namespace is created with exactly the same name as that client-org. This one-to-one mapping means duplicate client-org names will cause namespace conflicts. |
| 101 | + * You can optionally add an annotation to the namespace to tag the downstream end-user (for example, a customer ID or external reference) so you can map reports back to your own user records. |
| 102 | +* **Response Breakdown:** The JSON response for a single namespace provides granular details: |
| 103 | + * **clusterInfo**: Contains metadata about the cluster, such as its name, Kubernetes version, provider, and resource capacity. |
| 104 | + * **namespaceInfo**: Includes the namespace's labels, annotations, and creation timestamp. |
| 105 | + * **databases**: An array of objects, where each object represents a KubeDB instance and contains: |
| 106 | + * **databaseInfo**: Basic details like the database kind, product, and resource name. |
| 107 | + * **podDetails**: Information about the pods, including CPU and memory resources allocated. |
| 108 | + * **volumeDetails**: Details about the persistent volumes, including their initial size and any expansion history. |
| 109 | + |
| 110 | +For full field-by-field schemas, sample payloads, and screenshots, see the [Additional Resources](#additional-resources) section below. |
| 111 | + |
| 112 | +### **General API Cautions** |
| 113 | + |
| 114 | +- **Time Format:** All time-related values in the API responses (e.g., createdAt, lastReceivedAt) are represented in the **UNIX time format**. |
| 115 | +- **Data Retention:** The API response does not include resources (namespaces, pods, volumes, etc.) that were deleted more than **six months ago**. |
| 116 | + |
| 117 | +### **Additional Resources** |
| 118 | +- **Document Files:** For related document files, please access the following shared drive: [DBaaS Billing API Documents](https://drive.google.com/drive/u/1/folders/14ccceVuJQCKLvi9iSswnz86LqvB3Dfeq) |
0 commit comments