Добавить наблюдаемость и проверки отказов для ЛР 6

This commit is contained in:
2026-11-26 18:20:32 +03:00
parent 1d81159dd3
commit 9db37405fb
46 changed files with 7878 additions and 173 deletions
+5 -5
View File
@@ -9,7 +9,6 @@ import (
_ "image/jpeg"
_ "image/png"
"io"
"log"
"mime"
"net/http"
"os"
@@ -25,6 +24,7 @@ import (
"mtusi2026/internal/jobs"
"mtusi2026/internal/model"
"mtusi2026/internal/store"
"mtusi2026/internal/telemetry"
)
const (
@@ -162,7 +162,7 @@ func (a *api) handleUploadAttachment(w http.ResponseWriter, r *http.Request, u m
err = a.blobs.Put(putCtx, stagingKey, io.NewSectionReader(tmp, 0, n), n, mt)
cancel()
if err != nil {
log.Printf("s3 put failed: %v", err)
telemetry.Error(r.Context(), "attachment.staging.write_failed")
delCtx, delCancel := context.WithTimeout(baseCtx, 5*time.Second)
_ = a.blobs.Delete(delCtx, stagingKey)
delCancel()
@@ -177,7 +177,7 @@ func (a *api) handleUploadAttachment(w http.ResponseWriter, r *http.Request, u m
SizeBytes: n, SHA256: hex.EncodeToString(h.Sum(nil)), ObjectKey: key, StagingKey: stagingKey,
})
if err != nil {
log.Printf("attachment metadata commit uncertain, staging retained: %v", err)
telemetry.Error(r.Context(), "attachment.accept_failed")
writeError(w, http.StatusInternalServerError, requestID, codeInternal, "internal error")
return
}
@@ -252,10 +252,10 @@ func (a *api) handleDownloadAttachment(w http.ResponseWriter, r *http.Request, u
t.Stop()
if err != nil {
if errors.Is(err, blobstore.ErrNotFound) {
log.Printf("INCONSISTENCY: metadata without object id=%s key=%s", att.ID, att.ObjectKey)
telemetry.Error(r.Context(), "attachment.object_missing")
writeError(w, http.StatusInternalServerError, requestID, codeInternal, "internal error")
} else {
log.Printf("s3 get failed: %v", err)
telemetry.Error(r.Context(), "attachment.object_read_failed")
writeError(w, http.StatusServiceUnavailable, requestID, codeUnavailable, "attachment storage unavailable")
}
return