Skip to content

Commit c5714b6

Browse files
craig[bot]Nukitt
andcommitted
Merge #153929
153929: drpc,server: add support for `admin` and `timeseries` service r=shubhamdhama a=Nukitt Previously, the `admin` and `timeseries` services exposed their RPCs as HTTP REST APIs via the grpc-gateway. Now, we are migrating from the grpc-gateway to DRPC HTTP and hence all these RPCs needed to be migrated. In this patch, we add the DRPC HTTP support for all these endpoints. Epic: CRDB-48924 Fixes: #152821 and #152824 Release note: None Co-authored-by: Nukitt <[email protected]>
2 parents dc45340 + 2eae87a commit c5714b6

File tree

5 files changed

+111
-7
lines changed

5 files changed

+111
-7
lines changed

pkg/server/apiinternal/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ go_library(
44
name = "apiinternal",
55
srcs = [
66
"api_internal.go",
7+
"api_internal_admin.go",
78
"api_internal_status.go",
9+
"api_internal_ts.go",
810
],
911
importpath = "github.com/cockroachdb/cockroach/pkg/server/apiinternal",
1012
visibility = ["//visibility:public"],
@@ -16,6 +18,7 @@ go_library(
1618
"//pkg/server/serverpb",
1719
"//pkg/server/srverrors",
1820
"//pkg/settings/cluster",
21+
"//pkg/ts/tspb",
1922
"//pkg/util/httputil",
2023
"//pkg/util/log",
2124
"//pkg/util/protoutil",

pkg/server/apiinternal/api_internal.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
2020
"github.com/cockroachdb/cockroach/pkg/server/srverrors"
2121
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
22+
"github.com/cockroachdb/cockroach/pkg/ts/tspb"
2223
"github.com/cockroachdb/cockroach/pkg/util/httputil"
2324
"github.com/cockroachdb/cockroach/pkg/util/log"
2425
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
@@ -53,8 +54,10 @@ type route struct {
5354
// apiInternalServer provides REST endpoints that proxy to RPC services. It
5455
// serves as a bridge between HTTP REST clients and internal RPC services.
5556
type apiInternalServer struct {
56-
mux *mux.Router
57-
status serverpb.RPCStatusClient
57+
mux *mux.Router
58+
status serverpb.RPCStatusClient
59+
admin serverpb.RPCAdminClient
60+
timeseries tspb.RPCTimeSeriesClient
5861
}
5962

6063
// NewAPIInternalServer creates a new REST API server that proxies to internal
@@ -68,12 +71,34 @@ func NewAPIInternalServer(
6871
return nil, err
6972
}
7073

74+
admin, err := serverpb.DialAdminClient(nd, ctx, localNodeID, cs)
75+
if err != nil {
76+
return nil, err
77+
}
78+
79+
timeseries, err := rpcbase.DialRPCClient(
80+
nd,
81+
ctx,
82+
localNodeID,
83+
rpcbase.DefaultClass,
84+
tspb.NewGRPCTimeSeriesClientAdapter,
85+
tspb.NewDRPCTimeSeriesClientAdapter,
86+
cs,
87+
)
88+
if err != nil {
89+
return nil, err
90+
}
91+
7192
r := &apiInternalServer{
72-
status: status,
73-
mux: mux.NewRouter(),
93+
status: status,
94+
admin: admin,
95+
timeseries: timeseries,
96+
mux: mux.NewRouter(),
7497
}
7598

7699
r.registerStatusRoutes()
100+
r.registerAdminRoutes()
101+
r.registerTimeSeriesRoutes()
77102

78103
decoder.SetAliasTag("json")
79104
decoder.IgnoreUnknownKeys(true)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package apiinternal
7+
8+
// registerAdminRoutes sets up all admin REST endpoints.
9+
func (r *apiInternalServer) registerAdminRoutes() {
10+
routes := []route{
11+
// User and database metadata.
12+
{GET, "/_admin/v1/users", createHandler(r.admin.Users)},
13+
{GET, "/_admin/v1/databases", createHandler(r.admin.Databases)},
14+
{GET, "/_admin/v1/databases/{database}", createHandler(r.admin.DatabaseDetails)},
15+
{GET, "/_admin/v1/databases/{database}/tables/{table}", createHandler(r.admin.TableDetails)},
16+
{GET, "/_admin/v1/databases/{database}/tables/{table}/stats", createHandler(r.admin.TableStats)},
17+
{GET, "/_admin/v1/nontablestats", createHandler(r.admin.NonTableStats)},
18+
{GET, "/_admin/v1/events", createHandler(r.admin.Events)},
19+
20+
// Admin UI persisted state.
21+
{POST, "/_admin/v1/uidata", createHandler(r.admin.SetUIData)},
22+
{GET, "/_admin/v1/uidata", createHandler(r.admin.GetUIData)},
23+
24+
// Cluster-level information.
25+
{GET, "/_admin/v1/cluster", createHandler(r.admin.Cluster)},
26+
{GET, "/_admin/v1/settings", createHandler(r.admin.Settings)},
27+
{GET, "/_admin/v1/health", createHandler(r.admin.Health)},
28+
{GET, "/health", createHandler(r.admin.Health)},
29+
{GET, "/_admin/v1/liveness", createHandler(r.admin.Liveness)},
30+
31+
// Job and node management.
32+
{GET, "/_admin/v1/jobs", createHandler(r.admin.Jobs)},
33+
{GET, "/_admin/v1/jobs/{job_id}", createHandler(r.admin.Job)},
34+
{GET, "/_admin/v1/locations", createHandler(r.admin.Locations)},
35+
{GET, "/_admin/v1/queryplan", createHandler(r.admin.QueryPlan)},
36+
37+
// Range and replication utilities.
38+
{GET, "/_admin/v1/rangelog", createHandler(r.admin.RangeLog)},
39+
{GET, "/_admin/v1/rangelog/{range_id}", createHandler(r.admin.RangeLog)},
40+
{GET, "/_admin/v1/data_distribution", createHandler(r.admin.DataDistribution)},
41+
{GET, "/_admin/v1/metricmetadata", createHandler(r.admin.AllMetricMetadata)},
42+
{GET, "/_admin/v1/chartcatalog", createHandler(r.admin.ChartCatalog)},
43+
{POST, "/_admin/v1/enqueue_range", createHandler(r.admin.EnqueueRange)},
44+
45+
// Tracing utilities.
46+
{GET, "/_admin/v1/trace_snapshots", createHandler(r.admin.ListTracingSnapshots)},
47+
{POST, "/_admin/v1/trace_snapshots", createHandler(r.admin.TakeTracingSnapshot)},
48+
{GET, "/_admin/v1/trace_snapshots/{snapshot_id}", createHandler(r.admin.GetTracingSnapshot)},
49+
{POST, "/_admin/v1/traces", createHandler(r.admin.GetTrace)},
50+
{POST, "/_admin/v1/settracerecordingtype", createHandler(r.admin.SetTraceRecordingType)},
51+
52+
// Multi-tenant metadata.
53+
{GET, "/_admin/v1/tenants", createHandler(r.admin.ListTenants)},
54+
}
55+
56+
for _, route := range routes {
57+
r.mux.HandleFunc(route.path, route.handler).Methods(string(route.method))
58+
}
59+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package apiinternal
7+
8+
// registerTimeSeriesRoutes sets up all the time series REST endpoints.
9+
func (r *apiInternalServer) registerTimeSeriesRoutes() {
10+
routes := []route{
11+
{POST, "/ts/query", createHandler(r.timeseries.Query)},
12+
}
13+
14+
for _, route := range routes {
15+
r.mux.HandleFunc(route.path, route.handler).Methods(string(route.method))
16+
}
17+
}

pkg/server/server_http.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,19 @@ func (s *httpServer) setupRoutes(
225225
s.mux.Handle(authserver.DemoLoginPath, http.HandlerFunc(authnServer.DemoLogin))
226226
}
227227

228-
s.mux.Handle(apiconstants.AdminPrefix, authenticatedGWMux)
228+
s.mux.Handle(apiconstants.AdminPrefix, authenticatedAPIInternalServer)
229229

230230
// Handlers for statement diagnostic bundle download. These are special
231231
// because they return zip files, not protobufs or JSON.
232232
s.mux.Handle(apiconstants.AdminStmtBundle, stmtBundleHandlerFunc)
233233
s.mux.Handle(apiconstants.AdminTxnBundle, txnBundleHandlerFunc)
234234

235235
// The timeseries endpoint, used to produce graphs.
236-
s.mux.Handle(ts.URLPrefix, authenticatedGWMux)
236+
s.mux.Handle(ts.URLPrefix, authenticatedAPIInternalServer)
237237

238238
// Exempt the 2nd health check endpoint from authentication.
239239
// (This simply mirrors /health and exists for backward compatibility.)
240-
s.mux.Handle(apiconstants.AdminHealth, unauthenticatedGWMux)
240+
s.mux.Handle(apiconstants.AdminHealth, authenticatedAPIInternalServer)
241241
// The /_status/vars and /metrics endpoint is not authenticated either. Useful for monitoring.
242242
s.mux.Handle(apiconstants.StatusVars, http.HandlerFunc(varsHandler{metricSource, s.cfg.Settings, false /* useStaticLabels */}.handleVars))
243243
s.mux.Handle(apiconstants.MetricsPath, http.HandlerFunc(varsHandler{metricSource, s.cfg.Settings, true /* useStaticLabels */}.handleVars))

0 commit comments

Comments
 (0)