@@ -307,13 +307,12 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
307307
308308 if opt .CreateContainer {
309309 // Create bucket if it does not exist
310- metricCalls .WithLabelValues ("create-container" ).Inc ()
311- metricLastCallTimestamp .WithLabelValues ("create-container" ).SetToCurrentTime ()
312-
310+ start := time .Now ()
313311 _ , err := client .CreateContainer (ctx , opt .Container , & azblob.CreateContainerOptions {})
314312 if err != nil && ! bloberror .HasCode (err , bloberror .ContainerAlreadyExists ) {
315313 return nil , err
316314 }
315+ recordCallMetrics ("create-container" , start )
317316 }
318317
319318 b := & Backend {
@@ -399,6 +398,8 @@ func convertAzureError(err error) error {
399398}
400399
401400func (b * Backend ) doList (ctx context.Context , prefix string ) (simpleblob.BlobList , error ) {
401+ defer recordCallMetrics ("list" , time .Now ())
402+
402403 var blobs simpleblob.BlobList
403404
404405 // Runes to strip from blob names for GlobalPrefix
@@ -414,6 +415,7 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
414415 for blobPager .More () {
415416 resp , err := blobPager .NextPage (ctx )
416417 if err != nil {
418+ recordErrorMetrics ("list" , err )
417419 return nil , err
418420 }
419421
@@ -438,8 +440,6 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
438440 }
439441 }
440442
441- metricLastCallTimestamp .WithLabelValues ("list" ).SetToCurrentTime ()
442-
443443 return blobs , nil
444444}
445445
@@ -463,13 +463,14 @@ func (b *Backend) Load(ctx context.Context, name string) ([]byte, error) {
463463}
464464
465465func (b * Backend ) doLoadReader (ctx context.Context , name string ) (io.ReadCloser , error ) {
466- metricCalls .WithLabelValues ("load" ).Inc ()
467- metricLastCallTimestamp .WithLabelValues ("load" ).SetToCurrentTime ()
466+ defer recordCallMetrics ("load" , time .Now ())
468467
469468 // Download the blob's contents and ensure that the download worked properly
470469 blobDownloadResponse , err := b .client .DownloadStream (ctx , b .opt .Container , name , nil )
471470 if err = convertAzureError (err ); err != nil {
472- metricCallErrors .WithLabelValues ("load" ).Inc ()
471+ if ! errors .Is (err , os .ErrNotExist ) {
472+ recordErrorMetrics ("load" , err )
473+ }
473474 return nil , err
474475 }
475476
@@ -497,14 +498,12 @@ func (b *Backend) Store(ctx context.Context, name string, data []byte) error {
497498
498499// doStore is a convenience wrapper around doStoreReader.
499500func (b * Backend ) doStore (ctx context.Context , name string , data []byte ) (azblob.UploadStreamResponse , error ) {
500- return b .doStoreReader (ctx , name , bytes .NewReader (data ), int64 ( len ( data )) )
501+ return b .doStoreReader (ctx , name , bytes .NewReader (data ))
501502}
502503
503504// doStoreReader stores data with key name in Azure blob, using r as a source for data.
504- // The value of size may be -1, in case the size is not known.
505- func (b * Backend ) doStoreReader (ctx context.Context , name string , r io.Reader , size int64 ) (azblob.UploadStreamResponse , error ) {
506- metricCalls .WithLabelValues ("store" ).Inc ()
507- metricLastCallTimestamp .WithLabelValues ("store" ).SetToCurrentTime ()
505+ func (b * Backend ) doStoreReader (ctx context.Context , name string , r io.Reader ) (azblob.UploadStreamResponse , error ) {
506+ defer recordCallMetrics ("store" , time .Now ())
508507
509508 uploadStreamOptions := & azblob.UploadStreamOptions {
510509 Concurrency : b .opt .Concurrency ,
@@ -513,7 +512,7 @@ func (b *Backend) doStoreReader(ctx context.Context, name string, r io.Reader, s
513512 // Perform UploadStream
514513 resp , err := b .client .UploadStream (ctx , b .opt .Container , name , r , uploadStreamOptions )
515514 if err != nil {
516- metricCallErrors . WithLabelValues ("store" ). Inc ( )
515+ recordErrorMetrics ("store" , err )
517516 return azblob.UploadStreamResponse {}, err
518517 }
519518
@@ -533,8 +532,7 @@ func (b *Backend) Delete(ctx context.Context, name string) error {
533532}
534533
535534func (b * Backend ) doDelete (ctx context.Context , name string ) error {
536- metricCalls .WithLabelValues ("delete" ).Inc ()
537- metricLastCallTimestamp .WithLabelValues ("delete" ).SetToCurrentTime ()
535+ defer recordCallMetrics ("delete" , time .Now ())
538536
539537 _ , err := b .client .DeleteBlob (ctx , b .opt .Container , name , nil )
540538
@@ -543,7 +541,7 @@ func (b *Backend) doDelete(ctx context.Context, name string) error {
543541 if errors .Is (err , os .ErrNotExist ) {
544542 return nil
545543 }
546- metricCallErrors . WithLabelValues ("delete" ). Inc ( )
544+ recordErrorMetrics ("delete" , err )
547545 return err
548546 }
549547
0 commit comments