-
Notifications
You must be signed in to change notification settings - Fork 574
/
validate.go
36 lines (31 loc) · 945 Bytes
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package phlaredb
import (
"context"
"path"
"github.com/grafana/dskit/runutil"
"github.com/grafana/pyroscope/pkg/objstore/client"
"github.com/grafana/pyroscope/pkg/objstore/providers/filesystem"
"github.com/grafana/pyroscope/pkg/phlaredb/block"
"github.com/grafana/pyroscope/pkg/util"
)
// ValidateLocalBlock validates the block in the given directory is readable.
func ValidateLocalBlock(phlarectx context.Context, dir string) error {
meta, err := block.ReadMetaFromDir(dir)
if err != nil {
return err
}
bkt, err := client.NewBucket(phlarectx, client.Config{
StorageBackendConfig: client.StorageBackendConfig{
Backend: client.Filesystem,
Filesystem: filesystem.Config{
Directory: path.Dir(dir),
},
},
}, "validate")
if err != nil {
return err
}
q := NewSingleBlockQuerierFromMeta(phlarectx, bkt, meta)
defer runutil.CloseWithLogOnErr(util.Logger, q, "closing block querier")
return q.Open(phlarectx)
}