no cache archive reader

This commit is contained in:
royalcat 2024-04-17 11:36:14 +03:00
parent bcda69daad
commit 5591f145a9
16 changed files with 579 additions and 272 deletions
src/host/vfs

View file

@ -15,7 +15,7 @@ import (
type LogFS struct {
fs Filesystem
log *slog.Logger
log *rlog.Logger
timeout time.Duration
readTimeout time.Duration
@ -30,7 +30,7 @@ var _ Filesystem = (*LogFS)(nil)
func WrapLogFS(vfs Filesystem) *LogFS {
return &LogFS{
fs: vfs,
log: rlog.ComponentLog("fs"),
log: rlog.Component("logfs"),
timeout: time.Minute * 3,
readTimeout: time.Minute,
}
@ -102,7 +102,7 @@ func (fs *LogFS) Open(ctx context.Context, filename string) (file File, err erro
file, err = fs.fs.Open(ctx, filename)
if isLoggableError(err) {
fs.log.With("filename", filename).Error("Failed to open file")
fs.log.Error(ctx, "Failed to open file")
}
file = WrapLogFile(file, filename, fs.log, fs.readTimeout)
return file, err
@ -113,7 +113,10 @@ func (fs *LogFS) ReadDir(ctx context.Context, path string) (entries []fs.DirEntr
ctx, cancel := context.WithTimeout(ctx, fs.timeout)
defer cancel()
ctx, span := tracer.Start(ctx, "ReadDir",
fs.traceAttrs(attribute.String("path", path)),
fs.traceAttrs(
attribute.String("path", path),
attribute.String("fs-type", reflect.TypeOf(fs.fs).Name()),
),
)
defer func() {
if err != nil {
@ -124,7 +127,7 @@ func (fs *LogFS) ReadDir(ctx context.Context, path string) (entries []fs.DirEntr
entries, err = fs.fs.ReadDir(ctx, path)
if isLoggableError(err) {
fs.log.ErrorContext(ctx, "Failed to read dir", "path", path, "error", err.Error(), "fs-type", reflect.TypeOf(fs.fs).Name())
fs.log.Error(ctx, "Failed to read dir", rlog.Error(err))
}
return entries, err
}
@ -145,7 +148,7 @@ func (lfs *LogFS) Stat(ctx context.Context, filename string) (info fs.FileInfo,
info, err = lfs.fs.Stat(ctx, filename)
if isLoggableError(err) {
lfs.log.Error("Failed to stat", "filename", filename, "error", err)
lfs.log.Error(ctx, "Failed to stat", rlog.Error(err))
}
return info, err
}
@ -166,7 +169,7 @@ func (fs *LogFS) Unlink(ctx context.Context, filename string) (err error) {
err = fs.fs.Unlink(ctx, filename)
if isLoggableError(err) {
fs.log.Error("Failed to stat", "filename", filename, "error", err)
fs.log.Error(ctx, "Failed to stat", rlog.Error(err))
}
return err
}
@ -175,7 +178,7 @@ type LogFile struct {
filename string
f File
log *slog.Logger
log *rlog.Logger
timeout time.Duration
}
@ -191,11 +194,11 @@ func (f *LogFile) Type() fs.FileMode {
var _ File = (*LogFile)(nil)
func WrapLogFile(f File, filename string, log *slog.Logger, timeout time.Duration) *LogFile {
func WrapLogFile(f File, filename string, log *rlog.Logger, timeout time.Duration) *LogFile {
return &LogFile{
filename: filename,
f: f,
log: log.With("filename", filename),
log: log.With(slog.String("filename", filename)),
timeout: timeout,
}
}
@ -216,7 +219,7 @@ func (f *LogFile) Close(ctx context.Context) (err error) {
err = f.f.Close(ctx)
if isLoggableError(err) {
f.log.ErrorContext(ctx, "Failed to close", "error", err)
f.log.Error(ctx, "Failed to close", rlog.Error(err))
}
return err
}
@ -246,7 +249,7 @@ func (f *LogFile) Read(ctx context.Context, p []byte) (n int, err error) {
n, err = f.f.Read(ctx, p)
if isLoggableError(err) {
f.log.Error("Failed to read", "error", err)
f.log.Error(ctx, "Failed to read", rlog.Error(err))
}
return n, err
}
@ -259,6 +262,7 @@ func (f *LogFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err e
trace.WithAttributes(
attribute.String("filename", f.filename),
attribute.Int("length", len(p)),
attribute.Int64("offset", off),
),
)
defer func() {
@ -271,7 +275,7 @@ func (f *LogFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err e
n, err = f.f.ReadAt(ctx, p, off)
if isLoggableError(err) {
f.log.Error("Failed to read", "offset", off, "error", err)
f.log.Error(ctx, "Failed to read")
}
return n, err
}
@ -285,7 +289,7 @@ func (f *LogFile) Size() int64 {
func (f *LogFile) Info() (fs.FileInfo, error) {
info, err := f.f.Info()
if isLoggableError(err) {
f.log.Error("Failed to info", "error", err)
f.log.Error(context.Background(), "Failed to info", rlog.Error(err))
}
return info, err
}