feat(outbox): relay committed outbox events to Kafka

This commit is contained in:
shira committed 2026-10-06 03:01:53 +03:00
1 parent 78f1651f6b
commit 6c3b34f73e
42 files changed
+3731 -45

No files matched your search

@@ -5,6 +5,8 @@ import (
"strings"
"testing"
"time"
"lincodex/backend/internal/port/outbound"
)
func TestMetricsHandlerExposesBoundedRequestLabels(t *testing.T) {
@@ -21,3 +23,38 @@ func TestMetricsHandlerExposesBoundedRequestLabels(t *testing.T) {
t.Fatalf("metrics output is missing request duration:\n%s", body)
}
}
func TestMetricsHandlerExposesOutboxRelayOutcomes(t *testing.T) {
metrics := New()
metrics.ObserveOutboxRelayPass(3, 0)
metrics.ObserveOutboxRelayPass(1, 2)
response := httptest.NewRecorder()
metrics.Handler().ServeHTTP(response, httptest.NewRequest("GET", "/metrics", nil))
body := response.Body.String()
for _, want := range []string{
`lincodex_outbox_relay_events_total{outcome="published"} 4`,
`lincodex_outbox_relay_events_total{outcome="failed"} 2`,
} {
if !strings.Contains(body, want) {
t.Fatalf("metrics output is missing %s:\n%s", want, body)
}
}
}
func TestMetricsHandlerExposesTheOutboxBacklog(t *testing.T) {
metrics := New()
metrics.ObserveOutboxBacklog(outbound.OutboxBacklog{Pending: 42, OldestAge: 90 * time.Second})
response := httptest.NewRecorder()
metrics.Handler().ServeHTTP(response, httptest.NewRequest("GET", "/metrics", nil))
body := response.Body.String()
for _, want := range []string{
"lincodex_outbox_relay_pending_events 42",
"lincodex_outbox_relay_oldest_pending_age_seconds 90",
} {
if !strings.Contains(body, want) {
t.Fatalf("metrics output is missing %s:\n%s", want, body)
}
}
}