Commit f92422e
committed
Add payer metadata endpoint (#1013)
### TL;DR
Added a new API endpoint to retrieve payer usage information, including spend and message counts, with hourly or daily granularity.
## Requires
- xmtp/proto#287
### What changed?
- Added a new `GetPayerInfo` endpoint to the Metadata API service that allows querying payer usage data
- Created a `PayerInfoFetcher` to retrieve payer information from the database
- Added message count tracking to the `unsettled_usage` table via a new migration
- Modified the protocol buffer definitions to support the new API endpoint
- Updated the `dev/gen/protos` script to support configurable branch selection via `GEN_PROTO_BRANCH` environment variable
### How to test?
1. Run the database migrations to add the message count column
2. Use the new API endpoint with a payer address:
```
curl -X POST http://localhost:8080/mls/v2/metadata/get-payer-info \
-H "Content-Type: application/json" \
-d '{"payer_addresses": ["0x..."], "granularity": "PAYER_INFO_GRANULARITY_DAY"}'
```
3. Run the comprehensive test suite in `payer_info_test.go` which covers various scenarios including:
- Different time granularities (hourly/daily)
- Time range filtering
- Multiple originators
- Edge cases and boundary conditions
### Why make this change?
This change enables monitoring and reporting of payer usage metrics, allowing both the service operator and payers themselves to track message volume and spending over time. The granular data can be used for billing, analytics, and capacity planning purposes.1 parent 09466d1 commit f92422e
18 files changed
Lines changed: 1247 additions & 35 deletions
File tree
- dev/gen
- pkg
- api/metadata
- db
- queries
- sqlc
- migrations
- mocks/metadata_api
- proto
- openapi/xmtpv4/metadata_api
- xmtpv4/metadata_api
- server
- sync
- testutils/api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | | - | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
0 commit comments