Skip to content

Instantly share code, notes, and snippets.

@gouthamve
Created March 13, 2018 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gouthamve/7ee40d6ab5b7fb0fa0a9282ababf561e to your computer and use it in GitHub Desktop.
Save gouthamve/7ee40d6ab5b7fb0fa0a9282ababf561e to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"os"
"time"
"github.com/go-kit/kit/log"
"github.com/prometheus/tsdb"
"github.com/prometheus/tsdb/labels"
)
func main() {
tmpdir, err := ioutil.TempDir("", "test")
defer os.RemoveAll(tmpdir)
rngs := tsdb.ExponentialBlockRanges(2*60*60*1000, 10, 3)
db, err := tsdb.Open(tmpdir, log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)), nil, &tsdb.Options{
WALFlushInterval: 5 * time.Second,
RetentionDuration: 999999 * 24 * 60 * 60 * 1000,
BlockRanges: rngs,
})
checkErr(err)
for t := int64(1518912000000); t < 1520856000000; t += 10000 {
app := db.Appender()
app.Add(labels.Labels{labels.Label{"as", "bs"}}, t, 0)
checkErr(app.Commit())
time.Sleep(1 * time.Millisecond)
}
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment