package vfs import ( "context" "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 { Root(ctx context.Context, path string) (Root, error) Name() string } func Instrumented(fs VFS) VFS { return &instrumentedVFS{fs: fs} } type instrumentedVFS struct { fs VFS } func (i *instrumentedVFS) increment(operation string, err error) { metrics.VFSOperations.WithLabelValues(i.fs.Name(), operation, strconv.FormatBool(err == nil)).Inc() } func (i *instrumentedVFS) log() *log.Entry { return log.WithField("vfs", i.fs.Name()) } 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 } return &instrumentedRoot{root: root, name: i.fs.Name(), rootPath: path}, nil } func (i *instrumentedVFS) Name() string { return i.fs.Name() }