feat: billing — usage tracking per SQS operation in PostgreSQL

- New package app/billing: Init/RecordUsage/Close with auto-migrate
- Integration in actionHandler: record tenant_id, operation, msg_count, msg_bytes
- Helm chart: billing section in values.yaml, secret-billing.yaml, env vars in deployment
- Optional: billing disabled by default (BILLING_PG_HOST not set = no-op)
- Table: sqs_usage_records with index on (tenant_id, recorded_at)
This commit is contained in:
Naeel
2026-04-12 11:51:27 +03:00
parent d1af612b48
commit 1272388673
13 changed files with 448 additions and 4 deletions
+8
View File
@@ -13,6 +13,7 @@ import (
"syscall"
"time"
"shared-sqs/app/billing"
"shared-sqs/app/conf"
"shared-sqs/app/gosqs"
"shared-sqs/app/models"
@@ -124,6 +125,10 @@ func main() {
if os.Getenv("SHARED_SQS_SEED_DEMO") == "true" {
seedDemoData(tenantStore)
}
// Billing: подключение к PostgreSQL для учёта использования.
// Если BILLING_PG_HOST не задан — billing отключён, SQS работает без него.
billing.Init()
// Роутер с tenant auth и admin API
r := router.New(tenantStore, adminToken)
@@ -163,6 +168,9 @@ func main() {
// Остановить PeriodicTasks
close(quit)
// Закрыть billing (если был подключён)
billing.Close()
// Дать 10 секунд на завершение текущих HTTP запросов
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()