Skip to content

Commit 46255c8

Browse files
craig[bot]wenyihu6kvoliannrpom
committed
107075: asim: add random predefined cluster config selection r=kvoli a=wenyihu6 This patch takes the first step towards a randomized framework by enabling asim testing to randomly select a cluster information configuration from a set of predefined choices. These choices are hardcoded and represent common cluster configurations. TestRandomized now takes in `true` for randOptions.cluster to enable random cluster config selection. This provides two modes for cluster generation: 1. Default: currently set to 3 nodes and 1 store per node 2. Random: randomly select a predefined cluster info Part of: cockroachdb#106311 Release note: None 107967: kvserver: ignore lease validity when checking lease preferences r=erikgrinaker,andrewbaptist a=kvoli In cockroachdb#107507, we began eagerly enqueuing into the replicate queue, when acquiring a replica acquired a new lease which violated lease preferences. Lease preferences were only considered violated when the lease itself was valid. In cockroachdb#107507, we saw that it is uncommon, but possible for an invalid lease to be acquired, violate lease preferences and not be enqueued as a result. The end result was a leaseholder violating the applied lease preferences which would not be resolved until the next scanner cycle. Update the eager enqueue check to only check that the replica is the incoming leaseholder when applying the lease, and that the replica violates the applied lease preferences. Note the purgatory error introduced in cockroachdb#107507, still checks that the lease is valid and owned by the store before proceeding. It is a condition that the lease must be valid+owned by the store to have a change planned, so whilst it is possible the lease becomes invalid somewhere in-between planning, when the replica applies a valid lease, it will still be enqueued so purgatory is unnecessary. Fixes: cockroachdb#107862 Release note: None 107984: roachtest: bugfix testeng grafana link missing cluster name r=renatolabs a=annrpom Previously, the testeng grafana link generated after a roachtest failure directed the user to cockroachlabs.com due to a missing cluster name from the link. This patch should fix this issue by getting the cluster name from a `*githubIssues.cluster.name` instead of the `clusterName` from roachtest/cluster.go. Fixes: cockroachdb#107894 Release note (bug fix): The link to testeng grafana that is generated on a roachtest failure should now properly direct to grafana. Co-authored-by: wenyihu6 <[email protected]> Co-authored-by: Austen McClernon <[email protected]> Co-authored-by: Annie Pompa <[email protected]>
4 parents 602bc79 + 7a6867c + 92f268a + abd1e0d commit 46255c8

File tree

14 files changed

+156
-51
lines changed

14 files changed

+156
-51
lines changed

pkg/cmd/roachtest/github.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ func generateHelpCommand(
6060
"How To Investigate (internal)",
6161
"https://cockroachlabs.atlassian.net/l/c/SSSBr8c7",
6262
)(renderer)
63-
issues.HelpCommandAsLink(
64-
"Grafana",
65-
fmt.Sprintf("https://go.crdb.dev/p/roachfana/%s/%d/%d", clusterName, start.UnixMilli(), end.UnixMilli()),
66-
)(renderer)
63+
// An empty clusterName corresponds to a cluster creation failure
64+
if clusterName != "" {
65+
issues.HelpCommandAsLink(
66+
"Grafana",
67+
fmt.Sprintf("https://go.crdb.dev/p/roachfana/%s/%d/%d", clusterName, start.UnixMilli(), end.UnixMilli()),
68+
)(renderer)
69+
}
6770
}
6871
}
6972

@@ -131,6 +134,7 @@ func (g *githubIssues) createPostRequest(
131134

132135
issueOwner := spec.Owner
133136
issueName := testName
137+
issueClusterName := ""
134138

135139
messagePrefix := ""
136140
var infraFlake bool
@@ -202,6 +206,7 @@ func (g *githubIssues) createPostRequest(
202206
// Hence, we only emit when arch was unspecified.
203207
clusterParams[roachtestPrefix("arch")] = string(g.cluster.arch)
204208
}
209+
issueClusterName = g.cluster.name
205210
}
206211

207212
issueMessage := messagePrefix + message
@@ -218,7 +223,7 @@ func (g *githubIssues) createPostRequest(
218223
Artifacts: artifacts,
219224
ExtraLabels: labels,
220225
ExtraParams: clusterParams,
221-
HelpCommand: generateHelpCommand(clusterName, start, end),
226+
HelpCommand: generateHelpCommand(issueClusterName, start, end),
222227
}, nil
223228
}
224229

pkg/cmd/roachtest/github_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@ func TestCreatePostRequest(t *testing.T) {
184184
}
185185

186186
ti := &testImpl{
187-
spec: testSpec,
188-
l: nilLogger(),
187+
spec: testSpec,
188+
l: nilLogger(),
189+
start: time.Date(2023, time.July, 21, 16, 34, 3, 817, time.UTC),
190+
end: time.Date(2023, time.July, 21, 16, 42, 13, 137, time.UTC),
189191
}
190192

191-
testClusterImpl := &clusterImpl{spec: clusterSpec, arch: vm.ArchAMD64}
193+
testClusterImpl := &clusterImpl{spec: clusterSpec, arch: vm.ArchAMD64, name: "foo"}
192194
vo := vm.DefaultCreateOpts()
193195
vmOpts := &vo
194196

@@ -220,6 +222,11 @@ func TestCreatePostRequest(t *testing.T) {
220222
req, err := github.createPostRequest("github_test", ti.start, ti.end, testSpec, c.failure, "message")
221223
assert.NoError(t, err, "Expected no error in createPostRequest")
222224

225+
r := &issues.Renderer{}
226+
req.HelpCommand(r)
227+
file := fmt.Sprintf("help_command_createpost_%d.txt", idx+1)
228+
echotest.Require(t, r.String(), filepath.Join("testdata", file))
229+
223230
if c.expectedParams != nil {
224231
require.Equal(t, c.expectedParams, req.ExtraParams)
225232
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
echo
2+
----
3+
----
4+
5+
6+
See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)
7+
8+
9+
10+
See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)
11+
12+
13+
14+
See: [Grafana](https://go.crdb.dev/p/roachfana/foo/1689957243000/1689957733000)
15+
16+
----
17+
----
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
echo
2+
----
3+
----
4+
5+
6+
See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)
7+
8+
9+
10+
See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)
11+
12+
13+
14+
See: [Grafana](https://go.crdb.dev/p/roachfana/foo/1689957243000/1689957733000)
15+
16+
----
17+
----
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
echo
2+
----
3+
----
4+
5+
6+
See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)
7+
8+
9+
10+
See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)
11+
12+
----
13+
----
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
echo
2+
----
3+
----
4+
5+
6+
See: [roachtest README](https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/roachtest/README.md)
7+
8+
9+
10+
See: [How To Investigate \(internal\)](https://cockroachlabs.atlassian.net/l/c/SSSBr8c7)
11+
12+
13+
14+
See: [Grafana](https://go.crdb.dev/p/roachfana/foo/1689957243000/1689957733000)
15+
16+
----
17+
----

pkg/kv/kvserver/allocator/plan/replicate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,8 @@ func (rp ReplicaPlanner) shedLeaseTarget(
963963
liveVoters, _ := rp.storePool.LiveAndDeadReplicas(
964964
existingVoters, false /* includeSuspectAndDrainingStores */)
965965
preferred := rp.allocator.PreferredLeaseholders(rp.storePool, conf, liveVoters)
966-
if len(preferred) > 0 && repl.LeaseViolatesPreferences(ctx) {
966+
if len(preferred) > 0 &&
967+
repl.LeaseViolatesPreferences(ctx) {
967968
return nil, CantTransferLeaseViolatingPreferencesError{RangeID: desc.RangeID}
968969
}
969970
return nil, nil

pkg/kv/kvserver/asim/tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ go_library(
3636
"assert.go",
3737
"default_settings.go",
3838
"rand_framework.go",
39+
"rand_gen.go",
3940
],
4041
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/tests",
4142
visibility = ["//visibility:public"],

pkg/kv/kvserver/asim/tests/rand_framework.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (f randTestingFramework) getCluster() gen.ClusterGen {
5050
if !f.s.randOptions.cluster {
5151
return defaultBasicClusterGen()
5252
}
53-
return gen.BasicCluster{}
53+
return f.randomClusterInfoGen(f.s.randSource)
5454
}
5555

5656
func (f randTestingFramework) getRanges() gen.RangeGen {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2023 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.txt.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0, included in the file
9+
// licenses/APL.txt.
10+
11+
package tests
12+
13+
import (
14+
"math/rand"
15+
16+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/gen"
17+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/state"
18+
)
19+
20+
// randomClusterInfoGen returns a randomly picked predefined configuration.
21+
func (f randTestingFramework) randomClusterInfoGen(randSource *rand.Rand) gen.LoadedCluster {
22+
chosenIndex := randSource.Intn(len(state.ClusterOptions))
23+
chosenType := state.ClusterOptions[chosenIndex]
24+
return loadClusterInfo(chosenType)
25+
}

0 commit comments

Comments
 (0)