Skip to content

Commit

Permalink
Revert "sql: Add database ID to sampled query log"
Browse files Browse the repository at this point in the history
Reverts: cockroachdb#84195
This reverts commit c633d13.

Removes the DatabaseID field from the
SampledQuery telemetry log due to the potential of indefinite blocking
in the case of a lease acquisition failure. Protobuf field not reserved as
no official build was released with these changes yet.

Release note (sql change): Removes the DatabaseID field from the
SampledQuery telemetry log due to the potential of indefinite blocking
in the case of a lease acquisition failure.
  • Loading branch information
Thomas Hardy committed Jul 27, 2022
1 parent 8f4dc94 commit 1d4d147
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 102 deletions.
1 change: 0 additions & 1 deletion docs/generated/eventlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2244,7 +2244,6 @@ contains common SQL event/execution details.
| `Database` | Name of the database that initiated the query. | no |
| `StatementID` | Statement ID of the query. | no |
| `TransactionID` | Transaction ID of the query. | no |
| `DatabaseID` | Database ID of the query. | no |
| `StatementFingerprintID` | Statement fingerprint ID of the query. | no |


Expand Down
5 changes: 0 additions & 5 deletions pkg/sql/exec_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ func (p *planner) maybeLogStatementInternal(
}
if telemetryMetrics.maybeUpdateLastEmittedTime(telemetryMetrics.timeNow(), requiredTimeElapsed) {
skippedQueries := telemetryMetrics.resetSkippedQueryCount()
databaseName := p.CurrentDatabase()
sampledQuery := eventpb.SampledQuery{
CommonSQLExecDetails: execDetails,
SkippedQueries: skippedQueries,
Expand All @@ -392,10 +391,6 @@ func (p *planner) maybeLogStatementInternal(
TransactionID: p.txn.ID().String(),
StatementFingerprintID: uint64(stmtFingerprintID),
}
db, _ := p.Descriptors().GetImmutableDatabaseByName(ctx, p.txn, databaseName, tree.DatabaseLookupFlags{Required: true})
if db != nil {
sampledQuery.DatabaseID = uint32(db.GetID())
}
p.logOperationalEventsOnlyExternally(ctx, eventLogEntry{event: &sampledQuery})
} else {
telemetryMetrics.incSkippedQueryCount()
Expand Down
8 changes: 0 additions & 8 deletions pkg/sql/telemetry_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package sql

import (
"context"
gosql "database/sql"
"fmt"
"math"
"regexp"
Expand Down Expand Up @@ -97,14 +96,10 @@ func TestTelemetryLogging(t *testing.T) {

var sessionID string
var databaseName string
var dbID uint32

db := sqlutils.MakeSQLRunner(sqlDB)
conn := db.DB.(*gosql.DB)

db.QueryRow(t, `SHOW session_id`).Scan(&sessionID)
db.QueryRow(t, `SHOW database`).Scan(&databaseName)
dbID = sqlutils.QueryDatabaseID(t, conn, databaseName)
db.Exec(t, `SET application_name = 'telemetry-logging-test'`)
db.Exec(t, `SET CLUSTER SETTING sql.telemetry.query_sampling.enabled = true;`)
db.Exec(t, "CREATE TABLE t();")
Expand Down Expand Up @@ -275,9 +270,6 @@ func TestTelemetryLogging(t *testing.T) {
if !strings.Contains(e.Message, "\"Database\":\""+databaseName+"\"") {
t.Errorf("expected to find Database: %s", databaseName)
}
if !strings.Contains(e.Message, "\"DatabaseID\":"+strconv.Itoa(int(dbID))) {
t.Errorf("expected to find DatabaseID: %v", dbID)
}
stmtFingerprintID := roachpb.ConstructStatementFingerprintID(tc.queryNoConstants, false, true, databaseName)
if !strings.Contains(e.Message, "\"StatementFingerprintID\":"+strconv.FormatUint(uint64(stmtFingerprintID), 10)) {
t.Errorf("expected to find StatementFingerprintID: %v", stmtFingerprintID)
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/log/eventpb/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

//go:build bazel
// +build bazel

package main
Expand Down Expand Up @@ -342,6 +343,11 @@ func readInput(
return errors.Newf("field definition must not span multiple lines: %q", line)
}

// Skip reserved fields.
if reservedDefRe.MatchString(line) {
continue
}

// A field.
if strings.HasPrefix(line, "repeated") {
line = "array_of_" + strings.TrimSpace(strings.TrimPrefix(line, "repeated"))
Expand Down Expand Up @@ -446,6 +452,8 @@ var fieldDefRe = regexp.MustCompile(`\s*(?P<typ>[a-z._A-Z0-9]+)` +
`(.*"redact:\\"safeif:(?P<safeif>([^\\]|\\[^"])+)\\"")?` +
`).*$`)

var reservedDefRe = regexp.MustCompile(`\s*(reserved ([1-9][0-9]*);)`)

func camelToSnake(typeName string) string {
var res strings.Builder
res.WriteByte(typeName[0] + 'a' - 'A')
Expand Down
9 changes: 0 additions & 9 deletions pkg/util/log/eventpb/json_encode_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 47 additions & 77 deletions pkg/util/log/eventpb/telemetry.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/util/log/eventpb/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ message SampledQuery {
// Transaction ID of the query.
string transaction_id = 11 [(gogoproto.customname) = "TransactionID", (gogoproto.jsontag) = ',omitempty', (gogoproto.moretags) = "redact:\"nonsensitive\""];

// Database ID of the query.
uint32 database_id = 12 [(gogoproto.customname) = "DatabaseID", (gogoproto.jsontag) = ",omitempty"];
reserved 12;

// Statement fingerprint ID of the query.
uint64 statement_fingerprint_id = 13 [(gogoproto.customname) = "StatementFingerprintID", (gogoproto.jsontag) = ',omitempty'];
Expand Down

0 comments on commit 1d4d147

Please sign in to comment.