-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add profilecli command to dump the tsdb index (#3189)
This is useful connecting series to the profiles.parquet. ``` ❯ go run ./cmd/profilecli admin tsdb series ./my-block/index.tsdb {"SeriesRef":247850,"SeriesIndex":16992,"Labels":{"__name__":"process_cpu","__period_type__":"cpu","__period_unit__":"nanoseconds","__profile_type__":"process_cpu:cpu:nanoseconds:cpu:nanoseconds", ...}} [...] ```
- Loading branch information
1 parent
032c28b
commit 14bcf58
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/prometheus/prometheus/model/labels" | ||
|
||
phlaremodel "github.com/grafana/pyroscope/pkg/model" | ||
"github.com/grafana/pyroscope/pkg/phlaredb" | ||
"github.com/grafana/pyroscope/pkg/phlaredb/tsdb/index" | ||
) | ||
|
||
func tsdbSeries(ctx context.Context, path string) error { | ||
r, err := index.NewFileReader(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
it, err := phlaredb.PostingsForMatchers(r, nil, labels.MustNewMatcher(labels.MatchNotEqual, "__name__", "")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var ( | ||
lbls phlaremodel.Labels | ||
chunkMeta []index.ChunkMeta | ||
) | ||
line := struct { | ||
SeriesRef uint64 | ||
SeriesIndex *uint32 | ||
Labels json.RawMessage | ||
}{} | ||
enc := json.NewEncoder(output(ctx)) | ||
|
||
for it.Next() { | ||
if ctx.Err() != nil { | ||
return ctx.Err() | ||
} | ||
|
||
_, err = r.Series(it.At(), &lbls, &chunkMeta) | ||
if err != nil { | ||
return fmt.Errorf("error retrieving seriesRef: %w", err) | ||
} | ||
|
||
line.Labels, err = lbls.ToPrometheusLabels().MarshalJSON() | ||
if err != nil { | ||
return fmt.Errorf("error marshalling labels: %w", err) | ||
} | ||
|
||
if len(chunkMeta) > 0 { | ||
line.SeriesIndex = &chunkMeta[0].SeriesIndex | ||
} else { | ||
line.SeriesIndex = nil | ||
} | ||
line.SeriesRef = uint64(it.At()) | ||
if err := enc.Encode(&line); err != nil { | ||
return fmt.Errorf("error writing line: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |