Skip to content

Commit

Permalink
db: improve metrics formatting
Browse files Browse the repository at this point in the history
This change improves the formatting of the Pebble metrics:
 - we no longer try to artificially fit non-tabular information in a
   single table
 - all byte figures end in B/KB/MB/etc
 - counts and corresponding sizes are grouped together
 - flushable ingests information moved under ingestions

These metrics are periodically logged and can be obtained through the
db console as well.

Release note: Pebble metrics formatting improvements; tools that parse
these logs might need updating.

Fixes #1473.
  • Loading branch information
RaduBerinde committed Jul 18, 2023
1 parent bf5f4c4 commit 628c410
Show file tree
Hide file tree
Showing 13 changed files with 1,142 additions and 573 deletions.
6 changes: 6 additions & 0 deletions internal/humanize/humanize.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ var IEC = config{1024, []string{" B", " K", " M", " G", " T", " P", " E"}}
// SI produces human readable representations of integer values in SI units.
var SI = config{1000, []string{"", " K", " M", " G", " T", " P", " E"}}

// Bytes produces human readable representations of byte values in IEC units.
var Bytes = config{1024, []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}}

// Count produces human readable representations of unitless values in SI units.
var Count = config{1000, []string{"", "K", "M", "G", "T", "P", "E"}}

// Int64 produces a human readable representation of the value.
func (c *config) Int64(s int64) FormattedString {
if s < 0 {
Expand Down
38 changes: 38 additions & 0 deletions internal/humanize/humanize_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.

package humanize

import (
"bytes"
"fmt"
"strconv"
"strings"
"testing"

"github.com/cockroachdb/datadriven"
)

func TestHumanize(t *testing.T) {
datadriven.RunTest(t, "testdata/humanize", func(t *testing.T, td *datadriven.TestData) string {
var c config
switch td.Cmd {
case "bytes":
c = Bytes
case "count":
c = Count
default:
td.Fatalf(t, "invalid command %q", td.Cmd)
}
var buf bytes.Buffer
for _, row := range strings.Split(td.Input, "\n") {
val, err := strconv.ParseInt(row, 10, 64)
if err != nil {
td.Fatalf(t, "error parsing %q: %v", row, err)
}
fmt.Fprintf(&buf, "%s\n", c.Int64(val))
}
return buf.String()
})
}
49 changes: 49 additions & 0 deletions internal/humanize/testdata/humanize
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
bytes
0
1
9
99
123
123456
12345678
1234567890
1234567890123
123456789012345
123456789012345678
----
0B
1B
9B
99B
123B
121KB
12MB
1.1GB
1.1TB
112TB
110PB

count
0
1
9
99
123
123456
12345678
1234567890
1234567890123
123456789012345
123456789012345678
----
0
1
9
99
123
124K
12M
1.2G
1.2T
124T
124P
Loading

0 comments on commit 628c410

Please sign in to comment.