From af177d9708848ee8841108c237ff366d84455f9c Mon Sep 17 00:00:00 2001 From: Paul Hewlett Date: Thu, 18 Jul 2024 15:08:29 +0100 Subject: [PATCH] Flaky blobs caps systemtest AB#5311 --- azblob/list.go | 33 ++++++++++++++++++++++++--------- azblob/logger.go | 11 +++++++++++ azblob/storer.go | 2 ++ 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 azblob/logger.go diff --git a/azblob/list.go b/azblob/list.go index 48f845c..9d81fe3 100644 --- a/azblob/list.go +++ b/azblob/list.go @@ -13,15 +13,28 @@ import ( // Count counts the number of blobs filtered by the given tags filter func (azp *Storer) Count(ctx context.Context, tagsFilter string, opts ...Option) (int64, error) { - - logger.Sugar.Debugf("Count") - - r, err := azp.FilteredList(ctx, tagsFilter, opts...) - if err != nil { - return 0, err - } - - return int64(len(r.Items)), nil + log := logger.Sugar.FromContext(ctx) + defer log.close() + + log.Debugf("Count") + + var count int64 + var m string + opts = append(opts, WithListMarker(&m)) + + for { + r, err := azp.FilteredList(ctx, tagsFilter, opts...) + if err != nil { + return 0, err + } + count += int64(len(r.Items)) + log.Debugf("Count %d (%v)", count, r.Marker) + if r.Marker == nil { + break + } + } + log.Debugf("Count %d", count) + return count, nil } type FilterResponse struct { @@ -57,6 +70,8 @@ type FilterResponse struct { // // Returns all blobs with the specific tag filter. func (azp *Storer) FilteredList(ctx context.Context, tagsFilter string, opts ...Option) (*FilterResponse, error) { + log := logger.Sugar.FromContext(ctx) + defer log.close() span, ctx := tracing.StartSpanFromContext(ctx, "FilteredList") defer span.Finish() diff --git a/azblob/logger.go b/azblob/logger.go new file mode 100644 index 0000000..15db966 --- /dev/null +++ b/azblob/logger.go @@ -0,0 +1,11 @@ +package azbus + +import ( + "github.com/datatrails/go-datatrails-common/logger" +) + +const ( + DebugLevel = logger.DebugLevel +) + +type Logger = logger.Logger diff --git a/azblob/storer.go b/azblob/storer.go index 51822fd..8aa582a 100644 --- a/azblob/storer.go +++ b/azblob/storer.go @@ -27,6 +27,8 @@ type Storer struct { containerURL string containerClient *ContainerClient serviceClient *ServiceClient + + log Logger } // New returns new az blob read/write object