:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): add chargebee meters and credit units tables (#113209)
Tom Owers8f9601cf0f8a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 65002a080f4e..83703345705c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -1326,6 +1326,17 @@ Diffed against: <https://developers.chameleon.io/apis/overview.md>Note: Chameleon's published OpenAPI at developers.chameleon.io/api-reference/openapi.json is a stub (it documents a /plants toy API), so the authoritative endpoint table is the markdown overview page. Alert groups, rate limit groups, webhooks, domains and data imports were excluded as config/plumbing. Embeddables, Product Demos and Changes have doc pages in llms.txt but do not appear in the overview endpoint table, so no list endpoint could be confirmed for them - they are not reported as gaps.+## Chargebee — gaps++Today (10): `CreditUnits`, `Customers`, `Events`, `Invoices`, `ItemPrices`, `Items`, `Meters`, `Orders`, `Subscriptions`, `Transactions`++Diffed against: <https://raw.githubusercontent.com/chargebee/openapi/main/spec/chargebee_api_v2_pc_v2_spec.json>++- [x] `GET /meters` — usage-based billing meters: how usage of each metered feature is measured (medium)+- [x] `GET /credit_units` — credit unit definitions that credit-based billing grants and consumes (medium)++Note: `metered_features` has only write endpoints (create, archive, reactivate, delete) and no list endpoint; the same configuration is readable through `GET /meters`, whose `id` equals the feature id. `ledger_entries` is a documented resource with no list endpoint. The credit ledger is listable through `GET /ledger_operations`.+## Chargedesk — gapsToday (7): `activity_log`, `charge_items`, `charges`, `customers`, `products`, `subscription_cancellations`, `subscriptions`diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/canonical_descriptions.pyindex 1ba8f4a3de7a..6da092651bc6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/canonical_descriptions.py@@ -23,6 +23,20 @@ def _columns(**overrides: str) -> dict[str, str]:CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {+ "CreditUnits": {+ "description": "A credit unit for credit-based billing: a consumption unit, such as AI credits or API calls, that customers prepay and then spend as they use features.",+ "docs_url": "https://apidocs.chargebee.com/docs/api/credit_units",+ "columns": _columns(+ name="Internal display name for the credit unit, unique across the site.",+ external_name="Customer-facing display name for the credit unit, unique across the site.",+ status="Lifecycle status of the credit unit: active or archived.",+ is_unlimited="Whether the credit unit allows unlimited overdraft consumption after the allocated grants run out.",+ overdraft_amount="Amount of overdraft consumption allowed after the allocated grants run out, as a decimal string. Applies only when is_unlimited is false.",+ created_by="Source or user that created the credit unit.",+ updated_by="Source or user that last updated the credit unit.",+ resource_version="Version number that increments whenever the credit unit is modified, as a Unix timestamp in milliseconds.",+ ),+ },"Customers": {"description": "A Chargebee customer, who owns subscriptions, invoices, and payment methods.","docs_url": "https://apidocs.chargebee.com/docs/api/customers",@@ -130,6 +144,20 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {deleted="Whether the item has been deleted.",),},+ "Meters": {+ "description": "A meter that defines how usage of a metered feature is measured from usage events, for usage-based billing.",+ "docs_url": "https://apidocs.chargebee.com/docs/api/meters",+ "columns": _columns(+ id="Unique identifier for the meter. This is the same as the identifier of its feature.",+ name="Case-sensitive name of the meter, such as 'API Calls'.",+ description="Brief description of the meter.",+ type="How usage is measured: simple (a SQL query over usage event properties) or compound (a formula that combines other meters).",+ status="Status of the meter: active, archived, or deleted.",+ query="SQL query that measures usage from usage event properties.",+ column_definitions="Definitions of the usage event columns or properties that the meter's query references.",+ features="The feature associated with the meter. This list always has one element.",+ ),+ },"Orders": {"description": "An order created from an invoice to fulfill physical or digital goods.","docs_url": "https://apidocs.chargebee.com/docs/api/orders",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/chargebee.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/chargebee.pyindex bbebba85c030..4f12ab9e44ce 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/chargebee.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/chargebee.py@@ -39,6 +39,20 @@ def get_resource(# rows, so the first unfiltered sync still advances it.apply_incremental_filter = should_use_incremental_field and db_incremental_field_last_value is not Noneresources: dict[str, EndpointResource] = {+ # Credit units and meters have no server-side timestamp filter, so they only support full refresh.+ "CreditUnits": {+ "name": "CreditUnits",+ "table_name": "credit_units",+ "write_disposition": "replace",+ "endpoint": {+ "data_selector": "list[*].credit_unit",+ "path": "/v2/credit_units",+ "params": {+ "limit": 100,+ },+ },+ "table_format": "delta",+ },"Customers": {"name": "Customers","table_name": "customers",@@ -145,6 +159,19 @@ def get_resource(},"table_format": "delta",},+ "Meters": {+ "name": "Meters",+ "table_name": "meters",+ "write_disposition": "replace",+ "endpoint": {+ "data_selector": "list[*].meter",+ "path": "/v2/meters",+ "params": {+ "limit": 100,+ },+ },+ "table_format": "delta",+ },"Orders": {"name": "Orders","table_name": "orders",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/settings.pyindex 2f7d24150f6c..fd3d9e1d4a13 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/settings.py@@ -1,11 +1,13 @@from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldTypeENDPOINTS = (+ "CreditUnits","Customers","Events","Invoices","ItemPrices","Items",+ "Meters","Orders","Subscriptions","Transactions",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/tests/test_chargebee.py b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/tests/test_chargebee.pyindex cee1c1af1661..921b2cf95481 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/tests/test_chargebee.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/chargebee/tests/test_chargebee.py@@ -164,7 +164,18 @@ class TestChargebeeSourceResumeBehavior:@pytest.mark.parametrize("endpoint",- ["Customers", "Events", "Invoices", "ItemPrices", "Items", "Subscriptions", "Transactions", "Orders"],+ [+ "CreditUnits",+ "Customers",+ "Events",+ "Invoices",+ "ItemPrices",+ "Items",+ "Meters",+ "Subscriptions",+ "Transactions",+ "Orders",+ ],)def test_fresh_run_saves_offset_after_each_non_terminal_page(self, endpoint: str) -> None:manager = MagicMock(spec=ResumableSourceManager)@@ -270,6 +281,7 @@ class TestChargebeeSiteNameValidation:class TestChargebeeCatalogEndpoints:"""`Items` and `ItemPrices` carry the product catalog that `subscription_items` points at.+ `CreditUnits` and `Meters` carry the usage-based billing catalog.Their rows sit one level deeper than the response list, so a wrong `data_selector` orpath yields an empty table rather than an error.@@ -285,6 +297,18 @@ class TestChargebeeCatalogEndpoints:"item_price",{"id": "gold-USD-monthly", "item_id": "gold", "price": 1000},),+ (+ "CreditUnits",+ "/v2/credit_units",+ "credit_unit",+ {"id": "ai-tokens", "status": "active", "is_unlimited": False, "overdraft_amount": "100.5"},+ ),+ (+ "Meters",+ "/v2/meters",+ "meter",+ {"id": "api-calls", "type": "simple", "query": "SELECT SUM(api_calls) FROM events"},+ ),],)def test_yields_the_nested_catalog_object(@@ -394,3 +418,9 @@ class TestChargebeeIncrementalFilter:sent_params = self._drive(endpoint, incremental=False, last_value=1750000000)assert self.CURSOR_PARAMS[endpoint] not in sent_params[0]++ @pytest.mark.parametrize("endpoint", ["CreditUnits", "Meters"])+ def test_full_refresh_only_endpoints_ignore_incremental_watermark(self, endpoint: str) -> None:+ sent_params = self._drive(endpoint, incremental=True, last_value=1750000000)++ assert sent_params == [{"limit": 100}]