mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
Implements PR 3 of the 3-PR billing-API scope discussed in #791. Adds two service surfaces that share one underlying export pipeline: - `cur:*` — legacy Cost and Usage Reports management plane, target prefix `AWSOrigamiServiceGatewayService.*`. - `bcm-data-exports:*` — modern Billing and Cost Management Data Exports management plane, target prefix `AWSBillingAndCostManagementDataExports.*`. Both run as JSON 1.1 services dispatched through the existing `AwsJson11Controller`. ## Operations CUR (7): - `PutReportDefinition`, `ModifyReportDefinition`, `DescribeReportDefinitions`, `DeleteReportDefinition` - `TagResource` / `UntagResource` / `ListTagsForResource` (stubs) BCM Data Exports (7): - `CreateExport`, `GetExport`, `ListExports`, `UpdateExport`, `DeleteExport` - `ListExecutions`, `GetExecution` AWS-shaped error codes throughout: `DuplicateReportNameException`, `ReportLimitReachedException`, `ReportNotFoundException`, `ResourceNotFoundException`, `ValidationException`, `UnknownOperationException`. Storage keys are account-scoped (`<accountId>::<region>::<reportName>` for CUR; `<accountId>::<exportArn>` and `<accountId>::<exportArn>::<executionId>` for BCM) so both services participate in Floci's per-account isolation. ## Parquet emission The same `ResourceUsageEnumerator` SPI introduced in #832 (Cost Explorer) backs the Parquet artifact: 1. `EmissionEngine` collects `UsageLine` rows from every `@ApplicationScoped` enumerator bean. 2. `FocusRowProjector` projects them into FOCUS 1.2 / CUR 2.0 column shape, reusing #821's bundled Pricing snapshot for unit prices. 3. Rows are staged as newline-delimited JSON in `s3://floci-cur-staging/...` via Floci's S3 service — escape-safe for tags, descriptions, and resource identifiers. 4. The `floci-duck` sidecar runs `COPY (SELECT * FROM read_json_auto('s3://...')) TO 's3://...' (FORMAT PARQUET)` so Parquet writes happen inside DuckDB, not in the Java process. This avoids pulling Apache Parquet / Hadoop / Avro into Floci's classpath and keeps the native binary footprint unchanged. 5. Staging objects are removed in a best-effort `finally` block; each run carries a fresh `runId` (UUID) in both staging and destination keys so concurrent emissions cannot clobber each other. The emission engine is shared between CUR and BCM, but the management planes are otherwise independent — they each own their own validation, storage, and JSON dispatch. ## Run modes `FLOCI_SERVICES_CUR_EMIT_MODE` and `FLOCI_SERVICES_BCM_DATA_EXPORTS_EMIT_MODE`: - `synchronous` (default): emit on every report/export mutation - `daily`: emit once per 24h via a CUR-owned single-thread `ScheduledExecutorService` — separate from the EventBridge Scheduler dispatcher, so internal billing exports do not surface as user-visible Scheduler resources. - `off`: management plane only Emission failures never roll back the management mutation. Failures surface as `ReportStatus.LastStatus = ERROR` on CUR and `Execution.ExecutionStatus.StatusCode = DELIVERY_FAILURE` on BCM. ## Tests 42 new tests across 5 classes: - `CurIntegrationTest` (11) — full CRUD on report definitions, duplicate / not-found / validation paths - `BcmDataExportsIntegrationTest` (16) — full CRUD on exports + executions, all validation paths - `FocusRowProjectorTest` (9) — pure-unit projection: usage rows, USD-denominated record types (Credit / Refund / Tax), missing resource id, tags JSON, billing-period anchoring, region+account flow-through, rate cache reuse - `ParquetEmitterIntegrationTest` (3) — DuckDB readback, staging cleanup, concurrent run isolation - `CurEmissionIntegrationTest` (3) — end-to-end: PutReportDefinition -> emit -> Parquet readable through DuckDB; ReportStatus updates; CreateExport produces an execution record Full Floci suite stays green (4194/4194, excluding the pre-existing local-env flakes documented during PR #821 / #832 and the two duck-required tests added here that need the `floci-duck` sidecar and a fixed Floci HTTP port to verify cross-container S3 access). ## Documentation - `docs/services/cur.md` — operations, validation rules, emission pipeline, configuration, examples. - `docs/services/bcm-data-exports.md` — operations, validation, execution lifecycle, configuration, examples. - README service table updated with rows for both, plus a note that CUR / BCM Data Exports share one Parquet engine. Refs: https://github.com/orgs/floci-io/discussions/791 Refs: #823 Builds on: #821, #832
155 lines
5.1 KiB
Markdown
155 lines
5.1 KiB
Markdown
# BCM Data Exports (`bcm-data-exports:*`)
|
|
|
|
**Protocol:** JSON 1.1
|
|
**Header:** `X-Amz-Target: AWSBillingAndCostManagementDataExports.<Action>`
|
|
**Endpoint prefix:** `bcm-data-exports`
|
|
|
|
Floci emulates the BCM Data Exports management plane that ships with
|
|
CUR 2.0 / FOCUS 1.2. Exports share the same Parquet emission engine as
|
|
the legacy [`cur:*`](cur.md) service — the two are alternative
|
|
management surfaces over one underlying export pipeline.
|
|
|
|
## Supported Operations
|
|
|
|
| Operation | Notes |
|
|
|-----------|-------|
|
|
| `CreateExport` | Creates an export; rejects duplicate `Name` with `ValidationException` |
|
|
| `GetExport` | Returns one export by ARN; missing ARN returns `ResourceNotFoundException` |
|
|
| `ListExports` | Returns every export owned by the calling account |
|
|
| `UpdateExport` | Replaces mutable fields on an existing export |
|
|
| `DeleteExport` | Idempotent; deletes orphan executions too |
|
|
| `ListExecutions` | Returns all execution records for an export |
|
|
| `GetExecution` | Returns one execution record |
|
|
|
|
## Validation rules
|
|
|
|
- `Export.Name`: alphanumerics + `-_`, max 128 chars
|
|
- `Export.DataQuery.QueryStatement`: required (free-form SQL — Floci does
|
|
not parse it; the export shape is determined by the bundled FOCUS
|
|
schema)
|
|
- `Export.DestinationConfigurations.S3Destination`: required;
|
|
`S3Bucket` + `S3Region` mandatory
|
|
- `S3OutputConfigurations.Format`: `PARQUET` (CSV emission not yet implemented; `TEXT_OR_CSV` returns `ValidationException`)
|
|
- `S3OutputConfigurations.Compression`: `PARQUET` (`GZIP` not yet implemented)
|
|
- `S3OutputConfigurations.Overwrite`: `CREATE_NEW_REPORT` / `OVERWRITE_REPORT`
|
|
- `S3OutputConfigurations.OutputType`: `CUSTOM`
|
|
- `RefreshCadence.Frequency`: `SYNCHRONOUS` (the only AWS-supported
|
|
value at the time of writing)
|
|
|
|
## Storage keys
|
|
|
|
Account-scoped throughout:
|
|
|
|
- Export: `<accountId>::<exportArn>`
|
|
- Execution: `<accountId>::<exportArn>::<executionId>`
|
|
|
|
Deleting an export removes all of its executions in the same call to
|
|
avoid orphan records.
|
|
|
|
## Execution lifecycle
|
|
|
|
A successful `CreateExport` in `synchronous` mode produces exactly one
|
|
execution record:
|
|
|
|
```
|
|
INITIATION_IN_PROCESS (recorded at create-time)
|
|
|
|
|
v
|
|
DELIVERY_SUCCESS or DELIVERY_FAILURE
|
|
```
|
|
|
|
Status transitions on `UpdateExport` too. Both `success` and `failure`
|
|
end states are visible via `GetExecution.Execution.ExecutionStatus`.
|
|
|
|
## Emission
|
|
|
|
The Parquet pipeline is the same as for [`cur:*`](cur.md): rows from
|
|
the `ResourceUsageEnumerator` SPI go through `FocusRowProjector`, are
|
|
staged as NDJSON in `floci-cur-staging`, and written as Parquet by the
|
|
`floci-duck` sidecar via `COPY ... TO ... (FORMAT PARQUET)`. Each
|
|
execution produces an artifact at
|
|
`s3://<S3Bucket>/<S3Prefix>/<Name>/<runId>.parquet`.
|
|
|
|
### `FLOCI_SERVICES_BCM_DATA_EXPORTS_EMIT_MODE`
|
|
|
|
| Value | Behavior |
|
|
|-------|----------|
|
|
| `synchronous` (default) | Emit on every `CreateExport` / `UpdateExport` |
|
|
| `daily` | Emit every 24h via the shared CUR scheduled executor |
|
|
| `off` | Management plane only — no emission |
|
|
|
|
## Configuration
|
|
|
|
| Variable | Default | Description |
|
|
|---|---|---|
|
|
| `FLOCI_SERVICES_BCM_DATA_EXPORTS_ENABLED` | `true` | Enable or disable the service |
|
|
| `FLOCI_SERVICES_BCM_DATA_EXPORTS_EMIT_MODE` | `synchronous` | Run mode (see above) |
|
|
|
|
## Examples
|
|
|
|
```bash
|
|
export AWS_ENDPOINT_URL=http://localhost:4566
|
|
export AWS_DEFAULT_REGION=us-east-1
|
|
export AWS_ACCESS_KEY_ID=test
|
|
export AWS_SECRET_ACCESS_KEY=test
|
|
|
|
aws bcm-data-exports create-export --export '{
|
|
"Name": "focus-monthly",
|
|
"DataQuery": {"QueryStatement": "SELECT * FROM COST_AND_USAGE_REPORT"},
|
|
"DestinationConfigurations": {
|
|
"S3Destination": {
|
|
"S3Bucket": "my-billing",
|
|
"S3Prefix": "focus",
|
|
"S3Region": "us-east-1",
|
|
"S3OutputConfigurations": {
|
|
"Format": "PARQUET",
|
|
"Compression": "PARQUET",
|
|
"OutputType": "CUSTOM",
|
|
"Overwrite": "OVERWRITE_REPORT"
|
|
}
|
|
}
|
|
},
|
|
"RefreshCadence": {"Frequency": "SYNCHRONOUS"}
|
|
}'
|
|
|
|
aws bcm-data-exports list-exports
|
|
|
|
aws bcm-data-exports list-executions \
|
|
--export-arn arn:aws:bcm-data-exports:us-east-1:000000000000:export/focus-monthly
|
|
```
|
|
|
|
```python
|
|
import boto3
|
|
|
|
client = boto3.client(
|
|
"bcm-data-exports",
|
|
endpoint_url="http://localhost:4566",
|
|
region_name="us-east-1",
|
|
)
|
|
resp = client.create_export(Export={
|
|
"Name": "focus-monthly",
|
|
"DataQuery": {"QueryStatement": "SELECT * FROM COST_AND_USAGE_REPORT"},
|
|
"DestinationConfigurations": {"S3Destination": {
|
|
"S3Bucket": "my-billing",
|
|
"S3Prefix": "focus",
|
|
"S3Region": "us-east-1",
|
|
"S3OutputConfigurations": {
|
|
"Format": "PARQUET", "Compression": "PARQUET",
|
|
"OutputType": "CUSTOM", "Overwrite": "OVERWRITE_REPORT",
|
|
},
|
|
}},
|
|
"RefreshCadence": {"Frequency": "SYNCHRONOUS"},
|
|
})
|
|
print(resp["ExportArn"])
|
|
```
|
|
|
|
## Out of Scope
|
|
|
|
- Custom SQL evaluation in `DataQuery.QueryStatement` — Floci ignores
|
|
the SQL and emits the FOCUS shape directly. The query string is
|
|
persisted faithfully so SDK round-trips work, but it has no effect on
|
|
the Parquet output.
|
|
- Cost categories, billing views, and pricing-model overrides
|
|
- Real `RefreshCadence` scheduling beyond `SYNCHRONOUS` and the
|
|
`daily` Floci-internal mode
|