Files
traces/cmd/tempo-cli/cmd-list-cachesummary.go
renovate-sh-app[bot]GitHubrenovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>Oleg Kozliuk
4b24cde0e2 fix(deps): update module github.com/olekukonko/tablewriter to v1 (#5920)
* fix(deps): update module github.com/olekukonko/tablewriter to v1

| datasource | package                           | from   | to     |
| ---------- | --------------------------------- | ------ | ------ |
| go         | github.com/olekukonko/tablewriter | v0.0.5 | v1.1.2 |


Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>

* Fixed compilation errors due to breaking changes

---------

Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>
Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>
Co-authored-by: Oleg Kozliuk <[email protected]>
2026-01-05 10:05:39 +00:00

95 lines
2.2 KiB
Go

package main
import (
"fmt"
"os"
"time"
"github.com/olekukonko/tablewriter"
)
type listCacheSummaryCmd struct {
TenantID string `arg:"" help:"tenant-id within the bucket"`
backendOptions
}
func (l *listCacheSummaryCmd) Run(ctx *globalOptions) error {
r, _, c, err := loadBackend(&l.backendOptions, ctx)
if err != nil {
return err
}
windowDuration := time.Hour
results, err := loadBucket(r, c, l.TenantID, windowDuration, false)
if err != nil {
return err
}
displayCacheSummary(results)
return nil
}
func displayCacheSummary(results []blockStats) {
fmt.Println()
fmt.Println("Bloom filter shards by day and compaction level:")
columns := []string{"bloom filter age"}
out := make([][]string, 0)
bloomTable := make([][]int, 0)
for _, r := range results {
row := r.CompactionLevel
// extend rows
for len(bloomTable)-1 < int(row) {
bloomTable = append(bloomTable, make([]int, 0))
}
column := -1 * (int(time.Until(r.StartTime) / (time.Hour * 24)))
// extend column of given row
for len(bloomTable[row])-1 < column {
bloomTable[row] = append(bloomTable[row], 0)
}
// extend columns (header of bloomTable)
for i := len(columns) - 1; i <= column; i++ {
columns = append(columns, fmt.Sprintf("%d days", i))
}
if int(row) < len(bloomTable) && column < len(bloomTable[row]) {
bloomTable[row][column] += int(r.BloomShardCount)
} else {
fmt.Println("something wrong with row / column", row, column)
}
}
fmt.Println()
columnTotals := make([]int, len(columns)-1)
for i, row := range bloomTable {
line := make([]string, 0)
line = append(line, fmt.Sprintf("compaction level %d", i))
for j, column := range row {
line = append(line, fmt.Sprintf("%d", column))
columnTotals[j] += column
}
out = append(out, line)
}
columnTotalsRow := make([]string, 0, len(columns))
columnTotalsRow = append(columnTotalsRow, "total")
for _, total := range columnTotals {
columnTotalsRow = append(columnTotalsRow, fmt.Sprintf("%d", total))
}
fmt.Println()
w := tablewriter.NewWriter(os.Stdout)
w.Header(columns)
if err := w.Bulk(out); err != nil {
panic(err)
}
w.Footer(columnTotalsRow)
if err := w.Render(); err != nil {
panic(err)
}
}