Skip to content

Commit 0ac45a7

Browse files
committed
metrics: fix TestMetrics flake
The disk usage counts the OPTIONS file as well. One of the values `table_cache_shards` varies depending on machine and can lead to a 1 byte difference. We fix this option in this test and show exact bytes values for disk usage so this is easier to catch (it was caught with a separate change where that 1 byte happened to make the difference between `4.5KB` and `4.6KB`).
1 parent 98c989b commit 0ac45a7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

metrics_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"testing"
1717
"time"
1818

19+
"github.com/cockroachdb/crlib/crhumanize"
1920
"github.com/cockroachdb/crlib/crstrings"
2021
"github.com/cockroachdb/datadriven"
2122
"github.com/cockroachdb/pebble/internal/base"
@@ -247,6 +248,9 @@ func TestMetrics(t *testing.T) {
247248
// Large value for determinism.
248249
MaxOpenFiles: 10000,
249250
}
251+
// Fix FileCacheShards to avoid non-determinism in disk usage (the option is
252+
// written to the OPTIONS file).
253+
opts.Experimental.FileCacheShards = 10
250254
opts.Experimental.EnableValueBlocks = func() bool { return true }
251255
opts.Experimental.ValueSeparationPolicy = func() ValueSeparationPolicy {
252256
return ValueSeparationPolicy{
@@ -508,7 +512,7 @@ func TestMetrics(t *testing.T) {
508512
return buf.String()
509513

510514
case "disk-usage":
511-
return humanize.Bytes.Uint64(d.Metrics().DiskSpaceUsage()).String()
515+
return string(crhumanize.Bytes(d.Metrics().DiskSpaceUsage(), crhumanize.Compact, crhumanize.Exact))
512516

513517
case "additional-metrics":
514518
// The asynchronous loading of table stats can change metrics, so

testdata/metrics

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Iter category stats:
184184

185185
disk-usage
186186
----
187-
3.6KB
187+
3,709B
188188

189189
batch
190190
set b 2
@@ -287,7 +287,7 @@ Iter category stats:
287287

288288
disk-usage
289289
----
290-
5.9KB
290+
6,002B
291291

292292
# Closing iter a will release one of the zombie memtables.
293293

@@ -454,7 +454,7 @@ Iter category stats:
454454

455455
disk-usage
456456
----
457-
5.2KB
457+
5,295B
458458

459459
# Closing iter b will release the last zombie sstable and the last zombie memtable.
460460

@@ -539,7 +539,7 @@ Iter category stats:
539539

540540
disk-usage
541541
----
542-
4.5KB
542+
4,588B
543543

544544
additional-metrics
545545
----

0 commit comments

Comments
 (0)