diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-30 09:44:54 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-30 09:44:54 +0300 |
commit | 475b1d1397752107537229dc11e1e222e64d2a98 (patch) | |
tree | db8874b46b030bd5684c52e68dd213570b3c34e5 | |
parent | 031f6a1e63b52bf18db4087da7f678428f0ffdb8 (diff) |
Add extra metric for currently cached files per archive
-rw-r--r-- | acceptance_test.go | 5 | ||||
-rw-r--r-- | internal/vfs/zip/archive.go | 4 | ||||
-rw-r--r-- | internal/vfs/zip/vfs.go | 10 | ||||
-rw-r--r-- | metrics/metrics.go | 43 |
4 files changed, 44 insertions, 18 deletions
diff --git a/acceptance_test.go b/acceptance_test.go index be47c2ab..5b7788ce 100644 --- a/acceptance_test.go +++ b/acceptance_test.go @@ -492,8 +492,9 @@ func TestPrometheusMetricsCanBeScraped(t *testing.T) { 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_object_storage_files_per_zip_archive`) - require.Contains(t, string(body), `gitlab_pages_object_storage_zip_archive_cache`) + 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`) } func TestDisabledRedirects(t *testing.T) { diff --git a/internal/vfs/zip/archive.go b/internal/vfs/zip/archive.go index 7a9bcc3d..94c5a545 100644 --- a/internal/vfs/zip/archive.go +++ b/internal/vfs/zip/archive.go @@ -138,7 +138,9 @@ func (a *zipArchive) readArchive() { // recycle memory a.archive.File = nil - metrics.ZipServingFilesPerArchiveCount.Observe(float64(len(a.files))) + fileCount := float64(len(a.files)) + metrics.ZipServingFilesPerArchiveTotalCount.Add(fileCount) + metrics.ZipServingFilesPerZipArchiveCurrentlyCached.Set(fileCount) } func (a *zipArchive) findFile(name string) *zip.File { diff --git a/internal/vfs/zip/vfs.go b/internal/vfs/zip/vfs.go index 985ec3bb..5261802c 100644 --- a/internal/vfs/zip/vfs.go +++ b/internal/vfs/zip/vfs.go @@ -30,10 +30,16 @@ type zipVFS struct { // New creates a zipVFS instance that can be used by a serving request func New() vfs.VFS { - return &zipVFS{ + zipVFS := &zipVFS{ // TODO: add cache operation callbacks https://gitlab.com/gitlab-org/gitlab-pages/-/issues/465 cache: cache.New(defaultCacheExpirationInterval, defaultCacheCleanupInterval), } + + zipVFS.cache.OnEvicted(func(s string, i interface{}) { + metrics.ZipServingArchivesCurrentlyCached.Dec() + }) + + return zipVFS } // Root opens an archive given a URL path and returns an instance of zipArchive @@ -85,8 +91,8 @@ func (fs *zipVFS) findOrOpenArchive(ctx context.Context, path string) (*zipArchi if fs.cache.Add(path, archive, cache.DefaultExpiration) != nil { return nil, errAlreadyCached } - metrics.ZipServingArchiveCache.WithLabelValues("miss").Inc() + metrics.ZipServingArchivesCurrentlyCached.Inc() } zipArchive := archive.(*zipArchive) diff --git a/metrics/metrics.go b/metrics/metrics.go index effb717b..982112f1 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -141,24 +141,39 @@ var ( []string{"state"}, ) - // ZipServingFilesPerArchiveCount - ZipServingFilesPerArchiveCount = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Name: "gitlab_pages_object_storage_files_per_zip_archive", - Help: "The number of files per zip archive", - // squared buckets up to 2^13 - Buckets: prometheus.ExponentialBuckets(1, 2, 14), - }, - ) - // ZipServingArchiveCache is the number of zip archive cache hits/misses ZipServingArchiveCache = prometheus.NewCounterVec( prometheus.CounterOpts{ - Name: "gitlab_pages_object_storage_zip_archive_cache", - Help: "The number of object storage zip archives cache hits", + Name: "gitlab_pages_zip_archives_cache", + Help: "The number of zip archives cache hits", }, []string{"cache"}, ) + + // ZipServingArchivesCurrentlyCached is the number of zip archives currently + // in the cache + ZipServingArchivesCurrentlyCached = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "gitlab_pages_zip_archives_currently_cached", + Help: "The number of zip archives currently in the cache", + }, + ) + + // ZipServingFilesPerZipArchiveCurrentlyCached ... + ZipServingFilesPerZipArchiveCurrentlyCached = 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", + }, + ) + + // ZipServingFilesPerArchiveTotalCount over time + ZipServingFilesPerArchiveTotalCount = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "gitlab_pages_files_per_zip_archive_total", + Help: "The number of files per zip archive total count", + }, + ) ) // MustRegister collectors with the Prometheus client @@ -183,7 +198,9 @@ func MustRegister() { ObjectStorageBackendReqDuration, ObjectStorageTraceDuration, ZipServingOpenArchivesTotal, - ZipServingFilesPerArchiveCount, + ZipServingFilesPerArchiveTotalCount, ZipServingArchiveCache, + ZipServingFilesPerZipArchiveCurrentlyCached, + ZipServingArchivesCurrentlyCached, ) } |