feat(observability): add product metrics for API, outbox and delivery

This commit is contained in:
shira committed 2026-10-06 19:48:15 +03:00
1 parent 560724e2aa
commit 94488e2b57
51 files changed
+3655 -68

No files matched your search

+21 -12
View File
@@ -18,6 +18,7 @@ import (
"lincodex/backend/config"
"lincodex/backend/internal/adapter/secondary/prometheus"
"lincodex/backend/internal/port/outbound"
"lincodex/backend/internal/worker/deliverymetrics"
"lincodex/backend/internal/worker/jobrunner"
"lincodex/backend/internal/worker/outboxrelay"
)
@@ -45,6 +46,9 @@ type Application struct {
// is nil when the worker is disabled, no job kind is registered, or the
// database is not configured.
jobs *jobrunner.Worker
// deliveryMetrics reads the delivery and quota gauges while the servers
// run. It is nil when the database is not configured.
deliveryMetrics *deliverymetrics.Sampler
}
func NewApplication(
@@ -56,16 +60,18 @@ func NewApplication(
relay *outboxrelay.Relay,
consumers eventConsumers,
jobs *jobrunner.Worker,
deliveryMetrics *deliverymetrics.Sampler,
) *Application {
return &Application{
config: config,
apiHandler: apiHandler,
metrics: metrics,
logger: logger,
mailSender: mailSender,
relay: relay,
consumers: consumers,
jobs: jobs,
config: config,
apiHandler: apiHandler,
metrics: metrics,
logger: logger,
mailSender: mailSender,
relay: relay,
consumers: consumers,
jobs: jobs,
deliveryMetrics: deliveryMetrics,
}
}
@@ -191,10 +197,10 @@ func (application *Application) run(ctx context.Context) error {
return err
}
// startWorkers runs the relay, every consumer, and the scheduled job worker
// until ctx ends and returns a channel that closes when all of them have
// stopped. The workers stop together with the servers; none of them
// depends on another.
// startWorkers runs the relay, every consumer, the scheduled job worker, and
// the delivery metrics sampler until ctx ends and returns a channel that
// closes when all of them have stopped. The workers stop together with the
// servers; none of them depends on another.
func (application *Application) startWorkers(ctx context.Context) <-chan struct{} {
var workers sync.WaitGroup
if application.relay != nil {
@@ -206,6 +212,9 @@ func (application *Application) startWorkers(ctx context.Context) <-chan struct{
if application.jobs != nil {
workers.Go(func() { application.jobs.Run(ctx) })
}
if application.deliveryMetrics != nil {
workers.Go(func() { application.deliveryMetrics.Run(ctx) })
}
stopped := make(chan struct{})
go func() {
defer close(stopped)