MCPcopy
hub / github.com/grafana/tempo / ListBlocks

Method ListBlocks

tempodb/backend/azure/azure.go:203–262  ·  view source on GitHub ↗

ListBlocks implements backend.Reader

(ctx context.Context, tenant string)

Source from the content-addressed store, hash-verified

201
202// ListBlocks implements backend.Reader
203func (rw *Azure) ListBlocks(ctx context.Context, tenant string) ([]uuid.UUID, []uuid.UUID, error) {
204 ctx, span := tracer.Start(ctx, "V2.ListBlocks")
205 defer span.End()
206
207 var (
208 blockIDs = make([]uuid.UUID, 0, 1000)
209 compactedBlockIDs = make([]uuid.UUID, 0, 1000)
210 keypath = backend.KeyPathWithPrefix(backend.KeyPath{tenant}, rw.cfg.Prefix)
211 parts []string
212 id uuid.UUID
213 )
214
215 prefix := path.Join(keypath...)
216 if len(prefix) > 0 {
217 prefix += dir
218 }
219
220 pager := rw.containerClient.NewListBlobsFlatPager(&container.ListBlobsFlatOptions{
221 Include: container.ListBlobsInclude{},
222 Prefix: &prefix,
223 })
224
225 for pager.More() {
226 page, err := pager.NextPage(ctx)
227 if err != nil {
228 return nil, nil, fmt.Errorf("iterating objects: %w", err)
229 }
230
231 for _, b := range page.Segment.BlobItems {
232 if b.Name == nil {
233 continue
234 }
235
236 obj := strings.TrimPrefix(strings.TrimSuffix(*b.Name, dir), prefix)
237 parts = strings.Split(obj, "/")
238
239 // ie: <blockID>/meta.json
240 if len(parts) != 2 {
241 continue
242 }
243
244 if parts[1] != backend.MetaName && parts[1] != backend.CompactedMetaName {
245 continue
246 }
247
248 id, err = uuid.Parse(parts[0])
249 if err != nil {
250 return nil, nil, err
251 }
252
253 switch parts[1] {
254 case backend.MetaName:
255 blockIDs = append(blockIDs, id)
256 case backend.CompactedMetaName:
257 compactedBlockIDs = append(compactedBlockIDs, id)
258 }
259 }
260 }

Callers

nothing calls this directly

Calls 5

KeyPathWithPrefixFunction · 0.92
NextPageMethod · 0.80
StartMethod · 0.65
JoinMethod · 0.65
ParseMethod · 0.65

Tested by

no test coverage detected