[management] Move reverse proxy access logs to a dedicated database (#8303)

This commit is contained in:
Bethuel Mmbaga
2026-10-23 16:04:09 +03:00
committed by GitHub
parent 8397bed4af
commit 69f13e3733
18 changed files with 421 additions and 18 deletions
@@ -123,3 +123,37 @@ func TestSqlRepository_ListByAccount_StatusFilter(t *testing.T) {
assert.Equal(t, []string{"info", "notfound"}, listIDs("failed"))
assert.Equal(t, []string{"ok"}, listIDs("success"))
}
func TestSqlRepository_ListByAccount_Search(t *testing.T) {
repo, _ := newTestRepository(t)
ctx := context.Background()
api := newEntry("req-api", "acc", "GET", time.Hour)
api.Host = "api.example.com"
api.Path = "/v1/peers"
web := newEntry("req-web", "acc", "GET", 2*time.Hour)
web.Host = "web.example.com"
web.Path = "/login"
foreign := newEntry("foreign", "other", "GET", time.Hour)
foreign.Host = "api.example.com"
for _, entry := range []*accesslogs.AccessLogEntry{api, web, foreign} {
require.NoError(t, repo.Create(ctx, entry))
}
search := func(term string) []string {
logs, total, err := repo.ListByAccount(ctx, db.LockingStrengthNone, "acc", accesslogs.AccessLogFilter{Page: 1, PageSize: 10, Search: &term})
require.NoError(t, err)
require.EqualValues(t, len(logs), total)
ids := make([]string, 0, len(logs))
for _, entry := range logs {
ids = append(ids, entry.ID)
}
return ids
}
assert.Equal(t, []string{"req-api"}, search("api.example"), "search should match the host")
assert.Equal(t, []string{"req-web"}, search("/login"), "search should match the path")
assert.Equal(t, []string{"req-api"}, search("example.com/v1"), "search should match host and path joined")
assert.Equal(t, []string{"req-web"}, search("req-web"), "search should match the log ID")
assert.Equal(t, []string{"req-api", "req-web"}, search("example.com"), "search should list every match newest first")
assert.Empty(t, search("nothing-matches"))
}