diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-10-01 08:03:59 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-10-01 08:03:59 +0300 |
commit | 0f280ef9e75ceeab24722d296c78b3e6a004f981 (patch) | |
tree | 50d6359f54960b6e96d0ea43b07d720b9d630529 | |
parent | aec30ca4632f31e4921ecdc16c9f583bf57e6cbc (diff) |
Rename all zip and httprange metrics
Renames all metrics to make them easier to understand.
Adds a missing metric for number of open requests made by httprange.
-rw-r--r-- | acceptance_test.go | 19 | ||||
-rw-r--r-- | internal/httprange/http_reader.go | 13 | ||||
-rw-r--r-- | internal/httprange/transport.go | 2 | ||||
-rw-r--r-- | internal/vfs/zip/archive.go | 12 | ||||
-rw-r--r-- | internal/vfs/zip/vfs.go | 2 | ||||
-rw-r--r-- | metrics/metrics.go | 93 |
6 files changed, 82 insertions, 59 deletions
diff --git a/acceptance_test.go b/acceptance_test.go index 5b7788ce..c946167e 100644 --- a/acceptance_test.go +++ b/acceptance_test.go @@ -487,14 +487,17 @@ func TestPrometheusMetricsCanBeScraped(t *testing.T) { require.Contains(t, string(body), "gitlab_pages_serving_time_seconds_sum") 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_bucket`) - // object storage - require.Contains(t, string(body), `gitlab_pages_object_storage_backend_requests_total{status_code="206"}`) - require.Contains(t, string(body), `gitlab_pages_object_storage_backend_requests_duration_bucket`) - require.Contains(t, string(body), `gitlab_pages_object_storage_backend_httptrace_duration`) - require.Contains(t, string(body), `gitlab_pages_zip_archives_total`) - require.Contains(t, string(body), `gitlab_pages_zip_archives_currently_cached`) - require.Contains(t, string(body), `gitlab_pages_files_per_zip_archive_currently_cached`) - require.Contains(t, string(body), `gitlab_pages_files_per_zip_archive_total`) + // httprange + require.Contains(t, string(body), `gitlab_pages_httprange_requests_total{status_code="206"}`) + require.Contains(t, string(body), "gitlab_pages_httprange_requests_duration_bucket") + require.Contains(t, string(body), "gitlab_pages_httprange_trace_duration") + require.Contains(t, string(body), "gitlab_pages_httprange_open_requests") + // zip archives + require.Contains(t, string(body), "gitlab_pages_zip_opened") + require.Contains(t, string(body), "gitlab_pages_zip_cache_requests") + require.Contains(t, string(body), "gitlab_pages_zip_cached_archives") + require.Contains(t, string(body), "gitlab_pages_zip_archive_entries_cached") + require.Contains(t, string(body), "gitlab_pages_zip_opened_entries_count") } func TestDisabledRedirects(t *testing.T) { diff --git a/internal/httprange/http_reader.go b/internal/httprange/http_reader.go index 82c3189c..efb3b981 100644 --- a/internal/httprange/http_reader.go +++ b/internal/httprange/http_reader.go @@ -57,8 +57,8 @@ var httpClient = &http.Client{ Transport: &tracedTransport{ next: httptransport.NewTransportWithMetrics( "object_storage_client", - metrics.ObjectStorageBackendReqDuration, - metrics.ObjectStorageBackendReqTotal, + metrics.HTTPRangeRequestDuration, + metrics.HTTPRangeRequestsTotal, ), }, } @@ -75,14 +75,18 @@ func (r *Reader) ensureResponse() error { return err } - // TODO: add Traceln info for HTTP calls with headers and response https://gitlab.com/gitlab-org/gitlab-pages/-/issues/448 + metrics.HTTPRangeOpenRequests.Inc() + res, err := httpClient.Do(req) if err != nil { + metrics.HTTPRangeOpenRequests.Dec() return err } err = r.setResponse(res) if err != nil { + metrics.HTTPRangeOpenRequests.Dec() + // cleanup body on failure from r.setResponse to avoid memory leak res.Body.Close() } @@ -200,6 +204,9 @@ func (r *Reader) Close() error { // no need to read until the end err := r.res.Body.Close() r.res = nil + + metrics.HTTPRangeOpenRequests.Dec() + return err } diff --git a/internal/httprange/transport.go b/internal/httprange/transport.go index 1432acf9..9bb6e805 100644 --- a/internal/httprange/transport.go +++ b/internal/httprange/transport.go @@ -86,6 +86,6 @@ func newTracer(start time.Time) *httptrace.ClientTrace { } func httpTraceObserve(label string, start time.Time) { - metrics.ObjectStorageTraceDuration.WithLabelValues(label). + metrics.HTTPRangeTraceDuration.WithLabelValues(label). Observe(time.Since(start).Seconds()) } diff --git a/internal/vfs/zip/archive.go b/internal/vfs/zip/archive.go index 85c84a9f..1fec3903 100644 --- a/internal/vfs/zip/archive.go +++ b/internal/vfs/zip/archive.go @@ -63,9 +63,9 @@ func (a *zipArchive) openArchive(parentCtx context.Context) (err error) { defer func() { // checking named return err value if err != nil { - metrics.ZipServingOpenArchivesTotal.WithLabelValues("error").Inc() + metrics.ZipOpened.WithLabelValues("error").Inc() } else { - metrics.ZipServingOpenArchivesTotal.WithLabelValues("ok").Inc() + metrics.ZipOpened.WithLabelValues("ok").Inc() } }() @@ -139,8 +139,8 @@ func (a *zipArchive) readArchive() { a.archive.File = nil fileCount := float64(len(a.files)) - metrics.ZipServingFilesPerArchiveTotalCount.Add(fileCount) - metrics.ZipServingFilesPerZipArchiveCurrentlyCached.Add(fileCount) + metrics.ZipOpenedEntriesCount.Add(fileCount) + metrics.ZipArchiveEntriesCached.Add(fileCount) } func (a *zipArchive) findFile(name string) *zip.File { @@ -230,6 +230,6 @@ func (a *zipArchive) Readlink(ctx context.Context, name string) (string, error) // onEvicted called by the zipVFS.cache when an archive is removed from the cache func (a *zipArchive) onEvicted(){ - metrics.ZipServingArchivesCurrentlyCached.Dec() - metrics.ZipServingFilesPerZipArchiveCurrentlyCached.Sub(float64(len(a.files))) + metrics.ZipCachedArchives.Dec() + metrics.ZipArchiveEntriesCached.Sub(float64(len(a.files))) } diff --git a/internal/vfs/zip/vfs.go b/internal/vfs/zip/vfs.go index 9ba6f859..a84b07ec 100644 --- a/internal/vfs/zip/vfs.go +++ b/internal/vfs/zip/vfs.go @@ -92,7 +92,7 @@ func (fs *zipVFS) findOrOpenArchive(ctx context.Context, path string) (*zipArchi return nil, errAlreadyCached } metrics.ZipServingArchiveCache.WithLabelValues("miss").Inc() - metrics.ZipServingArchivesCurrentlyCached.Inc() + metrics.ZipCachedArchives.Inc() } zipArchive := archive.(*zipArchive) diff --git a/metrics/metrics.go b/metrics/metrics.go index 982112f1..b37d04d6 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -99,31 +99,36 @@ var ( Help: "The number of VFS operations", }, []string{"vfs_name", "operation", "success"}) - // ObjectStorageBackendReqTotal is the number of requests made to Object Storage by zip file serving + // HTTPRangeRequestsTotal is the number of requests made to a + // httprange.Resource by opening and/or reading from it. Mostly used by the + // internal/vfs/zip package to load archives from Object Storage. // 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." + + HTTPRangeRequestsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{ + Name: "gitlab_pages_httprange_requests_total", + Help: "The number of requests made by the zip VFS to a Resource with " + + "different status codes." + "Could be bigger than the number of requests served", }, []string{"status_code"}) - // ObjectStorageBackendReqDuration is the time it takes to get a response - // from Object Storage in seconds for zip file servings - ObjectStorageBackendReqDuration = prometheus.NewHistogramVec( + // HTTPRangeRequestDuration is the time it takes to get a response + // from an httprange.Resource hosted in object storage for a request made by + // the zip VFS + HTTPRangeRequestDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ - 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", + Name: "gitlab_pages_httprange_requests_duration", + Help: "The time (in seconds) it takes to get a response from " + + "a httprange.Resource hosted in object storage for a request " + + "made by the zip VFS", }, []string{"status_code"}, ) - // ObjectStorageTraceDuration Object Storage request responsiveness in - // seconds for different stages of an http request see httptrace.ClientTrace - ObjectStorageTraceDuration = prometheus.NewHistogramVec( + // HTTPRangeTraceDuration httprange requests duration in seconds for + // different stages of an http request (see httptrace.ClientTrace) + HTTPRangeTraceDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ - Name: "gitlab_pages_object_storage_backend_httptrace_duration", - Help: "Object Storage request tracing duration in seconds for " + + Name: "gitlab_pages_httprange_trace_duration", + Help: "httprange request tracing duration in seconds for " + "different connection stages (see Go's httptrace.ClientTrace)", Buckets: []float64{0.001, 0.005, 0.01, 0.02, 0.05, 0.100, 0.250, 0.500, 1, 2, 5, 10, 20, 50}, @@ -131,11 +136,17 @@ var ( []string{"request_stage"}, ) - // ZipServingOpenArchivesTotal is the number of zip archives that have been - // opened - ZipServingOpenArchivesTotal = prometheus.NewCounterVec( + // HTTPRangeOpenRequests is the number of open requests made by httprange.Reader + HTTPRangeOpenRequests = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "gitlab_pages_httprange_open_requests", + Help: "The number of open requests made by httprange.Reader", + + }) + + // ZipOpened is the number of zip archives that have been opened + ZipOpened = prometheus.NewCounterVec( prometheus.CounterOpts{ - Name: "gitlab_pages_zip_archives_total", + Name: "gitlab_pages_zip_opened", Help: "The total number of zip archives that have been opened", }, []string{"state"}, @@ -144,34 +155,35 @@ var ( // ZipServingArchiveCache is the number of zip archive cache hits/misses ZipServingArchiveCache = prometheus.NewCounterVec( prometheus.CounterOpts{ - Name: "gitlab_pages_zip_archives_cache", - Help: "The number of zip archives cache hits", + Name: "gitlab_pages_zip_cache_requests", + Help: "The number of zip archives cache hits/misses", }, []string{"cache"}, ) - // ZipServingArchivesCurrentlyCached is the number of zip archives currently - // in the cache - ZipServingArchivesCurrentlyCached = prometheus.NewGauge( + // ZipCachedArchives is the number of zip archives currently in the cache + ZipCachedArchives = prometheus.NewGauge( prometheus.GaugeOpts{ - Name: "gitlab_pages_zip_archives_currently_cached", + Name: "gitlab_pages_zip_cached_archives", Help: "The number of zip archives currently in the cache", }, ) - // ZipServingFilesPerZipArchiveCurrentlyCached ... - ZipServingFilesPerZipArchiveCurrentlyCached = prometheus.NewGauge( + // ZipArchiveEntriesCached is the number of files per zip archive currently + // in the cache + ZipArchiveEntriesCached = prometheus.NewGauge( prometheus.GaugeOpts{ - Name: "gitlab_pages_files_per_zip_archive_currently_cached", - Help: "The number of object storage zip archives currently in the cache", + Name: "gitlab_pages_zip_archive_entries_cached", + Help: "The number of files per zip archive currently in the cache", }, ) - // ZipServingFilesPerArchiveTotalCount over time - ZipServingFilesPerArchiveTotalCount = prometheus.NewCounter( + // ZipOpenedEntriesCount is the number of files per archive total count + // over time + ZipOpenedEntriesCount = prometheus.NewCounter( prometheus.CounterOpts{ - Name: "gitlab_pages_files_per_zip_archive_total", - Help: "The number of files per zip archive total count", + Name: "gitlab_pages_zip_opened_entries_count", + Help: "The number of files per zip archive total count over time", }, ) ) @@ -194,13 +206,14 @@ func MustRegister() { DiskServingFileSize, ServingTime, VFSOperations, - ObjectStorageBackendReqTotal, - ObjectStorageBackendReqDuration, - ObjectStorageTraceDuration, - ZipServingOpenArchivesTotal, - ZipServingFilesPerArchiveTotalCount, + HTTPRangeRequestsTotal, + HTTPRangeRequestDuration, + HTTPRangeTraceDuration, + HTTPRangeOpenRequests, + ZipOpened, + ZipOpenedEntriesCount, ZipServingArchiveCache, - ZipServingFilesPerZipArchiveCurrentlyCached, - ZipServingArchivesCurrentlyCached, + ZipArchiveEntriesCached, + ZipCachedArchives, ) } |