Add fetch/conversion metrics and improve logging
FetchResult now includes: - StatusCode: HTTP status from upstream - FetchDurationMs: time to fetch from upstream - RemoteAddr: upstream server address SourceMetadata now stores: - ContentLength: size from upstream - FetchDurationMs: fetch timing - RemoteAddr: for debugging Image conversion log now includes: - host: source hostname (was missing) - path: source path (renamed from file) - convert_ms: image processing time - quality: requested quality setting - fit: requested fit mode
This commit is contained in:
@@ -157,18 +157,23 @@ func (s *Service) fetchAndProcess(ctx context.Context, req *ImageRequest) (*Imag
|
||||
}
|
||||
|
||||
// Process the image
|
||||
processStart := time.Now()
|
||||
|
||||
processResult, err := s.processor.Process(ctx, bytes.NewReader(sourceData), req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("image processing failed: %w", err)
|
||||
}
|
||||
|
||||
processDuration := time.Since(processStart)
|
||||
|
||||
// Log conversion details
|
||||
inputSize := int64(len(sourceData))
|
||||
outputSize := processResult.ContentLength
|
||||
sizePercent := float64(outputSize) / float64(inputSize) * 100.0 //nolint:mnd // percentage calculation
|
||||
|
||||
s.log.Info("image converted",
|
||||
"file", req.SourcePath,
|
||||
"host", req.SourceHost,
|
||||
"path", req.SourcePath,
|
||||
"input_format", processResult.InputFormat,
|
||||
"output_format", req.Format,
|
||||
"input_bytes", inputSize,
|
||||
@@ -176,6 +181,9 @@ func (s *Service) fetchAndProcess(ctx context.Context, req *ImageRequest) (*Imag
|
||||
"input_dimensions", fmt.Sprintf("%dx%d", processResult.InputWidth, processResult.InputHeight),
|
||||
"output_dimensions", fmt.Sprintf("%dx%d", processResult.Width, processResult.Height),
|
||||
"size_ratio", fmt.Sprintf("%.1f%%", sizePercent),
|
||||
"convert_ms", processDuration.Milliseconds(),
|
||||
"quality", req.Quality,
|
||||
"fit", req.FitMode,
|
||||
)
|
||||
|
||||
// Store output content to cache
|
||||
|
||||
Reference in New Issue
Block a user