Skip to content

Commit

Permalink
Reuse Histogram objects in tsdb-chunks and tsdb-print-chunk tools (#7260
Browse files Browse the repository at this point in the history
)

Signed-off-by: Yuri Nikolic <[email protected]>
  • Loading branch information
duricanikolic authored Jan 31, 2024
1 parent 1d001c5 commit 57cb013
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tools/tsdb-chunks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func printChunksFile(filename string, printSamples bool) error {
var (
h *histogram.Histogram // reused in iteration as we just dump the value and move on
fh *histogram.FloatHistogram // reused in iteration as we just dump the value and move on
ts int64 // we declare ts here to prevent shadowing of h and fh within the loop
)
for c, err := nextChunk(cix, file); err == nil; c, err = nextChunk(cix, file) {
if printSamples {
Expand All @@ -94,7 +95,7 @@ func printChunksFile(filename string, printSamples bool) error {

fmt.Printf("Chunk #%d, sample #%d: ts: %d (%s), val: %g\n", cix, six, ts, formatTimestamp(ts), val)
case chunkenc.ValHistogram:
ts, h := it.AtHistogram(h)
ts, h = it.AtHistogram(h)
if ts < minTS {
minTS = ts
}
Expand All @@ -104,7 +105,7 @@ func printChunksFile(filename string, printSamples bool) error {

fmt.Printf("Chunk #%d, sample #%d: ts: %d (%s), val: %s\n", cix, six, ts, formatTimestamp(ts), h.String())
case chunkenc.ValFloatHistogram:
ts, fh := it.AtFloatHistogram(fh)
ts, fh = it.AtFloatHistogram(fh)
if ts < minTS {
minTS = ts
}
Expand Down
5 changes: 3 additions & 2 deletions tools/tsdb-print-chunk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ func printChunks(blockDir string, chunkRefs []string) {
var (
h *histogram.Histogram // reused in iteration as we just dump the value and move on
fh *histogram.FloatHistogram // reused in iteration as we just dump the value and move on
ts int64 // we declare ts here to prevent shadowing of h and fh within the loop
)
for valType := it.Next(); valType != chunkenc.ValNone; valType = it.Next() {
switch valType {
case chunkenc.ValFloat:
ts, v := it.At()
fmt.Printf("%g\t%d (%s)\n", v, ts, timestamp.Time(ts).UTC().Format(time.RFC3339Nano))
case chunkenc.ValHistogram:
ts, h := it.AtHistogram(h)
ts, h = it.AtHistogram(h)
fmt.Printf("%s\t%d (%s)\n", h.String(), ts, timestamp.Time(ts).UTC().Format(time.RFC3339Nano))
case chunkenc.ValFloatHistogram:
ts, fh := it.AtFloatHistogram(fh)
ts, fh = it.AtFloatHistogram(fh)
fmt.Printf("%s\t%d (%s)\n", fh.String(), ts, timestamp.Time(ts).UTC().Format(time.RFC3339Nano))
default:
fmt.Printf("skipping unsupported value type %v\n", valType)
Expand Down

0 comments on commit 57cb013

Please sign in to comment.