-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
97412: server: introduce CriticalNodes rpc r=zachlite a=zachlite Since #90016, we've had the ability to generate multi-tenant replication reports via `spanconfig.Reporter.SpanConfigConformance()`. This commit leverages #90016 to provide multi-tenant friendly observability of nodes whose replicas are unavailable or underreplicated, and are therefore considered critical nodes. A new `CriticalNodes` rpc is available via HTTP. The response includes a list of node descriptors that are considered critical, and the corresponding SpanConfigConformanceReport which includes details of non-conforming ranges contributing to the criticality. Epic: https://cockroachlabs.atlassian.net/browse/CRDB-10630 Release note: None Co-authored-by: zachlite <zachlite@gmail.com>
- Loading branch information
Showing
6 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package server | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/config/zonepb" | ||
"github.com/cockroachdb/cockroach/pkg/server/serverpb" | ||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCriticalNodes(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
testCluster := serverutils.StartNewTestCluster(t, 3, base.TestClusterArgs{ | ||
ServerArgs: base.TestServerArgs{ | ||
Knobs: base.TestingKnobs{Server: &TestingKnobs{ | ||
DefaultSystemZoneConfigOverride: zonepb.DefaultZoneConfigRef(), | ||
}}, | ||
}, | ||
}) | ||
s := testCluster.Server(0).TenantStatusServer().(serverpb.StatusServer) | ||
ctx := context.Background() | ||
defer testCluster.Stopper().Stop(ctx) | ||
|
||
// Add a table, and alter its zone config to something | ||
// that can't be satisfied, given this is a 3-node cluster. | ||
db := testCluster.ServerConn(0) | ||
_, err := db.Exec("CREATE TABLE test (x int PRIMARY KEY)") | ||
require.NoError(t, err) | ||
_, err = db.Exec("ALTER TABLE test CONFIGURE ZONE USING num_replicas = 5;") | ||
require.NoError(t, err) | ||
|
||
testutils.SucceedsWithin(t, func() error { | ||
res, err := s.CriticalNodes(ctx, &serverpb.CriticalNodesRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
if res.Report.IsEmpty() { | ||
return errors.Errorf( | ||
"expected report to not be empty, got: {over: %d, under: %d, violating: %d, unavailable: %d}", | ||
len(res.Report.OverReplicated), | ||
len(res.Report.UnderReplicated), | ||
len(res.Report.ViolatingConstraints), | ||
len(res.Report.Unavailable), | ||
) | ||
} | ||
|
||
// We should expect all 3 nodes to be critical, because they all contain | ||
// a replica for the under-replicated range. | ||
require.Equal(t, 3, len(res.CriticalNodes)) | ||
return nil | ||
}, 2*time.Minute) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters