diff options
-rw-r--r-- | acceptance_test.go | 2 | ||||
-rw-r--r-- | internal/httprange/http_reader.go | 6 | ||||
-rw-r--r-- | internal/httptransport/transport.go | 21 | ||||
-rw-r--r-- | internal/source/gitlab/client/client.go | 2 | ||||
-rw-r--r-- | metrics/metrics.go | 20 |
5 files changed, 19 insertions, 32 deletions
diff --git a/acceptance_test.go b/acceptance_test.go index f652f9ad..c4383c65 100644 --- a/acceptance_test.go +++ b/acceptance_test.go @@ -464,7 +464,7 @@ func TestPrometheusMetricsCanBeScraped(t *testing.T) { require.NoError(t, err) require.Contains(t, string(body), "gitlab_pages_http_in_flight_requests 0") - // TODO: remove metrics for disk sourcehttps://gitlab.com/gitlab-org/gitlab-pages/-/issues/382 + // TODO: remove metrics for disk source https://gitlab.com/gitlab-org/gitlab-pages/-/issues/382 require.Contains(t, string(body), "gitlab_pages_served_domains 0") require.Contains(t, string(body), "gitlab_pages_domains_failed_total 0") require.Contains(t, string(body), "gitlab_pages_domains_updated_total 0") diff --git a/internal/httprange/http_reader.go b/internal/httprange/http_reader.go index 9b6a8bbd..474b589f 100644 --- a/internal/httprange/http_reader.go +++ b/internal/httprange/http_reader.go @@ -47,9 +47,9 @@ var httpClient = &http.Client{ // The longest time the request can be executed Timeout: 30 * time.Minute, Transport: httptransport.NewTransportWithMetrics( - metrics.ZipFileServingReqDuration, - metrics.ZipFileServingReqTotal, - httptransport.WithMeteredRoundTripperName("httprange_client"), + "object_storage_client", + metrics.ObjectStorageBackendReqDuration, + metrics.ObjectStorageBackendReqTotal, ), } diff --git a/internal/httptransport/transport.go b/internal/httptransport/transport.go index 4f177914..8f8fa387 100644 --- a/internal/httptransport/transport.go +++ b/internal/httptransport/transport.go @@ -31,9 +31,6 @@ type meteredRoundTripper struct { counter *prometheus.CounterVec } -// Option setting for metered round tripper -type Option func(*meteredRoundTripper) - func newInternalTransport() *http.Transport { return &http.Transport{ DialTLS: func(network, addr string) (net.Conn, error) { @@ -49,25 +46,13 @@ func newInternalTransport() *http.Transport { // NewTransportWithMetrics will create a custom http.RoundTripper that can be used with an http.Client. // The RoundTripper will report metrics based on the collectors passed. -func NewTransportWithMetrics(gaugeVec *prometheus.GaugeVec, counterVec *prometheus.CounterVec, options ...Option) http.RoundTripper { - mtr := &meteredRoundTripper{ +func NewTransportWithMetrics(name string, gaugeVec *prometheus.GaugeVec, counterVec *prometheus.CounterVec) http.RoundTripper { + return &meteredRoundTripper{ next: InternalTransport, + name: name, durations: gaugeVec, counter: counterVec, } - - for _, option := range options { - option(mtr) - } - - return mtr -} - -// WithMeteredRoundTripperName adds a name to the meteredRoundTripper instance -func WithMeteredRoundTripperName(name string) func(*meteredRoundTripper) { - return func(tripper *meteredRoundTripper) { - tripper.name = name - } } // This is here because macOS does not support the SSL_CERT_FILE and diff --git a/internal/source/gitlab/client/client.go b/internal/source/gitlab/client/client.go index e06a87d1..94a0cfe5 100644 --- a/internal/source/gitlab/client/client.go +++ b/internal/source/gitlab/client/client.go @@ -56,7 +56,7 @@ func NewClient(baseURL string, secretKey []byte, connectionTimeout, jwtTokenExpi baseURL: parsedURL, httpClient: &http.Client{ Timeout: connectionTimeout, - Transport: httptransport.NewTransportWithMetrics(metrics.DomainsSourceAPICallDuration, metrics.DomainsSourceAPIReqTotal), + Transport: httptransport.NewTransportWithMetrics("gitlab_internal_api", metrics.DomainsSourceAPICallDuration, metrics.DomainsSourceAPIReqTotal), }, jwtTokenExpiry: jwtTokenExpiry, }, nil diff --git a/metrics/metrics.go b/metrics/metrics.go index 9923043b..cb4287c8 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -99,15 +99,17 @@ var ( Help: "The number of VFS operations", }, []string{"vfs_name", "operation", "success"}) - // ZipFileServingReqTotal is the number of requests made to Object Storage by zip file serving - ZipFileServingReqTotal = prometheus.NewCounterVec(prometheus.CounterOpts{ - Name: "gitlab_pages_httprange_zip_reader_requests_total", - Help: "The number of requests made to Object Storage by zip file serving with different status codes", + // ObjectStorageBackendReqTotal is the number of requests made to Object Storage by zip file serving + // Could be bigger than the number of pages served. + ObjectStorageBackendReqTotal = prometheus.NewCounterVec(prometheus.CounterOpts{ + Name: "gitlab_pages_object_storage_backend_requests_total", + Help: "The number of requests made to Object Storage by zip file serving with different status codes." + + "Could be bigger than the number of requests served", }, []string{"status_code"}) - // ZipFileServingReqDuration is the time it takes to get a response from Object Storage in seconds for zip file servings - ZipFileServingReqDuration = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "gitlab_pages_httprange_zip_reader_requests_duration", + // ObjectStorageBackendReqDuration is the time it takes to get a response from Object Storage in seconds for zip file servings + ObjectStorageBackendReqDuration = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "gitlab_pages_object_storage_backend_requests_duration", Help: "The time (in seconds) it takes to get a response from the Object Storage provider for zip file serving", }, []string{"status_code"}) ) @@ -130,7 +132,7 @@ func MustRegister() { DiskServingFileSize, ServingTime, VFSOperations, - ZipFileServingReqTotal, - ZipFileServingReqDuration, + ObjectStorageBackendReqTotal, + ObjectStorageBackendReqDuration, ) } |