Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: add store metrics info to /api/v2/nodes api #98208

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/server/api_v2_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type nodeStatus struct {

// Metrics contain the last sampled metrics for this node.
Metrics map[string]float64 `json:"metrics,omitempty"`
// StoreMetrics contain the last sampled store metrics for this node.
StoreMetrics map[roachpb.StoreID]map[string]float64 `json:"store_metrics,omitempty"`
// TotalSystemMemory is the total amount of available system memory on this
// node (or cgroup), in bytes.
TotalSystemMemory int64 `json:"total_system_memory,omitempty"`
Expand Down Expand Up @@ -116,6 +118,10 @@ func (a *apiV2SystemServer) listNodes(w http.ResponseWriter, r *http.Request) {
var resp nodesResponse
resp.Next = next
for _, n := range nodes.Nodes {
storeMetrics := make(map[roachpb.StoreID]map[string]float64)
for _, ss := range n.StoreStatuses {
storeMetrics[ss.Desc.StoreID] = ss.Metrics
}
resp.Nodes = append(resp.Nodes, nodeStatus{
NodeID: int32(n.Desc.NodeID),
Address: n.Desc.Address,
Expand All @@ -127,6 +133,7 @@ func (a *apiV2SystemServer) listNodes(w http.ResponseWriter, r *http.Request) {
ClusterName: n.Desc.ClusterName,
SQLAddress: n.Desc.SQLAddress,
Metrics: n.Metrics,
StoreMetrics: storeMetrics,
TotalSystemMemory: n.TotalSystemMemory,
NumCpus: n.NumCpus,
UpdatedAt: n.UpdatedAt,
Expand Down
11 changes: 10 additions & 1 deletion pkg/server/api_v2_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ func TestNodesV2(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

testCluster := serverutils.StartNewTestCluster(t, 3, base.TestClusterArgs{})
testCluster := serverutils.StartNewTestCluster(t, 3, base.TestClusterArgs{
ServerArgs: base.TestServerArgs{
StoreSpecs: []base.StoreSpec{
base.DefaultTestStoreSpec,
base.DefaultTestStoreSpec,
base.DefaultTestStoreSpec,
},
},
})
ctx := context.Background()
defer testCluster.Stopper().Stop(ctx)

Expand All @@ -147,5 +155,6 @@ func TestNodesV2(t *testing.T) {
for _, n := range nodesResp.Nodes {
require.Greater(t, int(n.NodeID), 0)
require.Less(t, int(n.NodeID), 4)
require.Equal(t, len(n.StoreMetrics), 3)
}
}