diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-21 09:01:18 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-24 03:22:45 +0300 |
commit | a451e2b0683d46e2ce2d7a92181eb4379dddf866 (patch) | |
tree | 5548742c7f69b93eaef9ac1d56b02cdb5cc30201 /internal/serving | |
parent | 27adbbac6de8473a78b39799cef2d8873beef91a (diff) |
Add Name to the VFS interface to use with metrics
Diffstat (limited to 'internal/serving')
-rw-r--r-- | internal/serving/disk/local/serving.go | 2 | ||||
-rw-r--r-- | internal/serving/disk/reader.go | 6 | ||||
-rw-r--r-- | internal/serving/disk/serving.go | 2 | ||||
-rw-r--r-- | internal/serving/disk/symlink/path_test.go | 2 | ||||
-rw-r--r-- | internal/serving/disk/zip/serving.go | 2 |
5 files changed, 7 insertions, 7 deletions
diff --git a/internal/serving/disk/local/serving.go b/internal/serving/disk/local/serving.go index d4a882bc..2882a301 100644 --- a/internal/serving/disk/local/serving.go +++ b/internal/serving/disk/local/serving.go @@ -8,7 +8,7 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/metrics" ) -var instance = disk.New(vfs.Instrumented(&local.VFS{}, "local"), metrics.DiskServingFileSize) +var instance = disk.New(vfs.Instrumented(local.New("local")), metrics.VFSServingFileSize) // Instance returns a serving instance that is capable of reading files // from the disk diff --git a/internal/serving/disk/reader.go b/internal/serving/disk/reader.go index 5b34c556..559d332c 100644 --- a/internal/serving/disk/reader.go +++ b/internal/serving/disk/reader.go @@ -20,7 +20,7 @@ import ( // Reader is a disk access driver type Reader struct { - fileSizeMetric prometheus.Histogram + fileSizeMetric *prometheus.HistogramVec vfs vfs.VFS } @@ -196,7 +196,7 @@ func (reader *Reader) serveFile(ctx context.Context, w http.ResponseWriter, r *h w.Header().Set("Content-Type", contentType) - reader.fileSizeMetric.Observe(float64(fi.Size())) + reader.fileSizeMetric.WithLabelValues(reader.vfs.Name()).Observe(float64(fi.Size())) // Support vfs.SeekableFile if available (uncompressed files) if rs, ok := file.(vfs.SeekableFile); ok { @@ -231,7 +231,7 @@ func (reader *Reader) serveCustomFile(ctx context.Context, w http.ResponseWriter return err } - reader.fileSizeMetric.Observe(float64(fi.Size())) + reader.fileSizeMetric.WithLabelValues(reader.vfs.Name()).Observe(float64(fi.Size())) w.Header().Set("Content-Type", contentType) w.Header().Set("Content-Length", strconv.FormatInt(fi.Size(), 10)) diff --git a/internal/serving/disk/serving.go b/internal/serving/disk/serving.go index 94ea3f23..312ed093 100644 --- a/internal/serving/disk/serving.go +++ b/internal/serving/disk/serving.go @@ -43,7 +43,7 @@ func (s *Disk) ServeNotFoundHTTP(h serving.Handler) { // New returns a serving instance that is capable of reading files // from the VFS -func New(vfs vfs.VFS, fileSizeMetric prometheus.Histogram) serving.Serving { +func New(vfs vfs.VFS, fileSizeMetric *prometheus.HistogramVec) serving.Serving { return &Disk{ reader: Reader{ fileSizeMetric: fileSizeMetric, diff --git a/internal/serving/disk/symlink/path_test.go b/internal/serving/disk/symlink/path_test.go index 8c1d19b3..5e7ea16d 100644 --- a/internal/serving/disk/symlink/path_test.go +++ b/internal/serving/disk/symlink/path_test.go @@ -21,7 +21,7 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/vfs/local" ) -var fs = vfs.Instrumented(&local.VFS{}, "local") +var fs = vfs.Instrumented(local.New("local")) type EvalSymlinksTest struct { // If dest is empty, the path is created; otherwise the dest is symlinked to the path. diff --git a/internal/serving/disk/zip/serving.go b/internal/serving/disk/zip/serving.go index 42cc8f0c..63578379 100644 --- a/internal/serving/disk/zip/serving.go +++ b/internal/serving/disk/zip/serving.go @@ -8,7 +8,7 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/metrics" ) -var instance = disk.New(vfs.Instrumented(zip.New(), "zip"), metrics.ZipServingFileSize) +var instance = disk.New(vfs.Instrumented(zip.New("zip")), metrics.VFSServingFileSize) // Instance returns a serving instance that is capable of reading files // from a zip archives opened from a URL, most likely stored in object storage |