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 25, 2022
1 parent 8f4dc94 commit b174ee2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 107 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
9 changes: 0 additions & 9 deletions pkg/sql/telemetry_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ package sql

import (
"context"
gosql "database/sql"
"fmt"
"math"
"regexp"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -97,14 +95,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 +269,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
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.

127 changes: 48 additions & 79 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.

5 changes: 1 addition & 4 deletions pkg/util/log/eventpb/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ 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"];

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

// CapturedIndexUsageStats
Expand Down

0 comments on commit b174ee2

Please sign in to comment.