Merge branch 'master' of github.com:prometheus/tsdb

pull/5805/head
Fabian Reinartz 7 years ago
commit 99d39174f6

@ -64,11 +64,6 @@ type Appendable interface {
Appender() Appender Appender() Appender
} }
// Queryable defines an entity which provides a Querier.
type Queryable interface {
Querier(mint, maxt int64) Querier
}
// BlockMeta provides meta information about a block. // BlockMeta provides meta information about a block.
type BlockMeta struct { type BlockMeta struct {
// Unique identifier for the block and its contents. Changes on compaction. // Unique identifier for the block and its contents. Changes on compaction.

@ -0,0 +1,3 @@
TODO:
- [ ] add tabular output
- [ ] break commands in separate files

@ -18,8 +18,6 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http"
_ "net/http/pprof"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -33,41 +31,36 @@ import (
"github.com/prometheus/prometheus/pkg/textparse" "github.com/prometheus/prometheus/pkg/textparse"
"github.com/prometheus/tsdb" "github.com/prometheus/tsdb"
"github.com/prometheus/tsdb/labels" "github.com/prometheus/tsdb/labels"
"github.com/spf13/cobra" "gopkg.in/alecthomas/kingpin.v2"
) )
func main() { func main() {
// Start HTTP server for pprof endpoint. var (
go http.ListenAndServe(":9999", nil) cli = kingpin.New(filepath.Base(os.Args[0]), "CLI tool for tsdb")
benchCmd = cli.Command("bench", "run benchmarks")
root := &cobra.Command{ benchWriteCmd = benchCmd.Command("write", "run a write performance benchmark")
Use: "tsdb", benchWriteOutPath = benchWriteCmd.Flag("out", "set the output path").Default("benchout/").String()
Short: "CLI tool for tsdb", benchWriteNumMetrics = benchWriteCmd.Flag("metrics", "number of metrics to read").Default("10000").Int()
} benchSamplesFile = benchWriteCmd.Arg("file", "input file with samples data, default is (../../testdata/20k.series)").Default("../../testdata/20k.series").String()
root.AddCommand(
NewBenchCommand(),
) )
flag.CommandLine.Set("log.level", "debug") switch kingpin.MustParse(cli.Parse(os.Args[1:])) {
case benchWriteCmd.FullCommand():
root.Execute() wb := &writeBenchmark{
} outPath: *benchWriteOutPath,
numMetrics: *benchWriteNumMetrics,
func NewBenchCommand() *cobra.Command { samplesFile: *benchSamplesFile,
c := &cobra.Command{ }
Use: "bench", wb.run()
Short: "run benchmarks",
} }
c.AddCommand(NewBenchWriteCommand()) flag.CommandLine.Set("log.level", "debug")
return c
} }
type writeBenchmark struct { type writeBenchmark struct {
outPath string outPath string
cleanup bool samplesFile string
numMetrics int cleanup bool
numMetrics int
storage *tsdb.DB storage *tsdb.DB
@ -77,22 +70,7 @@ type writeBenchmark struct {
mtxprof *os.File mtxprof *os.File
} }
func NewBenchWriteCommand() *cobra.Command { func (b *writeBenchmark) run() {
var wb writeBenchmark
c := &cobra.Command{
Use: "write <file>",
Short: "run a write performance benchmark",
Run: wb.run,
}
c.PersistentFlags().StringVar(&wb.outPath, "out", "benchout/", "set the output path")
c.PersistentFlags().IntVar(&wb.numMetrics, "metrics", 10000, "number of metrics to read")
return c
}
func (b *writeBenchmark) run(cmd *cobra.Command, args []string) {
if len(args) != 1 {
exitWithError(fmt.Errorf("missing file argument"))
}
if b.outPath == "" { if b.outPath == "" {
dir, err := ioutil.TempDir("", "tsdb_bench") dir, err := ioutil.TempDir("", "tsdb_bench")
if err != nil { if err != nil {
@ -123,7 +101,7 @@ func (b *writeBenchmark) run(cmd *cobra.Command, args []string) {
var metrics []labels.Labels var metrics []labels.Labels
measureTime("readData", func() { measureTime("readData", func() {
f, err := os.Open(args[0]) f, err := os.Open(b.samplesFile)
if err != nil { if err != nil {
exitWithError(err) exitWithError(err)
} }

@ -165,8 +165,7 @@ func Open(dir string, l log.Logger, r prometheus.Registerer, opts *Options) (db
return nil, err return nil, err
} }
if l == nil { if l == nil {
l = log.NewLogfmtLogger(os.Stdout) l = log.NewNopLogger()
l = log.With(l, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
} }
if opts == nil { if opts == nil {
opts = DefaultOptions opts = DefaultOptions

@ -570,6 +570,9 @@ var (
errInvalidFlag = fmt.Errorf("invalid flag") errInvalidFlag = fmt.Errorf("invalid flag")
) )
// NewIndexReader returns a new IndexReader on the given directory.
func NewIndexReader(dir string) (IndexReader, error) { return newIndexReader(dir) }
// newIndexReader returns a new indexReader on the given directory. // newIndexReader returns a new indexReader on the given directory.
func newIndexReader(dir string) (*indexReader, error) { func newIndexReader(dir string) (*indexReader, error) {
f, err := openMmapFile(filepath.Join(dir, "index")) f, err := openMmapFile(filepath.Join(dir, "index"))

Loading…
Cancel
Save