Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…db#89293

86251: ui, obsservice: add feature flags to db console r=maryliag,abarganier a=dhartunian

This commit adds feature flags to the initial data that DB Console loads from
the backend server. The purpose of this is to enable development on `master` of
features that can be deployed prior to the release of a DB version, and to
allow for the UI to run against various backends (primarily: obs service) with
different capabilities and be able to selectively enable UI components to
match.

The feature flags are defined in `admin.proto` using the same pattern that's
implemented in our managed service, and are available via a Typescript
interface from the compiled protobuf. This couples us a little bit to the
relevant backend via the protobuf. However, if we treat the flag list as
append-only the UI should always remain backwards compatible with this payload.

Resolves cockroachdb#84299

Release note: None

89237: sql: require `CREATE` privilege on a schema to create udf r=chengxiong-ruan a=chengxiong-ruan

A user must have `CREATE` privilege on a schema to create a user-defined function. Funny that I took it for granted while reviewing the udf doc PR :(

Release note: None
Release justification: necessary bug fix and low risk.

89248: vendor: bump Pebble to 518ead0d41bb r=jbowens a=nicktrav

```
518ead0d build: remove vendor directory
dea76ba4 db: add IteratorStats.Merge
```

Release note: None.

89293: logictestccl: fix flakey test r=ajwerner a=ajwerner

We cannot query the lease table for its entries -- they are affected by background work.

Release note: None

Co-authored-by: David Hartunian <[email protected]>
Co-authored-by: Chengxiong Ruan <[email protected]>
Co-authored-by: Nick Travers <[email protected]>
Co-authored-by: Andrew Werner <[email protected]>
  • Loading branch information
5 people committed Oct 4, 2022
5 parents 7098b09 + 02fc201 + 8f55e1b + bb8f53f + 0fd5930 commit 54e81fc
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 30 deletions.
6 changes: 3 additions & 3 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,10 @@ def go_deps():
patches = [
"@com_github_cockroachdb_cockroach//build/patches:com_github_cockroachdb_pebble.patch",
],
sha256 = "ef378b3bd97f3a9a69dba1f1228af97cf28c1e1bd0a9818da19c7638bd08bed9",
strip_prefix = "github.com/cockroachdb/[email protected]20220930163150-781ebeecebd2",
sha256 = "387907b742706c699ae4e1eecbb8afe576004cb5460da2fe30b7f4d7d77503ed",
strip_prefix = "github.com/cockroachdb/[email protected]20221003221406-518ead0d41bb",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20220930163150-781ebeecebd2.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20221003221406-518ead0d41bb.zip",
],
)
go_repository(
Expand Down
2 changes: 1 addition & 1 deletion build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/go-test-teamcity/com_github_cockroachdb_go_test_teamcity-v0.0.0-20191211140407-cff980ad0a55.zip": "bac30148e525b79d004da84d16453ddd2d5cd20528e9187f1d7dac708335674b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.13.0.zip": "b3d43d8f95edf65f73a5348f29e1159823cac64b148f8d3bb48340bf55d70872",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20211118104740-dabe8e521a4f.zip": "1972c3f171f118add3fd9e64bcea6cbb9959a3b7fa0ada308e8a7310813fea74",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20220930163150-781ebeecebd2.zip": "ef378b3bd97f3a9a69dba1f1228af97cf28c1e1bd0a9818da19c7638bd08bed9",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20221003221406-518ead0d41bb.zip": "387907b742706c699ae4e1eecbb8afe576004cb5460da2fe30b7f4d7d77503ed",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.3.zip": "7778b1e4485e4f17f35e5e592d87eb99c29e173ac9507801d000ad76dd0c261e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/returncheck/com_github_cockroachdb_returncheck-v0.0.0-20200612231554-92cdbca611dd.zip": "ce92ba4352deec995b1f2eecf16eba7f5d51f5aa245a1c362dfe24c83d31f82b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/sentry-go/com_github_cockroachdb_sentry_go-v0.6.1-cockroachdb.2.zip": "fbb2207d02aecfdd411b1357efe1192dbb827959e36b7cab7491731ac55935c9",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require (
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
github.com/cockroachdb/gostdlib v1.13.0
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f
github.com/cockroachdb/pebble v0.0.0-20220930163150-781ebeecebd2
github.com/cockroachdb/pebble v0.0.0-20221003221406-518ead0d41bb
github.com/cockroachdb/redact v1.1.3
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
github.com/cockroachdb/stress v0.0.0-20220803192808-1806698b1b7b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ github.com/cockroachdb/gostdlib v1.13.0/go.mod h1:eXX95p9QDrYwJfJ6AgeN9QnRa/lqqi
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f h1:6jduT9Hfc0njg5jJ1DdKCFPdMBrp/mdZfCpa5h+WM74=
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/pebble v0.0.0-20220930163150-781ebeecebd2 h1:Q+3tj38xdrE+33gHXIqm+UQkKV2Rw77GhRZjRuvTc8o=
github.com/cockroachdb/pebble v0.0.0-20220930163150-781ebeecebd2/go.mod h1:kLR1opoVvCCE4czHe/oymuca481JU4p2sFMlGr2+xq4=
github.com/cockroachdb/pebble v0.0.0-20221003221406-518ead0d41bb h1:e0iAn/JlJkJo6LS+JSVKSqzpreuEaOCR/9x0TZ4xKys=
github.com/cockroachdb/pebble v0.0.0-20221003221406-518ead0d41bb/go.mod h1:kLR1opoVvCCE4czHe/oymuca481JU4p2sFMlGr2+xq4=
github.com/cockroachdb/redact v1.0.8/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ=
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
Expand Down
21 changes: 4 additions & 17 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,10 @@ SELECT count(distinct(node_id)), count(*) FROM crdb_internal.node_runtime_info
----
1 12

query IT
SELECT node_id, name FROM crdb_internal.leases ORDER BY name
----
0 eventlog
0 jobs
0 locations
0 protected_ts_meta
0 protected_ts_records
0 public
0 role_members
0 role_options
0 scheduled_jobs
0 settings
0 statement_diagnostics_requests
0 table_statistics
0 test
0 users
query I
SELECT sign(count(*)) FROM crdb_internal.leases
----
1

query error database "crdb_internal" does not exist
ALTER DATABASE crdb_internal RENAME TO not_crdb_internal
Expand Down
1 change: 1 addition & 0 deletions pkg/obsservice/obslib/httpproxy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/cli/exit",
"//pkg/server/serverpb",
"//pkg/ui",
"//pkg/util/log",
"//pkg/util/stop",
Expand Down
4 changes: 4 additions & 0 deletions pkg/obsservice/obslib/httpproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/cockroachdb/cmux"
"github.com/cockroachdb/cockroach/pkg/cli/exit"
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/ui"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/stop"
Expand Down Expand Up @@ -141,6 +142,9 @@ func (p *ReverseHTTPProxy) Start(ctx context.Context, stop *stop.Stopper) {
return &u
},
OIDC: &noOIDCConfigured{},
Flags: serverpb.FeatureFlags{
IsObservabilityService: true,
},
}))
for _, path := range CRDBProxyPaths {
mux.Handle(path, p.proxy)
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(
`{"ExperimentalUseLogin":false,"LoginEnabled":false,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":""}`,
`{"ExperimentalUseLogin":false,"LoginEnabled":false,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{}}`,
build.GetInfo().Tag,
build.BinaryVersionPrefix(),
1,
Expand Down Expand Up @@ -832,7 +832,7 @@ Binary built without web UI.
{
loggedInClient,
fmt.Sprintf(
`{"ExperimentalUseLogin":true,"LoginEnabled":true,"LoggedInUser":"authentic_user","Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":""}`,
`{"ExperimentalUseLogin":true,"LoginEnabled":true,"LoggedInUser":"authentic_user","Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{}}`,
build.GetInfo().Tag,
build.BinaryVersionPrefix(),
1,
Expand All @@ -841,7 +841,7 @@ Binary built without web UI.
{
loggedOutClient,
fmt.Sprintf(
`{"ExperimentalUseLogin":true,"LoginEnabled":true,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":""}`,
`{"ExperimentalUseLogin":true,"LoginEnabled":true,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{}}`,
build.GetInfo().Tag,
build.BinaryVersionPrefix(),
1,
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/serverpb/admin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1239,3 +1239,8 @@ message SetTraceRecordingTypeRequest {
// SetTraceRecordingTypeRequest is the response for SetTraceRecordingType.
message SetTraceRecordingTypeResponse{}

// FeatureFlags within this struct are used within back-end/front-end code to show/hide features.
message FeatureFlags {
// Whether the server is an instance of the Observability Service
bool is_observability_service = 1;
}
6 changes: 6 additions & 0 deletions pkg/sql/create_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func (n *createFunctionNode) startExec(params runParams) error {
return unimplemented.NewWithIssue(85144, "CREATE FUNCTION...sql_body unimplemented")
}

if err := params.p.canCreateOnSchema(
params.ctx, n.scDesc.GetID(), n.dbDesc.GetID(), params.p.User(), skipCheckPublicSchema,
); err != nil {
return err
}

for _, dep := range n.planDeps {
if dbID := dep.desc.GetParentID(); dbID != n.dbDesc.GetID() && dbID != keys.SystemDatabaseID {
return pgerror.Newf(pgcode.FeatureNotSupported, "the function cannot refer to other databases")
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,18 @@ test sc_test_show_grants f_test_show_grants(int8, text, oid) u_test_
statement ok
SET search_path = public;

subtest udf_create_privilege

statement ok
CREATE SCHEMA sc_test_priv;

user testuser

statement error pq: user testuser does not have CREATE privilege on schema sc_test_priv
CREATE FUNCTION sc_test_priv.f() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$;

user root

subtest execution

statement ok
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
deps = [
"//pkg/base",
"//pkg/build",
"//pkg/server/serverpb",
"//pkg/util/httputil",
"//pkg/util/log",
],
Expand Down
4 changes: 4 additions & 0 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/build"
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/util/httputil"
"github.com/cockroachdb/cockroach/pkg/util/log"
)
Expand Down Expand Up @@ -67,6 +68,7 @@ type indexHTMLArgs struct {
OIDCAutoLogin bool
OIDCLoginEnabled bool
OIDCButtonText string
FeatureFlags serverpb.FeatureFlags
}

// OIDCUIConf is a variable that stores data required by the
Expand Down Expand Up @@ -102,6 +104,7 @@ type Config struct {
NodeID *base.NodeIDContainer
GetUser func(ctx context.Context) *string
OIDC OIDCUI
Flags serverpb.FeatureFlags
}

var uiConfigPath = regexp.MustCompile("^/uiconfig$")
Expand Down Expand Up @@ -141,6 +144,7 @@ func Handler(cfg Config) http.Handler {
OIDCAutoLogin: oidcConf.AutoLogin,
OIDCLoginEnabled: oidcConf.Enabled,
OIDCButtonText: oidcConf.ButtonText,
FeatureFlags: cfg.Flags,
}
if cfg.NodeID != nil {
args.NodeID = cfg.NodeID.String()
Expand Down
11 changes: 10 additions & 1 deletion pkg/ui/workspaces/cluster-ui/src/util/dataFromServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

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

export interface DataFromServer {
ExperimentalUseLogin: boolean;
LoginEnabled: boolean;
Expand All @@ -18,6 +21,7 @@ export interface DataFromServer {
OIDCAutoLogin: boolean;
OIDCLoginEnabled: boolean;
OIDCButtonText: string;
FeatureFlags: IFeatureFlags;
}

// Tell TypeScript about `window.dataFromServer`, which is set in a script
Expand All @@ -30,5 +34,10 @@ declare global {
}

export function getDataFromServer(): DataFromServer {
return window.dataFromServer || ({} as DataFromServer);
return (
window.dataFromServer ||
({
FeatureFlags: {},
} as DataFromServer)
);
}
11 changes: 10 additions & 1 deletion pkg/ui/workspaces/db-console/src/util/dataFromServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

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

export interface DataFromServer {
ExperimentalUseLogin: boolean;
LoginEnabled: boolean;
Expand All @@ -18,6 +21,7 @@ export interface DataFromServer {
OIDCAutoLogin: boolean;
OIDCLoginEnabled: boolean;
OIDCButtonText: string;
FeatureFlags: IFeatureFlags;
}
// 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 All @@ -44,7 +48,12 @@ export function fetchDataFromServer(): Promise<DataFromServer> {
}

export function getDataFromServer(): DataFromServer {
return window.dataFromServer || ({} as DataFromServer);
return (
window.dataFromServer ||
({
FeatureFlags: {},
} as DataFromServer)
);
}

export function setDataFromServer(d: DataFromServer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Badge } from "@cockroachlabs/cluster-ui";

import "./layout.styl";
import "./layoutPanel.styl";
import { getDataFromServer } from "src/util/dataFromServer";

export interface LayoutProps {
clusterName: string;
Expand Down Expand Up @@ -92,6 +93,9 @@ class Layout extends React.Component<LayoutProps & RouteComponentProps> {
<div className="layout-panel__navigation-bar">
<PageHeader>
<Text textType={TextTypes.Heading2} noWrap>
{getDataFromServer().FeatureFlags.is_observability_service
? "(Obs Service) "
: ""}
{clusterName || `Cluster id: ${clusterId || ""}`}
</Text>
<Badge text={clusterVersion} />
Expand Down
2 changes: 1 addition & 1 deletion vendor

0 comments on commit 54e81fc

Please sign in to comment.