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

release-2.1: assorted missing telemetry #31638

Merged
merged 6 commits into from
Nov 12, 2018
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
3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ unreserved_keyword ::=
| 'DAY'
| 'DEALLOCATE'
| 'DELETE'
| 'DEFERRED'
| 'DISCARD'
| 'DOMAIN'
| 'DOUBLE'
Expand Down Expand Up @@ -589,6 +590,7 @@ unreserved_keyword ::=
| 'HIGH'
| 'HISTOGRAM'
| 'HOUR'
| 'IMMEDIATE'
| 'IMPORT'
| 'INCREMENT'
| 'INCREMENTAL'
Expand Down Expand Up @@ -634,6 +636,7 @@ unreserved_keyword ::=
| 'OF'
| 'OFF'
| 'OID'
| 'OIDS'
| 'OIDVECTOR'
| 'OPERATOR'
| 'OPTION'
Expand Down
35 changes: 35 additions & 0 deletions pkg/server/telemetry/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"fmt"
"sync/atomic"

"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
)

Expand Down Expand Up @@ -123,3 +125,36 @@ func GetAndResetFeatureCounts(quantize bool) map[string]int32 {
}
return m
}

// RecordError takes an error and increments the corresponding count
// for its error code, and, if it is an unimplemented or internal
// error, the count for that feature or the internal error's shortened
// stack trace.
func RecordError(err error) {
if err == nil {
return
}

if pgErr, ok := pgerror.GetPGCause(err); ok {
Count("errorcodes." + pgErr.Code)

if details := pgErr.InternalCommand; details != "" {
var prefix string
switch pgErr.Code {
case pgerror.CodeFeatureNotSupportedError:
prefix = "unimplemented."
case pgerror.CodeInternalError:
prefix = "internalerror."
default:
prefix = "othererror." + pgErr.Code + "."
}
Count(prefix + details)
}
} else {
typ := log.ErrorSource(err)
if typ == "" {
typ = "unknown"
}
Count("othererror." + typ)
}
}
11 changes: 11 additions & 0 deletions pkg/server/updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ func TestReportUsage(t *testing.T) {
) {
t.Fatal(err)
}
if _, err := db.Exec(`SELECT crdb_internal.set_vmodule('invalid')`); !testutils.IsError(
err, "comma-separated list",
) {
t.Fatal(err)
}
// If the vtable ever gets supported, change to pick one that is not supported yet.
if _, err := db.Exec(`SELECT * FROM pg_catalog.pg_stat_wal_receiver`); !testutils.IsError(
err, "virtual schema table not implemented",
Expand Down Expand Up @@ -528,7 +533,11 @@ func TestReportUsage(t *testing.T) {
"unimplemented.#9148": 10,
"internalerror.": 10,
"othererror.builtins.go": 10,
"othererror." +
pgerror.CodeDataExceptionError +
".crdb_internal.set_vmodule()": 10,
"errorcodes.blah": 10,
"errorcodes." + pgerror.CodeDataExceptionError: 10,
"errorcodes." + pgerror.CodeInternalError: 10,
"errorcodes." + pgerror.CodeSyntaxError: 10,
"errorcodes." + pgerror.CodeFeatureNotSupportedError: 10,
Expand Down Expand Up @@ -665,6 +674,7 @@ func TestReportUsage(t *testing.T) {
`[true,false,true] SELECT _ / _`,
`[true,false,true] SELECT crdb_internal.force_assertion_error(_)`,
`[true,false,true] SELECT crdb_internal.force_error(_, $1)`,
`[true,false,true] SELECT crdb_internal.set_vmodule(_)`,
`[true,true,false] SELECT * FROM _ WHERE (_ = _) AND (_ = _)`,
`[true,true,false] SELECT * FROM _ WHERE (_ = length($1::STRING)) OR (_ = $2)`,
`[true,true,false] SELECT _ FROM _ WHERE (_ = _) AND (lower(_) = lower(_))`,
Expand Down Expand Up @@ -709,6 +719,7 @@ func TestReportUsage(t *testing.T) {
`SELECT _ / _`,
`SELECT crdb_internal.force_assertion_error(_)`,
`SELECT crdb_internal.force_error(_, $1)`,
`SELECT crdb_internal.set_vmodule(_)`,
`SET CLUSTER SETTING "server.time_until_store_dead" = _`,
`SET CLUSTER SETTING "diagnostics.reporting.send_crash_reports" = _`,
`SET application_name = _`,
Expand Down
35 changes: 2 additions & 33 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,37 +302,6 @@ func (s *Server) Start(ctx context.Context, stopper *stop.Stopper) {
s.PeriodicallyClearStmtStats(ctx, stopper)
}

// recordError takes an error and increments the corresponding count
// for its error code, and, if it is an unimplemented or internal
// error, the count for that feature or the internal error's shortened
// stack trace.
func (s *Server) recordError(err error) {
if err == nil {
return
}

if pgErr, ok := pgerror.GetPGCause(err); ok {
telemetry.Count("errorcodes." + pgErr.Code)

switch pgErr.Code {
case pgerror.CodeFeatureNotSupportedError:
if feature := pgErr.InternalCommand; feature != "" {
telemetry.Count("unimplemented." + feature)
}
case pgerror.CodeInternalError:
if trace := pgErr.InternalCommand; trace != "" {
telemetry.Count("internalerror." + trace)
}
}
} else {
typ := log.ErrorSource(err)
if typ == "" {
typ = "unknown"
}
telemetry.Count("othererror." + typ)
}
}

// ResetStatementStats resets the executor's collected statement statistics.
func (s *Server) ResetStatementStats(ctx context.Context) {
s.sqlStats.resetStats(ctx)
Expand Down Expand Up @@ -1290,12 +1259,12 @@ func (ex *connExecutor) run(
ex.sessionEventf(ex.Ctx(), "execution error: %s", pe.errorCause())
}
if resErr == nil && ok {
ex.server.recordError(pe.errorCause())
telemetry.RecordError(pe.errorCause())
// Depending on whether the result has the error already or not, we have
// to call either Close or CloseWithErr.
res.CloseWithErr(pe.errorCause())
} else {
ex.server.recordError(resErr)
telemetry.RecordError(resErr)
res.Close(stateToTxnStatusIndicator(ex.machine.CurState()))
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/conn_executor_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/internal/client"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/sql/coltypes"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
Expand Down Expand Up @@ -1207,7 +1208,7 @@ func (ex *connExecutor) runShowSyntax(
commErr = res.AddRow(ctx, tree.Datums{tree.NewDString(field), tree.NewDString(msg)})
return nil
},
ex.server.recordError, /* reportErr */
telemetry.RecordError, /* reportErr */
); err != nil {
res.SetError(err)
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2548,6 +2548,7 @@ func TestUnimplementedSyntax(t *testing.T) {
{`CREATE OPERATOR a`, 0, `create operator`},
{`CREATE PUBLICATION a`, 0, `create publication`},
{`CREATE RULE a`, 0, `create rule`},
{`CREATE SCHEMA a`, 26443, `create`},
{`CREATE SERVER a`, 0, `create server`},
{`CREATE SUBSCRIPTION a`, 0, `create subscription`},
{`CREATE TEXT SEARCH a`, 7821, `create text`},
Expand All @@ -2566,6 +2567,7 @@ func TestUnimplementedSyntax(t *testing.T) {
{`DROP OPERATOR a`, 0, `drop operator`},
{`DROP PUBLICATION a`, 0, `drop publication`},
{`DROP RULE a`, 0, `drop rule`},
{`DROP SCHEMA a`, 26443, `drop`},
{`DROP SERVER a`, 0, `drop server`},
{`DROP SUBSCRIPTION a`, 0, `drop subscription`},
{`DROP TEXT SEARCH a`, 7821, `drop text`},
Expand All @@ -2586,11 +2588,26 @@ func TestUnimplementedSyntax(t *testing.T) {
{`CREATE TEMP VIEW a AS SELECT b`, 5807, ``},
{`CREATE TEMP SEQUENCE a`, 5807, ``},

{`CREATE TABLE a(LIKE b)`, 30840, ``},

{`CREATE TABLE a(b INT) WITH OIDS`, 0, `create table with oids`},
{`CREATE TABLE a(b INT) WITH foo = bar`, 0, `create table with foo`},

{`CREATE TABLE a AS SELECT b WITH NO DATA`, 0, `create table as with no data`},

{`CREATE TABLE a(b INT AS (123) VIRTUAL)`, 0, `virtual computed columns`},
{`CREATE TABLE a(b INT REFERENCES c(x) MATCH FULL`, 0, `references match full`},
{`CREATE TABLE a(b INT REFERENCES c(x) MATCH PARTIAL`, 0, `references match partial`},
{`CREATE TABLE a(b INT REFERENCES c(x) MATCH SIMPLE`, 0, `references match simple`},

{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) DEFERRABLE)`, 31632, `deferrable`},
{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) INITIALLY DEFERRED)`, 31632, `initially deferred`},
{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) INITIALLY IMMEDIATE)`, 31632, `initially immediate`},
{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) DEFERRABLE INITIALLY DEFERRED)`, 31632, `initially deferred`},
{`CREATE TABLE a(b INT, FOREIGN KEY (b) REFERENCES c(x) DEFERRABLE INITIALLY IMMEDIATE)`, 31632, `initially immediate`},
{`CREATE TABLE a(b INT, UNIQUE (b) DEFERRABLE)`, 31632, `deferrable`},
{`CREATE TABLE a(b INT, CHECK (b > 0) DEFERRABLE)`, 31632, `deferrable`},

{`CREATE SEQUENCE a AS DOUBLE PRECISION`, 25110, `FLOAT8`},
{`CREATE SEQUENCE a OWNED BY b`, 26382, ``},

Expand Down
Loading