diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-06-05 11:31:18 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-06-05 11:31:18 +0300 |
commit | e96f9d00469050d3548ee45928b2a5b6733a3a7d (patch) | |
tree | 25dd18901d9e23e08c275ee6c896c06ae63dfe14 /internal/serving | |
parent | c877296b468e4a828da27f4fd47c3e17eb7e2e1d (diff) |
Use histograms instead of gagues
Removed test assertion for metric as histograms are not collectors
so we can't really test it. Left the test though as it's still valuable.
Diffstat (limited to 'internal/serving')
-rw-r--r-- | internal/serving/disk/reader.go | 6 | ||||
-rw-r--r-- | internal/serving/disk/serving_test.go | 5 |
2 files changed, 3 insertions, 8 deletions
diff --git a/internal/serving/disk/reader.go b/internal/serving/disk/reader.go index 949dd4e0..83fe3378 100644 --- a/internal/serving/disk/reader.go +++ b/internal/serving/disk/reader.go @@ -17,7 +17,7 @@ import ( // Reader is a disk access driver type Reader struct { - fileSizeMetric *prometheus.GaugeVec + fileSizeMetric *prometheus.HistogramVec } func (reader *Reader) tryFile(h serving.Handler) error { @@ -144,7 +144,7 @@ func (reader *Reader) serveFile(w http.ResponseWriter, r *http.Request, origPath return err } - reader.fileSizeMetric.With(prometheus.Labels{"serving_type": "disk", "content_type": contentType}).Set(float64(fi.Size())) + reader.fileSizeMetric.With(prometheus.Labels{"serving_type": "disk", "content_type": contentType}).Observe(float64(fi.Size())) w.Header().Set("Content-Type", contentType) http.ServeContent(w, r, origPath, fi.ModTime(), file) @@ -172,7 +172,7 @@ func (reader *Reader) serveCustomFile(w http.ResponseWriter, r *http.Request, co return err } - reader.fileSizeMetric.With(prometheus.Labels{"serving_type": "disk", "content_type": contentType}).Set(float64(fi.Size())) + reader.fileSizeMetric.With(prometheus.Labels{"serving_type": "disk", "content_type": contentType}).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_test.go b/internal/serving/disk/serving_test.go index 01a9a775..6398700d 100644 --- a/internal/serving/disk/serving_test.go +++ b/internal/serving/disk/serving_test.go @@ -6,12 +6,9 @@ import ( "net/http/httptest" "testing" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitlab-pages/internal/serving" - "gitlab.com/gitlab-org/gitlab-pages/metrics" ) func TestDisk_ServeFileHTTP(t *testing.T) { @@ -38,6 +35,4 @@ func TestDisk_ServeFileHTTP(t *testing.T) { require.NoError(t, err) require.Contains(t, string(body), "HTML Document") - gaugeValue := testutil.ToFloat64(metrics.ServingFileSize.With(prometheus.Labels{"serving_type": "disk", "content_type": resp.Header.Get("Content-Type")})) - require.Greater(t, gaugeValue, float64(0)) } |