Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions internal/dashboard/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
"time"
)

const (
defaultLogCollectorSize = 1000
maxLogCollectorSize = 10000
)

// RequestLog holds details about a single API request.
type RequestLog struct {
Method string `json:"method"`
Expand All @@ -28,6 +33,13 @@ type LogCollector struct {

// NewLogCollector creates a LogCollector that holds at most maxSize entries.
func NewLogCollector(maxSize int) *LogCollector {
if maxSize <= 0 {
maxSize = defaultLogCollectorSize
}
if maxSize > maxLogCollectorSize {
maxSize = maxLogCollectorSize
}

return &LogCollector{
entries: make([]RequestLog, maxSize),
maxSize: maxSize,
Expand All @@ -52,12 +64,12 @@ func (c *LogCollector) Recent(n int) []RequestLog {
c.mu.RLock()
defer c.mu.RUnlock()

if n <= 0 || c.count == 0 {
return []RequestLog{}
}
if n > c.count {
n = c.count
}
if n <= 0 {
return []RequestLog{}
}

result := make([]RequestLog, n)
// cursor points to the slot that will be written next, so cursor-1 is the
Expand Down
Loading