metric: treat io.EOF as successful upload, not an error

Uploads that end with io.EOF are now considered successful and no longer increment the upload error metric.
This aligns metric reporting with Go convention, where io.EOF indicates normal completion rather than an error.
This commit is contained in:
lushenle 2025-06-19 21:05:44 +08:00
commit 8979d2ce80

View file

@ -18,6 +18,9 @@
package metric
import (
"errors"
"io"
"github.com/go-chi/chi/v5"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
@ -648,7 +651,7 @@ func AddMetricsEndpoint(metricsPath string, handler chi.Router) {
func TransferCompleted(bytesSent, bytesReceived int64, transferKind int, err error, isSFTPFs bool) {
if transferKind == 0 {
// upload
if err == nil {
if err == nil || errors.Is(err, io.EOF) {
totalUploads.Inc()
} else {
totalUploadErrors.Inc()