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

pkg/ui: filter metric dashboard options for tenants #97995

Merged
merged 1 commit into from
Mar 8, 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
2 changes: 2 additions & 0 deletions pkg/obsservice/obslib/httpproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func (p *ReverseHTTPProxy) Start(ctx context.Context, stop *stop.Stopper) {
OIDC: &noOIDCConfigured{},
Flags: serverpb.FeatureFlags{
IsObservabilityService: true,
// TODO(obs-infra): make conditional once obsservice becomes tenant-aware.
CanViewKvMetricDashboards: true,
},
}))
for _, path := range CRDBProxyPaths {
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,9 @@ func (s *Server) PreStart(ctx context.Context) error {
sqlServer: s.sqlServer,
db: s.db,
}), /* apiServer */
serverpb.FeatureFlags{
CanViewKvMetricDashboards: s.rpcContext.TenantID.Equal(roachpb.SystemTenantID),
}, /* flags */
); err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/server_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cockroachdb/cmux"
"github.com/cockroachdb/cockroach/pkg/rpc"
"github.com/cockroachdb/cockroach/pkg/server/debug"
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/server/status"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/ts"
Expand Down Expand Up @@ -94,6 +95,7 @@ func (s *httpServer) setupRoutes(
handleRequestsUnauthenticated http.Handler,
handleDebugUnauthenticated http.Handler,
apiServer http.Handler,
flags serverpb.FeatureFlags,
) error {
// OIDC Configuration must happen prior to the UI Handler being defined below so that we have
// the system settings initialized for it to pick up from the oidcAuthenticationServer.
Expand All @@ -117,6 +119,7 @@ func (s *httpServer) setupRoutes(
}
return nil
},
Flags: flags,
})

// The authentication mux used here is created in "allow anonymous" mode so that the UI
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ Binary built without web UI.
respBytes, err = io.ReadAll(resp.Body)
require.NoError(t, err)
expected := fmt.Sprintf(
`{"Insecure":true,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{}}`,
`{"Insecure":true,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true}}`,
build.GetInfo().Tag,
build.BinaryVersionPrefix(),
1,
Expand Down Expand Up @@ -832,7 +832,7 @@ Binary built without web UI.
{
loggedInClient,
fmt.Sprintf(
`{"Insecure":false,"LoggedInUser":"authentic_user","Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{}}`,
`{"Insecure":false,"LoggedInUser":"authentic_user","Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true}}`,
build.GetInfo().Tag,
build.BinaryVersionPrefix(),
1,
Expand All @@ -841,7 +841,7 @@ Binary built without web UI.
{
loggedOutClient,
fmt.Sprintf(
`{"Insecure":false,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{}}`,
`{"Insecure":false,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true}}`,
build.GetInfo().Tag,
build.BinaryVersionPrefix(),
1,
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/serverpb/admin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1457,4 +1457,6 @@ message SetTraceRecordingTypeResponse{}
message FeatureFlags {
// Whether the server is an instance of the Observability Service
bool is_observability_service = 1;
// Whether the logged in user is able to view KV-level metric dashboards.
bool can_view_kv_metric_dashboards = 2;
}
3 changes: 3 additions & 0 deletions pkg/server/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ func (s *SQLServerWrapper) PreStart(ctx context.Context) error {
sqlServer: s.sqlServer,
db: s.db,
}), /* apiServer */
serverpb.FeatureFlags{
CanViewKvMetricDashboards: s.rpcContext.TenantID.Equal(roachpb.SystemTenantID),
},
); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/workspaces/cluster-ui/src/util/dataFromServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// licenses/APL.txt.

import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
import IFeatureFlags = cockroach.server.serverpb.IFeatureFlags;
import FeatureFlags = cockroach.server.serverpb.FeatureFlags;

export interface DataFromServer {
Insecure: boolean;
Expand All @@ -20,7 +20,7 @@ export interface DataFromServer {
OIDCAutoLogin: boolean;
OIDCLoginEnabled: boolean;
OIDCButtonText: string;
FeatureFlags: IFeatureFlags;
FeatureFlags: FeatureFlags;
}

// Tell TypeScript about `window.dataFromServer`, which is set in a script
Expand Down
4 changes: 3 additions & 1 deletion pkg/ui/workspaces/db-console/src/redux/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { loginReducer, LoginAPIState } from "./login";
import rootSaga from "./sagas";
import { initializeAnalytics } from "./analytics";
import { DataFromServer } from "src/util/dataFromServer";
import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
import FeatureFlags = cockroach.server.serverpb.FeatureFlags;

export interface AdminUIState {
cachedData: APIReducersState;
Expand All @@ -53,7 +55,7 @@ export interface AdminUIState {

const emptyDataFromServer: DataFromServer = {
Insecure: true,
FeatureFlags: {},
FeatureFlags: new FeatureFlags(),
LoggedInUser: "",
NodeID: "",
OIDCAutoLogin: false,
Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/workspaces/db-console/src/util/dataFromServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// licenses/APL.txt.

import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
import IFeatureFlags = cockroach.server.serverpb.IFeatureFlags;
import FeatureFlags = cockroach.server.serverpb.FeatureFlags;

export interface DataFromServer {
Insecure: boolean;
Expand All @@ -20,7 +20,7 @@ export interface DataFromServer {
OIDCAutoLogin: boolean;
OIDCLoginEnabled: boolean;
OIDCButtonText: string;
FeatureFlags: IFeatureFlags;
FeatureFlags: FeatureFlags;
}
// Tell TypeScript about `window.dataFromServer`, which is set in a script
// tag in index.html, the contents of which are generated in a Go template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
import _ from "lodash";

export interface LineGraphProps extends MetricsDataComponentProps {
isKvGraph?: boolean;
title?: string;
subtitle?: string;
legend?: boolean;
Expand Down Expand Up @@ -159,6 +160,11 @@ export class LineGraph extends React.Component<LineGraphProps, {}> {
this.setNewTimeRange = this.setNewTimeRange.bind(this);
}

static defaultProps: Partial<LineGraphProps> = {
// Marking a graph as not being KV-related is opt-in.
isKvGraph: true,
};

// axis is copied from the nvd3 LineGraph component above
axis = createSelector(
(props: { children?: React.ReactNode }) => props.children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export default function (props: GraphDashboardProps) {
const { storeSources } = props;

return [
<LineGraph title="Max Changefeed Latency" sources={storeSources}>
<LineGraph
title="Max Changefeed Latency"
isKvGraph={false}
sources={storeSources}
>
<Axis units={AxisUnits.Duration} label="time">
<Metric
name="cr.node.changefeed.max_behind_nanos"
Expand All @@ -31,7 +35,11 @@ export default function (props: GraphDashboardProps) {
</Axis>
</LineGraph>,

<LineGraph title="Sink Byte Traffic" sources={storeSources}>
<LineGraph
title="Sink Byte Traffic"
isKvGraph={false}
sources={storeSources}
>
<Axis units={AxisUnits.Bytes} label="bytes">
<Metric
name="cr.node.changefeed.emitted_bytes"
Expand All @@ -41,7 +49,7 @@ export default function (props: GraphDashboardProps) {
</Axis>
</LineGraph>,

<LineGraph title="Sink Counts" sources={storeSources}>
<LineGraph title="Sink Counts" isKvGraph={false} sources={storeSources}>
<Axis units={AxisUnits.Count} label="actions">
<Metric
name="cr.node.changefeed.emitted_messages"
Expand All @@ -56,7 +64,7 @@ export default function (props: GraphDashboardProps) {
</Axis>
</LineGraph>,

<LineGraph title="Sink Timings" sources={storeSources}>
<LineGraph title="Sink Timings" isKvGraph={false} sources={storeSources}>
<Axis units={AxisUnits.Duration} label="time">
<Metric
name="cr.node.changefeed.emit_nanos"
Expand All @@ -71,7 +79,11 @@ export default function (props: GraphDashboardProps) {
</Axis>
</LineGraph>,

<LineGraph title="Changefeed Restarts" sources={storeSources}>
<LineGraph
title="Changefeed Restarts"
isKvGraph={false}
sources={storeSources}
>
<Axis units={AxisUnits.Count} label="actions">
<Metric
name="cr.node.changefeed.error_retries"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function (props: GraphDashboardProps) {
return [
<LineGraph
title="SQL Statements"
isKvGraph={false}
sources={nodeSources}
tooltip={`A moving average of the number of SELECT, INSERT, UPDATE, and DELETE statements
successfully executed per second ${tooltipSelection}.`}
Expand Down Expand Up @@ -66,6 +67,7 @@ export default function (props: GraphDashboardProps) {

<LineGraph
title="Service Latency: SQL Statements, 99th percentile"
isKvGraph={false}
tooltip={
<div>
Over the last minute, this node executed 99% of SQL statements within
Expand All @@ -92,6 +94,7 @@ export default function (props: GraphDashboardProps) {
</LineGraph>,
<LineGraph
title="SQL Statement Contention"
isKvGraph={false}
sources={nodeSources}
tooltip={`A moving average of the number of SQL statements executed per second that experienced contention ${tooltipSelection}.`}
preCalcGraphSize={true}
Expand Down Expand Up @@ -132,6 +135,7 @@ export default function (props: GraphDashboardProps) {

<LineGraph
title="Capacity"
isKvGraph={false}
sources={storeSources}
tooltip={<CapacityGraphTooltip tooltipSelection={tooltipSelection} />}
preCalcGraphSize={true}
Expand Down
Loading