From 5e09a2b2bb973f0e08c8cd0834763553bed46c25 Mon Sep 17 00:00:00 2001 From: Catherine Date: Tue, 21 Oct 2025 03:54:20 +0000 Subject: [PATCH] Add a metric for site space saving due to compression. --- src/manifest.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/manifest.go b/src/manifest.go index 225f673..f0a2e6b 100644 --- a/src/manifest.go +++ b/src/manifest.go @@ -15,13 +15,28 @@ import ( "path/filepath" "strings" "sync" + "time" "github.com/c2h5oh/datasize" "github.com/klauspost/compress/zstd" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" ) +var ( + siteCompressionSpaceSaving = promauto.NewHistogramVec(prometheus.HistogramOpts{ + Name: "git_pages_site_compression_space_saving", + Help: "Reduction in site size after compression relative to the uncompressed size", + Buckets: []float64{.01, .025, .05, .1, .25, .5, .75, 1, 1.25, 1.5, 1.75, 2, 2.5, 5, 10}, + + NativeHistogramBucketFactor: 1.1, + NativeHistogramMaxBucketNumber: 100, + NativeHistogramMinResetDuration: 10 * time.Minute, + }, []string{}) +) + func IsManifestEmpty(manifest *Manifest) bool { if len(manifest.Contents) > 1 { return false @@ -166,11 +181,15 @@ func CompressFiles(ctx context.Context, manifest *Manifest) { } } + spaceSaving := (float64(originalSize) - float64(transformedSize)) / float64(originalSize) log.Printf("compress: saved %.2f%% (%s to %s)", - (float32(originalSize)-float32(transformedSize))/float32(originalSize)*100.0, + spaceSaving*100.0, datasize.ByteSize(originalSize).HR(), datasize.ByteSize(transformedSize).HR(), ) + siteCompressionSpaceSaving. + With(prometheus.Labels{}). + Observe(spaceSaving) } // Apply post-processing steps to the manifest.