Skip to content

Commit b852857

Browse files
committed
mmaprototype: add tracing to rebalance_store test
1 parent ecd7124 commit b852857

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

pkg/kv/kvserver/allocator/mmaprototype/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ go_test(
5353
"//pkg/testutils/dd",
5454
"//pkg/util/randutil",
5555
"//pkg/util/timeutil",
56+
"//pkg/util/tracing",
5657
"@com_github_cockroachdb_datadriven//:datadriven",
5758
"@com_github_cockroachdb_errors//:errors",
5859
"@com_github_stretchr_testify//require",

pkg/kv/kvserver/allocator/mmaprototype/cluster_state_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"github.com/cockroachdb/cockroach/pkg/testutils/datapathutils"
2222
"github.com/cockroachdb/cockroach/pkg/testutils/dd"
2323
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
24+
"github.com/cockroachdb/cockroach/pkg/util/tracing"
2425
"github.com/cockroachdb/datadriven"
26+
"github.com/cockroachdb/redact"
2527
"github.com/stretchr/testify/require"
2628
)
2729

@@ -519,8 +521,13 @@ func TestClusterState(t *testing.T) {
519521
storeID := dd.ScanArg[roachpb.StoreID](t, d, "store-id")
520522
rng := rand.New(rand.NewSource(0))
521523
dsm := newDiversityScoringMemo()
522-
cs.rebalanceStores(context.Background(), storeID, rng, dsm)
523-
return printPendingChangesTest(testingGetPendingChanges(t, cs))
524+
tr := tracing.NewTracer()
525+
ctx, finishAndGet := tracing.ContextWithRecordingSpan(context.Background(), tr, "rebalance-stores")
526+
cs.rebalanceStores(ctx, storeID, rng, dsm)
527+
rec := finishAndGet()
528+
var sb redact.StringBuilder
529+
rec.SafeFormatMinimal(&sb)
530+
return sb.String() + printPendingChangesTest(testingGetPendingChanges(t, cs))
524531

525532
case "tick":
526533
seconds := dd.ScanArg[int](t, d, "seconds")

pkg/kv/kvserver/allocator/mmaprototype/testdata/cluster_state/rebalance_stores_basic

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ store-id=2 node-id=2 status=ok accepting all reported=[cpu:10, write-bandwidth:0
5555
store-id=3 node-id=3 status=ok accepting all reported=[cpu:10, write-bandwidth:0, byte-size:0] adjusted=[cpu:10, write-bandwidth:0, byte-size:0] node-reported-cpu=10 node-adjusted-cpu=10 seq=1
5656
top-k-ranges (local-store-id=1) dim=WriteBandwidth: r1
5757

58-
# TODO(tbg): maybe it'll be good to at least optionally be able to have the
59-
# trace printed in the output here.
58+
# s1 is overloaded and local, so rebalanceStores should try and succeed to shed
59+
# a lease from it.
6060
rebalance-stores store-id=1
6161
----
62+
[mmaid=1] cluster means: (stores-load [cpu:33, write-bandwidth:0, byte-size:0]) (stores-capacity [cpu:100, write-bandwidth:100, byte-size:100]) (nodes-cpu-load 33) (nodes-cpu-capacity 100)
63+
[mmaid=1] overload-continued s1 ((store=overloadUrgent worst=CPURate cpu=overloadUrgent writes=loadNormal bytes=loadNormal node=overloadUrgent high_disk=false frac_pending=0.00,0.00(true))) - within grace period
64+
[mmaid=1] start processing shedding store s1: cpu node load overloadUrgent, store load overloadUrgent, worst dim CPURate
65+
[mmaid=1] top-K[CPURate] ranges for s1 with lease on local s1: r1:[cpu:60, write-bandwidth:0, byte-size:0]
66+
[mmaid=1] result(success): shedding r1 lease from s1 to s2 [change:r1=[transfer_to=2 cids=1,2]] with resulting loads source:[cpu:40, write-bandwidth:0, byte-size:0] target:[cpu:54, write-bandwidth:0, byte-size:0] (means: [cpu:33, write-bandwidth:0, byte-size:0]) (frac_pending: (src:0.00,target:0.50) (src:4.40,target:0.00))
6267
pending(2)
6368
change-id=1 store-id=1 node-id=1 range-id=1 load-delta=[cpu:-40, write-bandwidth:0, byte-size:0] start=0s
6469
prev=(replica-id=1 type=VOTER_FULL leaseholder=true)

0 commit comments

Comments
 (0)