mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-19 03:03:39 +09:00
feat: Add audit logging (#38189)
Co-authored-by: bircni <bircni@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
bircni
wxiaoguang
parent
4d43445532
commit
da37b7916b
@@ -0,0 +1,41 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/unittest"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
// BenchmarkInsertEvent measures the synchronous database cost added when audit
|
||||
// recording is enabled. Keep it separate from router benchmarks so it remains
|
||||
// comparable across changes to request handling.
|
||||
func BenchmarkInsertEvent(b *testing.B) {
|
||||
if err := unittest.PrepareTestDatabase(); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
event := &Event{
|
||||
Action: UserPassword,
|
||||
ActorID: 1,
|
||||
ActorName: "actor",
|
||||
ScopeType: ScopeUser,
|
||||
ScopeID: 2,
|
||||
ScopeName: "scope",
|
||||
Origin: OriginUI,
|
||||
Metadata: `{"source":"benchmark"}`,
|
||||
TimestampUnix: timeutil.TimeStamp(i + 1),
|
||||
}
|
||||
if err := InsertEvent(ctx, event); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user