Skip to content

Commit bfcb953

Browse files
committed
metrics: don't use horizontal table rendering
The horizontal table rendering is very unintuitive. We no longer need it, given that we can customize both the vertical and horizontal dividers. Change the only table that is using it.
1 parent 69e4395 commit bfcb953

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

internal/ascii/table/table.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ func Int[T any](header string, width int, align Align, fn func(r T) int) Field[T
308308
})
309309
}
310310

311+
func Int64[T any](header string, width int, align Align, fn func(r T) int64) Field[T] {
312+
return makeFuncField(header, width, align, func(tupleIndex int, tuple T) string {
313+
return strconv.FormatInt(fn(tuple), 10)
314+
})
315+
}
316+
311317
func AutoIncrement[T any](header string, width int, align Align) Field[T] {
312318
return makeFuncField(header, width, align, func(tupleIndex int, tuple T) string {
313319
return strconv.Itoa(tupleIndex)

metrics.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,19 @@ var (
696696
table.Bytes("sstsz", 6, table.AlignRight, func(m *LevelMetrics) uint64 { return m.TableBytesFlushed + m.TableBytesCompacted }),
697697
table.Bytes("blobsz", 6, table.AlignRight, func(m *LevelMetrics) uint64 { return m.BlobBytesFlushed + m.BlobBytesCompacted }),
698698
)
699-
compactionKindTable = table.Define[pair[string, int64]](
700-
table.String("kind", 5, table.AlignRight, func(p pair[string, int64]) string { return p.k }),
701-
table.Count("count", 5, table.AlignRight, func(p pair[string, int64]) int64 { return p.v }),
699+
compactionKindTable = table.Define[*Metrics](
700+
table.String("kind", 5, table.AlignRight, func(m *Metrics) string { return "count" }),
701+
table.Div(),
702+
table.Int64("default", 7, table.AlignRight, func(m *Metrics) int64 { return m.Compact.DefaultCount }),
703+
table.Int64("delete", 7, table.AlignRight, func(m *Metrics) int64 { return m.Compact.DeleteOnlyCount }),
704+
table.Int64("elision", 8, table.AlignRight, func(m *Metrics) int64 { return m.Compact.ElisionOnlyCount }),
705+
table.Int64("move", 5, table.AlignRight, func(m *Metrics) int64 { return m.Compact.MoveCount }),
706+
table.Int64("read", 5, table.AlignRight, func(m *Metrics) int64 { return m.Compact.ReadCount }),
707+
table.Int64("tomb", 5, table.AlignRight, func(m *Metrics) int64 { return m.Compact.TombstoneDensityCount }),
708+
table.Int64("rewrite", 8, table.AlignRight, func(m *Metrics) int64 { return m.Compact.RewriteCount }),
709+
table.Int64("copy", 5, table.AlignRight, func(m *Metrics) int64 { return m.Compact.CopyCount }),
710+
table.Int64("multi", 6, table.AlignRight, func(m *Metrics) int64 { return m.Compact.MultiLevelCount }),
711+
table.Int64("blob", 5, table.AlignRight, func(m *Metrics) int64 { return m.Compact.BlobFileRewriteCount }),
702712
)
703713
commitPipelineInfoTableTopHeader = `COMMIT PIPELINE`
704714
commitPipelineInfoTableSubHeader = ` wals | memtables | ingestions`
@@ -880,11 +890,6 @@ func makeCompressionInfo(algorithm string, table, blob CompressionStatsForSettin
880890
return i
881891
}
882892

883-
type pair[k, v any] struct {
884-
k k
885-
v v
886-
}
887-
888893
// String pretty-prints the metrics.
889894
//
890895
// See testdata/metrics for an example.
@@ -921,19 +926,9 @@ func (m *Metrics) String() string {
921926
cur.Offset(-1, 0).WriteString("total")
922927

923928
cur = cur.NewlineReturn()
924-
compactionKindContents := []pair[string, int64]{
925-
{k: "default", v: m.Compact.DefaultCount},
926-
{k: "delete", v: m.Compact.DeleteOnlyCount},
927-
{k: "elision", v: m.Compact.ElisionOnlyCount},
928-
{k: "move", v: m.Compact.MoveCount},
929-
{k: "read", v: m.Compact.ReadCount},
930-
{k: "tomb", v: m.Compact.TombstoneDensityCount},
931-
{k: "rewrite", v: m.Compact.RewriteCount},
932-
{k: "copy", v: m.Compact.CopyCount},
933-
{k: "multi", v: m.Compact.MultiLevelCount},
934-
{k: "blob", v: m.Compact.BlobFileRewriteCount},
935-
}
936-
cur = compactionKindTable.Render(cur, table.RenderOptions{Orientation: table.Horizontally}, compactionKindContents...)
929+
cur = compactionKindTable.Render(cur, table.RenderOptions{
930+
HorizontalDividers: table.HorizontalDividers{},
931+
}, m)
937932
cur = cur.NewlineReturn()
938933

939934
commitPipelineInfoContents := commitPipelineInfo{

0 commit comments

Comments
 (0)