Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2020-09-14 04:12:44 +0300
committerJaime Martinez <jmartinez@gitlab.com>2020-09-15 07:49:29 +0300
commit297d3a48c553b54093462068ff28543236be6649 (patch)
tree6e764327dbe1817ab3e9f48ea1ceab37279ab8c3 /metrics
parent17f10d8dbff9d228e111b99063bc71fc10695000 (diff)
Update metrics acceptance tests
Remove metrics_test.go and leave responsibility of testing to acceptance_test.go with `TestPrometheusMetricsCanBeScraped`. Update TODOs with issue links.
Diffstat (limited to 'metrics')
-rw-r--r--metrics/metrics.go1
-rw-r--r--metrics/metrics_test.go60
2 files changed, 1 insertions, 60 deletions
diff --git a/metrics/metrics.go b/metrics/metrics.go
index de4206b5..c2bf6566 100644
--- a/metrics/metrics.go
+++ b/metrics/metrics.go
@@ -5,6 +5,7 @@ import (
)
var (
+ // TODO: remove disk source metrics https://gitlab.com/gitlab-org/gitlab-pages/-/issues/382
// DomainsServed counts the total number of sites served
DomainsServed = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gitlab_pages_served_domains",
diff --git a/metrics/metrics_test.go b/metrics/metrics_test.go
deleted file mode 100644
index c65aab3c..00000000
--- a/metrics/metrics_test.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package metrics
-
-import (
- "io/ioutil"
- "net/http"
- "net/http/httptest"
- "testing"
- "time"
-
- "github.com/prometheus/client_golang/prometheus"
- "github.com/prometheus/client_golang/prometheus/promhttp"
- "github.com/prometheus/client_golang/prometheus/testutil"
- "github.com/stretchr/testify/require"
-)
-
-func TestMetricsVectorsCanBeScraped(t *testing.T) {
- reg := prometheus.NewRegistry()
-
- // vectors will only be available in /metrics after a label has been set/incremented so we can't test these in
- // TestPrometheusMetricsCanBeScraped as part of the acceptance tests
- reg.MustRegister(
- DomainsSourceAPIReqTotal,
- DomainsSourceAPICallDuration,
- ZipFileServingReqTotal,
- ZipFileServingReqDuration,
- )
-
- handler := promhttp.HandlerFor(reg, promhttp.HandlerOpts{})
- testServer := httptest.NewServer(handler)
- defer testServer.Close()
-
- DomainsSourceAPICallDuration.WithLabelValues("200").Set(float64(20 * time.Millisecond))
- DomainsSourceAPIReqTotal.WithLabelValues("200").Inc()
-
- c, err := DomainsSourceAPIReqTotal.GetMetricWithLabelValues("200")
- require.NoError(t, err)
- require.Equal(t, float64(1), testutil.ToFloat64(c))
-
- ZipFileServingReqDuration.WithLabelValues("200").Set(float64(20 * time.Millisecond))
- ZipFileServingReqTotal.WithLabelValues("200").Inc()
-
- c, err = ZipFileServingReqTotal.GetMetricWithLabelValues("200")
- require.NoError(t, err)
- require.Equal(t, float64(1), testutil.ToFloat64(c))
-
- metricFamilies, err := reg.Gather()
- require.NoError(t, err)
-
- require.Len(t, metricFamilies, 4)
-
- res, err := http.Get(testServer.URL + "/metrics")
- require.NoError(t, err)
- defer res.Body.Close()
- body, _ := ioutil.ReadAll(res.Body)
-
- require.Contains(t, string(body), `gitlab_pages_domains_source_api_requests_total{status_code="200"}`)
- require.Contains(t, string(body), `gitlab_pages_domains_source_api_call_duration{status_code="200"}`)
- require.Contains(t, string(body), `gitlab_pages_httprange_zip_reader_requests_total{status_code="200"}`)
- require.Contains(t, string(body), `gitlab_pages_httprange_zip_reader_requests_duration{status_code="200"}`)
-}