ccproxy.observability.storage.duckdb_simple¶
ccproxy.observability.storage.duckdb_simple
¶
Simplified DuckDB storage for low-traffic environments.
This module provides a simple, direct DuckDB storage implementation without connection pooling or batch processing. Suitable for dev environments with low request rates (< 10 req/s).
AccessLogPayload
¶
Bases: TypedDict
TypedDict for access log data payloads.
Note: All fields are optional (total=False) to allow partial payloads. The storage layer will provide sensible defaults for missing fields.
SimpleDuckDBStorage
¶
Simple DuckDB storage with queue-based writes to prevent deadlocks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database_path
|
str | Path
|
Path to DuckDB database file |
'data/metrics.duckdb'
|
Source code in ccproxy/observability/storage/duckdb_simple.py
initialize
async
¶
Initialize the storage backend.
Source code in ccproxy/observability/storage/duckdb_simple.py
store_request
async
¶
Store a single request log entry asynchronously via queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
AccessLogPayload
|
Request data to store |
required |
Returns:
Type | Description |
---|---|
bool
|
True if queued successfully |
Source code in ccproxy/observability/storage/duckdb_simple.py
store_batch
async
¶
Store a batch of metrics efficiently.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metrics
|
Sequence[AccessLogPayload]
|
List of metric data to store |
required |
Returns:
Type | Description |
---|---|
bool
|
True if batch stored successfully |
Source code in ccproxy/observability/storage/duckdb_simple.py
store
async
¶
Store single metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
AccessLogPayload
|
Metric data to store |
required |
Returns:
Type | Description |
---|---|
bool
|
True if stored successfully |
query
async
¶
Execute SQL query and return results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql
|
str
|
SQL query string |
required |
params
|
dict[str, Any] | list[Any] | None
|
Query parameters |
None
|
limit
|
int
|
Maximum number of results |
1000
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
List of result rows as dictionaries |
Source code in ccproxy/observability/storage/duckdb_simple.py
get_recent_requests
async
¶
Get recent requests for debugging/monitoring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit
|
int
|
Number of recent requests to return |
100
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
List of recent request records |
Source code in ccproxy/observability/storage/duckdb_simple.py
get_analytics
async
¶
Get analytics using SQLModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time
|
float | None
|
Start timestamp (Unix time) |
None
|
end_time
|
float | None
|
End timestamp (Unix time) |
None
|
model
|
str | None
|
Filter by model name |
None
|
service_type
|
str | None
|
Filter by service type |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Analytics summary data |
Source code in ccproxy/observability/storage/duckdb_simple.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
|
close
async
¶
Close the database connection and stop background worker.
Source code in ccproxy/observability/storage/duckdb_simple.py
is_enabled
¶
health_check
async
¶
Get health status of the storage backend.
Source code in ccproxy/observability/storage/duckdb_simple.py
reset_data
async
¶
Reset all data in the storage (useful for testing/debugging).
Returns:
Type | Description |
---|---|
bool
|
True if reset was successful |