fix
Build and Publish / Metadata (push) Has been cancelled
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled

This commit is contained in:
2026-04-05 18:27:35 +02:00
parent 83c8f6eae2
commit d83fe85864
8 changed files with 72 additions and 8 deletions
+9 -1
View File
@@ -1,3 +1,4 @@
// Package storage implements persistent storage for telemetry data.
package storage
import (
@@ -11,10 +12,12 @@ import (
"github.com/natefinch/lumberjack"
)
// FileStore implements the Store interface using a file-based logger.
type FileStore struct {
logger *lumberjack.Logger
}
// NewFileStore creates a new FileStore instance that writes to filename.
func NewFileStore(filename string) *FileStore {
return &FileStore{
logger: &lumberjack.Logger{
@@ -27,6 +30,7 @@ func NewFileStore(filename string) *FileStore {
}
}
// Append saves a new history entry to the file store.
func (fs *FileStore) Append(ctx context.Context, entry websocket.HistoryEntry) error {
data, err := json.Marshal(entry)
if err != nil {
@@ -36,10 +40,12 @@ func (fs *FileStore) Append(ctx context.Context, entry websocket.HistoryEntry) e
return err
}
// GetHistory retrieves historical entries from the file store.
func (fs *FileStore) GetHistory(ctx context.Context, limit int) ([]websocket.HistoryEntry, error) {
return fs.Search(ctx, "", limit)
}
// Search searches for historical entries in the file store matching the query.
func (fs *FileStore) Search(ctx context.Context, query string, limit int) ([]websocket.HistoryEntry, error) {
if limit <= 0 {
limit = 50 // Default to a manageable number
@@ -52,7 +58,9 @@ func (fs *FileStore) Search(ctx context.Context, query string, limit int) ([]web
}
return nil, err
}
defer file.Close()
defer func() {
_ = file.Close()
}()
var matchingLines []string
scanner := bufio.NewScanner(file)
+3 -1
View File
@@ -11,7 +11,9 @@ import (
func TestFileStore(t *testing.T) {
filename := "test-otel.log"
defer os.Remove(filename)
defer func() {
_ = os.Remove(filename)
}()
fs := NewFileStore(filename)
ctx := context.Background()
+1
View File
@@ -5,6 +5,7 @@ import (
"git.tornberg.me/go-otel/internal/websocket"
)
// Store interface for telemetry history persistence.
type Store interface {
Append(ctx context.Context, entry websocket.HistoryEntry) error
GetHistory(ctx context.Context, limit int) ([]websocket.HistoryEntry, error)