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:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"shared-sqs/app/admin"
|
||||
"shared-sqs/app/auth"
|
||||
"shared-sqs/app/billing"
|
||||
sqs "shared-sqs/app/gosqs"
|
||||
"shared-sqs/app/interfaces"
|
||||
"shared-sqs/app/tenant"
|
||||
@@ -131,6 +132,16 @@ func actionHandler(w http.ResponseWriter, req *http.Request) {
|
||||
if ok {
|
||||
statusCode, responseBody := jsonFn(req)
|
||||
encodeResponse(w, req, statusCode, responseBody)
|
||||
// Billing: записываем каждую успешную SQS-операцию (async, no-op если billing выключен)
|
||||
if statusCode < 400 {
|
||||
if t, _ := req.Context().Value(auth.TenantContextKey).(*tenant.Tenant); t != nil {
|
||||
msgBytes := req.ContentLength
|
||||
if msgBytes < 0 {
|
||||
msgBytes = 0
|
||||
}
|
||||
billing.RecordUsage(t.ID, action, 1, msgBytes)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Warnf("Bad Request - Action: %s", action)
|
||||
|
||||
Reference in New Issue
Block a user