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:
authorKamil TrzciƄski <ayufan@ayufan.eu>2020-09-03 16:53:26 +0300
committerVladimir Shushlin <vshushlin@gitlab.com>2020-09-03 16:53:26 +0300
commite8a29071e5f4d0a8c35eede932cff7f4ed03adfe (patch)
tree7f62366277976df67c70fcf5a56b8080f000d98e /internal/vfs/vfs.go
parentab92a1bf2fd3d3b28498d79245f19623cec5f618 (diff)
Abstract `VFS` `Root`
Diffstat (limited to 'internal/vfs/vfs.go')
-rw-r--r--internal/vfs/vfs.go49
1 files changed, 21 insertions, 28 deletions
diff --git a/internal/vfs/vfs.go b/internal/vfs/vfs.go
index 07c99b77..9d9551a1 100644
--- a/internal/vfs/vfs.go
+++ b/internal/vfs/vfs.go
@@ -2,54 +2,47 @@ package vfs
import (
"context"
- "io"
- "os"
"strconv"
+ log "github.com/sirupsen/logrus"
+
"gitlab.com/gitlab-org/gitlab-pages/metrics"
)
// VFS abstracts the things Pages needs to serve a static site from disk.
type VFS interface {
- Lstat(ctx context.Context, name string) (os.FileInfo, error)
- Readlink(ctx context.Context, name string) (string, error)
- Open(ctx context.Context, name string) (File, error)
-}
-
-// File represents an open file, which will typically be the response body of a Pages request.
-type File interface {
- io.Reader
- io.Seeker
- io.Closer
+ Root(ctx context.Context, path string) (Root, error)
}
func Instrumented(fs VFS, name string) VFS {
- return &InstrumentedVFS{fs: fs, name: name}
+ return &instrumentedVFS{fs: fs, name: name}
}
-type InstrumentedVFS struct {
+type instrumentedVFS struct {
fs VFS
name string
}
-func (i *InstrumentedVFS) increment(operation string, err error) {
+func (i *instrumentedVFS) increment(operation string, err error) {
metrics.VFSOperations.WithLabelValues(i.name, operation, strconv.FormatBool(err == nil)).Inc()
}
-func (i *InstrumentedVFS) Lstat(ctx context.Context, name string) (os.FileInfo, error) {
- fi, err := i.fs.Lstat(ctx, name)
- i.increment("Lstat", err)
- return fi, err
+func (i *instrumentedVFS) log() *log.Entry {
+ return log.WithField("vfs", i.name)
}
-func (i *InstrumentedVFS) Readlink(ctx context.Context, name string) (string, error) {
- target, err := i.fs.Readlink(ctx, name)
- i.increment("Readlink", err)
- return target, err
-}
+func (i *instrumentedVFS) Root(ctx context.Context, path string) (Root, error) {
+ root, err := i.fs.Root(ctx, path)
+
+ i.increment("Root", err)
+ i.log().
+ WithField("path", path).
+ WithError(err).
+ Traceln("Root call")
+
+ if err != nil {
+ return nil, err
+ }
-func (i *InstrumentedVFS) Open(ctx context.Context, name string) (File, error) {
- f, err := i.fs.Open(ctx, name)
- i.increment("Open", err)
- return f, err
+ return &instrumentedRoot{root: root, name: i.name, rootPath: path}, nil
}