Log snapshot listing failures
This commit is contained in:
@@ -26,9 +26,11 @@ type Server struct {
|
||||
}
|
||||
|
||||
var Version = "dev"
|
||||
var apiErrorLog *slog.Logger
|
||||
|
||||
func New(socket string, svc *service.Service, log *slog.Logger) *Server {
|
||||
s := &Server{service: svc, log: log, socket: socket}
|
||||
apiErrorLog = log
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /v1/health", s.health)
|
||||
mux.HandleFunc("GET /v1/config", s.getConfig)
|
||||
@@ -55,7 +57,7 @@ func New(socket string, svc *service.Service, log *slog.Logger) *Server {
|
||||
mux.HandleFunc("GET /v1/repositories/{id}/snapshots", s.snapshots)
|
||||
mux.HandleFunc("GET /v1/repositories/{id}/snapshots/{snapshot}/files", s.snapshotFiles)
|
||||
mux.HandleFunc("POST /v1/restores", s.restore)
|
||||
s.http = &http.Server{Handler: requestLog(log, mux), ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 30 * time.Second, WriteTimeout: 5 * time.Minute, IdleTimeout: 30 * time.Second}
|
||||
s.http = &http.Server{Handler: requestLog(log, mux), ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 30 * time.Second, WriteTimeout: 25 * time.Minute, IdleTimeout: 30 * time.Second}
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -321,6 +323,9 @@ func writeError(w http.ResponseWriter, err error) {
|
||||
if strings.Contains(message, "already queued") {
|
||||
status = 409
|
||||
}
|
||||
if apiErrorLog != nil {
|
||||
apiErrorLog.Warn("api error", "status", status, "error", message)
|
||||
}
|
||||
writeJSON(w, status, map[string]string{"error": message})
|
||||
}
|
||||
|
||||
|
||||
@@ -385,16 +385,24 @@ func (s *Service) RepositoryStats(ctx context.Context) []model.RepositoryStats {
|
||||
}
|
||||
|
||||
func (s *Service) SnapshotFiles(ctx context.Context, repoID, snapshot, path string) ([]map[string]any, error) {
|
||||
started := time.Now()
|
||||
repo, ok := s.repository(repoID)
|
||||
if !ok {
|
||||
return nil, errors.New("validation: unknown repository")
|
||||
}
|
||||
mounted, err := s.mounts.Prepare(ctx, repo)
|
||||
if err != nil {
|
||||
s.log.Warn("snapshot file listing failed", "repoID", repoID, "snapshot", snapshot, "path", path, "durationMs", time.Since(started).Milliseconds(), "error", err)
|
||||
return nil, err
|
||||
}
|
||||
defer s.mounts.Cleanup(context.Background(), mounted)
|
||||
return s.restic.List(ctx, mounted.Repository, snapshot, path)
|
||||
items, err := s.restic.List(ctx, mounted.Repository, snapshot, path)
|
||||
if err != nil {
|
||||
s.log.Warn("snapshot file listing failed", "repoID", repoID, "snapshot", snapshot, "path", path, "durationMs", time.Since(started).Milliseconds(), "error", err)
|
||||
return nil, err
|
||||
}
|
||||
s.log.Info("snapshot file listing loaded", "repoID", repoID, "snapshot", snapshot, "path", path, "items", len(items), "durationMs", time.Since(started).Milliseconds())
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (s *Service) TestRepository(ctx context.Context, repoID string, initialize bool) error {
|
||||
|
||||
Reference in New Issue
Block a user