feat: billing layer v1.3.86 — PostgreSQL statistics
- internal/billing: Store interface + pgStore (pgx/v5 pool) + NoopStore - factory.go: NewStore() from BILLING_DSN env var (NoopStore fallback) - Server.billing: injected into Config, initialized in main - handleInvokeFunction: record invocation (TriggerConsole) - invokeInternalFunction: record invocation (TriggerHTTP) - handleCreateFunction: record event_type=create - handleCloneFunction: record event_type=clone - handleDeleteFunction: record event_type=delete - table: invocations (namespace, function_name, trigger_type, duration_ms, status_code...) - BILLING_DSN added to console.yaml - pgx/v5 added to go.mod/go.sum
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package billing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// NewStore создаёт Store из переменной окружения BILLING_DSN.
|
||||
// Если DSN пустой — возвращает NoopStore (статистика отключена, сервер работает нормально).
|
||||
func NewStore() Store {
|
||||
dsn := os.Getenv("BILLING_DSN")
|
||||
if dsn == "" {
|
||||
log.Printf("billing: BILLING_DSN not set, statistics disabled")
|
||||
return NoopStore{}
|
||||
}
|
||||
store, err := NewPostgresStore(context.Background(), dsn)
|
||||
if err != nil {
|
||||
log.Printf("billing: failed to connect to PostgreSQL: %v — statistics disabled", err)
|
||||
return NoopStore{}
|
||||
}
|
||||
return store
|
||||
}
|
||||
Reference in New Issue
Block a user