Skip to content

Commit a00e95e

Browse files
committed
s3proxy: update the metric for local bytes read
1 parent a54ec83 commit a00e95e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

s3proxy/s3proxy.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ func (c *Cacher) Get(ctx context.Context, name string) (_ io.ReadCloser, oerr er
144144
}
145145

146146
// Check whether the file already exists locally.
147-
if rc, err := openReader(path); err == nil {
147+
if rc, size, err := openReader(path); err == nil {
148148
c.getLocalHit.Add(1)
149+
c.getLocalBytes.Add(size)
149150
return rc, nil
150151
} else if errors.Is(err, os.ErrNotExist) {
151152
c.getLocalMiss.Add(1)
@@ -178,7 +179,8 @@ func (c *Cacher) Get(ctx context.Context, name string) (_ io.ReadCloser, oerr er
178179
if _, err := c.putLocal(ctx, name, path, obj.Body); err != nil {
179180
return nil, err
180181
}
181-
return openReader(path)
182+
rc, _, err := openReader(path)
183+
return rc, err
182184
}
183185

184186
// putLocal reports whether the specified path already exists in the local
@@ -311,12 +313,12 @@ func (c *Cacher) vlogf(msg string, args ...any) {
311313
}
312314
}
313315

314-
func openReader(path string) (io.ReadCloser, error) {
316+
func openReader(path string) (_ io.ReadCloser, size int64, _ error) {
315317
data, err := os.ReadFile(path)
316318
if err != nil {
317-
return nil, err
319+
return nil, 0, err
318320
}
319-
return io.NopCloser(bytes.NewReader(data)), nil
321+
return io.NopCloser(bytes.NewReader(data)), int64(len(data)), nil
320322
}
321323

322324
func openFileSize(path string) (io.ReadCloser, int64, error) {

0 commit comments

Comments
 (0)