diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-10-01 08:14:56 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-10-01 08:14:56 +0300 |
commit | d0dbf04e47d919a854c9e6ad49028418a9643489 (patch) | |
tree | 380768f249b6395153b7d42c4f634906a8665a98 /internal | |
parent | 0f280ef9e75ceeab24722d296c78b3e6a004f981 (diff) |
Move metrics.ZipOpened to readArchive()
Diffstat (limited to 'internal')
-rw-r--r-- | internal/vfs/zip/archive.go | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/internal/vfs/zip/archive.go b/internal/vfs/zip/archive.go index 1fec3903..6ce6d319 100644 --- a/internal/vfs/zip/archive.go +++ b/internal/vfs/zip/archive.go @@ -60,15 +60,6 @@ func newArchive(path string, openTimeout time.Duration) *zipArchive { } func (a *zipArchive) openArchive(parentCtx context.Context) (err error) { - defer func() { - // checking named return err value - if err != nil { - metrics.ZipOpened.WithLabelValues("error").Inc() - } else { - metrics.ZipOpened.WithLabelValues("ok").Inc() - } - }() - // return early if openArchive was done already in a concurrent request select { case <-a.done: @@ -114,6 +105,7 @@ func (a *zipArchive) readArchive() { a.resource, a.err = httprange.NewResource(ctx, a.path) if a.err != nil { + metrics.ZipOpened.WithLabelValues("error").Inc() return } @@ -123,7 +115,8 @@ func (a *zipArchive) readArchive() { a.archive, a.err = zip.NewReader(a.reader, a.resource.Size) }) - if a.archive == nil { + if a.archive == nil || a.err != nil { + metrics.ZipOpened.WithLabelValues("error").Inc() return } @@ -139,6 +132,7 @@ func (a *zipArchive) readArchive() { a.archive.File = nil fileCount := float64(len(a.files)) + metrics.ZipOpened.WithLabelValues("ok").Inc() metrics.ZipOpenedEntriesCount.Add(fileCount) metrics.ZipArchiveEntriesCached.Add(fileCount) } @@ -229,7 +223,7 @@ 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.ZipCachedArchives.Dec() - metrics.ZipArchiveEntriesCached.Sub(float64(len(a.files))) +func (a *zipArchive) onEvicted() { + metrics.ZipCachedArchives.Dec() + metrics.ZipArchiveEntriesCached.Sub(float64(len(a.files))) } |