Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(blooms): Handle not found metas gracefully #12853

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions pkg/storage/stores/shipper/bloomshipper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/concurrency"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -388,28 +389,34 @@ func (b *BloomClient) GetMetas(ctx context.Context, refs []MetaRef) ([]Meta, err
err := concurrency.ForEachJob(ctx, len(refs), b.concurrency, func(ctx context.Context, idx int) error {
meta, err := b.GetMeta(ctx, refs[idx])
if err != nil {
return err
key := b.KeyResolver.Meta(refs[idx]).Addr()
if !b.IsObjectNotFoundErr(err) {
return fmt.Errorf("failed to get meta file %s: %w", key, err)
}
level.Error(b.logger).Log("msg", "failed to get meta file", "ref", key, "err", err)
}
results[idx] = meta
return nil
})
return results, err
}

// GetMeta fetches the meta file for given MetaRef from object storage and
// decodes the JSON data into a Meta.
// If the meta file is not found in storage or decoding fails, the empty Meta
// is returned along with the error.
func (b *BloomClient) GetMeta(ctx context.Context, ref MetaRef) (Meta, error) {
meta := Meta{
MetaRef: ref,
}
meta := Meta{MetaRef: ref}
key := b.KeyResolver.Meta(ref).Addr()
reader, _, err := b.client.GetObject(ctx, key)
if err != nil {
return Meta{}, fmt.Errorf("failed to get meta file%s: %w", key, err)
return meta, err
}
defer reader.Close()

err = json.NewDecoder(reader).Decode(&meta)
if err != nil {
return Meta{}, fmt.Errorf("failed to decode meta file %s: %w", key, err)
return meta, errors.Wrap(err, "failed to decode JSON")
}
return meta, nil
}
Expand Down
19 changes: 14 additions & 5 deletions pkg/storage/stores/shipper/bloomshipper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,20 @@ func TestBloomClient_GetMetas(t *testing.T) {
require.Equal(t, metas, []Meta{m1, m2})
})

t.Run("does not exist", func(t *testing.T) {
metas, err := c.GetMetas(ctx, []MetaRef{{}})
require.Error(t, err)
require.True(t, c.client.IsObjectNotFoundErr(err))
require.Equal(t, metas, []Meta{{}})
t.Run("does not exist - yields empty meta", func(t *testing.T) {
ref := MetaRef{
Ref: Ref{
TenantID: "tenant",
TableName: "table",
Bounds: v1.FingerprintBounds{},
StartTimestamp: 1000,
EndTimestamp: 2000,
Checksum: 1234,
},
}
metas, err := c.GetMetas(ctx, []MetaRef{ref})
require.NoError(t, err)
require.Equal(t, metas, []Meta{{MetaRef: ref}})
})
}

Expand Down
Loading