IMG-46: Call finishFn on download finished (metrics) (#1487)

* Skip goes to processing

* Call finishFn on download finished

* defer DownloadFinished in DownloadSync
This commit is contained in:
Victor Sokolov
2025-08-15 12:43:57 +02:00
committed by GitHub
parent d47eeee6ad
commit af890f8b71
5 changed files with 50 additions and 13 deletions

View File

@@ -29,6 +29,7 @@ import (
"github.com/imgproxy/imgproxy/v3/processing"
"github.com/imgproxy/imgproxy/v3/router"
"github.com/imgproxy/imgproxy/v3/security"
"github.com/imgproxy/imgproxy/v3/svg"
"github.com/imgproxy/imgproxy/v3/vips"
)
@@ -361,15 +362,16 @@ func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) {
statusCode := http.StatusOK
originData, originHeaders, err := func() (imagedata.ImageData, http.Header, error) {
defer metrics.StartDownloadingSegment(ctx, metrics.Meta{
downloadFinished := metrics.StartDownloadingSegment(ctx, metrics.Meta{
metrics.MetaSourceImageURL: metricsMeta[metrics.MetaSourceImageURL],
metrics.MetaSourceImageOrigin: metricsMeta[metrics.MetaSourceImageOrigin],
})()
})
downloadOpts := imagedata.DownloadOptions{
Header: imgRequestHeader,
CookieJar: nil,
MaxSrcFileSize: po.SecurityOptions.MaxSrcFileSize,
Header: imgRequestHeader,
CookieJar: nil,
MaxSrcFileSize: po.SecurityOptions.MaxSrcFileSize,
DownloadFinished: downloadFinished,
}
if config.CookiePassthrough {
@@ -468,6 +470,12 @@ func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) {
}
if err != nil {
// svg_processing is an exception. We use As here because Is does not work with types.
var e svg.SanitizeError
if errors.As(err, &e) {
checkErr(ctx, "svg_processing", e)
}
// First, check if the processing error wasn't caused by an image data error
checkErr(ctx, "download", originData.Error())