diff --git a/docs/generated/eventlog.md b/docs/generated/eventlog.md index 300136ae531b..4b8098ab4d7f 100644 --- a/docs/generated/eventlog.md +++ b/docs/generated/eventlog.md @@ -2242,6 +2242,10 @@ contains common SQL event/execution details. | `SkippedQueries` | skipped_queries indicate how many SQL statements were not considered for sampling prior to this one. If the field is omitted, or its value is zero, this indicates that no statement was omitted since the last event. | no | | `CostEstimate` | Cost of the query as estimated by the optimizer. | no | | `Distribution` | The distribution of the DistSQL query plan (local, full, or partial). | no | +| `SessionID` | SessionID is the ID of the session that initiated the query. | no | +| `Database` | Name of the database that initiated the query. | no | +| `StatementID` | Statement ID of the query. | no | +| `TransactionID` | Transaction ID of the query. | no | #### Common fields diff --git a/pkg/sql/exec_log.go b/pkg/sql/exec_log.go index 9c5e25b963ca..c56dcfc942a4 100644 --- a/pkg/sql/exec_log.go +++ b/pkg/sql/exec_log.go @@ -382,6 +382,10 @@ func (p *planner) maybeLogStatementInternal( SkippedQueries: skippedQueries, CostEstimate: p.curPlan.instrumentation.costEstimate, Distribution: p.curPlan.instrumentation.distribution.String(), + SessionID: p.extendedEvalCtx.SessionID.String(), + Database: p.CurrentDatabase(), + StatementID: p.stmt.QueryID.String(), + TransactionID: p.txn.ID().String(), }}) } else { telemetryMetrics.incSkippedQueryCount() diff --git a/pkg/sql/telemetry_logging_test.go b/pkg/sql/telemetry_logging_test.go index 39d8b5d3c560..16b0e0f54db5 100644 --- a/pkg/sql/telemetry_logging_test.go +++ b/pkg/sql/telemetry_logging_test.go @@ -92,7 +92,12 @@ func TestTelemetryLogging(t *testing.T) { defer s.Stopper().Stop(context.Background()) + var sessionID string + var databaseName string + db := sqlutils.MakeSQLRunner(sqlDB) + db.QueryRow(t, `SHOW session_id`).Scan(&sessionID) + db.QueryRow(t, `SHOW database`).Scan(&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();") @@ -231,6 +236,16 @@ func TestTelemetryLogging(t *testing.T) { if !distRe.MatchString(e.Message) { t.Errorf("expected to find Distribution but none was found") } + // Match StatementID on any non-empty string value. + stmtID := regexp.MustCompile("\"StatementID\":(\"\\S+\")") + if !stmtID.MatchString(e.Message) { + t.Errorf("expected to find StatementID but none was found in: %s", e.Message) + } + // Match TransactionID on any non-empty string value. + txnID := regexp.MustCompile("\"TransactionID\":(\"\\S+\")") + if !txnID.MatchString(e.Message) { + t.Errorf("expected to find TransactionID but none was found in: %s", e.Message) + } for _, eTag := range tc.expectedUnredactedTags { for _, tag := range strings.Split(e.Tags, ",") { kv := strings.Split(tag, "=") @@ -242,6 +257,12 @@ func TestTelemetryLogging(t *testing.T) { if !strings.Contains(e.Message, "\"ApplicationName\":\""+tc.expectedApplicationName+"\"") { t.Errorf("expected to find unredacted Application Name: %s", tc.expectedApplicationName) } + if !strings.Contains(e.Message, "\"SessionID\":\""+sessionID+"\"") { + t.Errorf("expected to find sessionID: %s", sessionID) + } + if !strings.Contains(e.Message, "\"Database\":\""+databaseName+"\"") { + t.Errorf("expected to find Database: %s", databaseName) + } } } if logCount != expectedLogCount { diff --git a/pkg/util/log/eventpb/json_encode_generated.go b/pkg/util/log/eventpb/json_encode_generated.go index d1e88df60ebe..ee3c5e026146 100644 --- a/pkg/util/log/eventpb/json_encode_generated.go +++ b/pkg/util/log/eventpb/json_encode_generated.go @@ -2860,6 +2860,46 @@ func (m *SampledQuery) AppendJSONFields(printComma bool, b redact.RedactableByte b = append(b, '"') } + if m.SessionID != "" { + if printComma { + b = append(b, ',') + } + printComma = true + b = append(b, "\"SessionID\":\""...) + b = redact.RedactableBytes(jsonbytes.EncodeString([]byte(b), string(m.SessionID))) + b = append(b, '"') + } + + if m.Database != "" { + if printComma { + b = append(b, ',') + } + printComma = true + b = append(b, "\"Database\":\""...) + b = redact.RedactableBytes(jsonbytes.EncodeString([]byte(b), string(m.Database))) + b = append(b, '"') + } + + if m.StatementID != "" { + if printComma { + b = append(b, ',') + } + printComma = true + b = append(b, "\"StatementID\":\""...) + b = redact.RedactableBytes(jsonbytes.EncodeString([]byte(b), string(m.StatementID))) + b = append(b, '"') + } + + if m.TransactionID != "" { + if printComma { + b = append(b, ',') + } + printComma = true + b = append(b, "\"TransactionID\":\""...) + b = redact.RedactableBytes(jsonbytes.EncodeString([]byte(b), string(m.TransactionID))) + b = append(b, '"') + } + return printComma, b } diff --git a/pkg/util/log/eventpb/telemetry.pb.go b/pkg/util/log/eventpb/telemetry.pb.go index e5e651072069..fb68af1f1761 100644 --- a/pkg/util/log/eventpb/telemetry.pb.go +++ b/pkg/util/log/eventpb/telemetry.pb.go @@ -39,6 +39,14 @@ type SampledQuery struct { CostEstimate float64 `protobuf:"fixed64,5,opt,name=cost_estimate,json=costEstimate,proto3" json:",omitempty"` // The distribution of the DistSQL query plan (local, full, or partial). Distribution string `protobuf:"bytes,6,opt,name=distribution,proto3" json:",omitempty" redact:"nonsensitive"` + // SessionID is the ID of the session that initiated the query. + SessionID string `protobuf:"bytes,8,opt,name=session_id,json=sessionId,proto3" json:",omitempty" redact:"nonsensitive"` + // Name of the database that initiated the query. + Database string `protobuf:"bytes,9,opt,name=database,proto3" json:",omitempty" redact:"nonsensitive"` + // Statement ID of the query. + StatementID string `protobuf:"bytes,10,opt,name=statement_id,json=statementId,proto3" json:",omitempty" redact:"nonsensitive"` + // Transaction ID of the query. + TransactionID string `protobuf:"bytes,11,opt,name=transaction_id,json=transactionId,proto3" json:",omitempty" redact:"nonsensitive"` } func (m *SampledQuery) Reset() { *m = SampledQuery{} } @@ -127,45 +135,51 @@ func init() { func init() { proto.RegisterFile("util/log/eventpb/telemetry.proto", fileDescriptor_3d317b4ad74be4f7) } var fileDescriptor_3d317b4ad74be4f7 = []byte{ - // 605 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xcf, 0x6e, 0xd3, 0x4e, - 0x10, 0xc7, 0xb3, 0xbf, 0xa6, 0x4d, 0xb2, 0x49, 0xfb, 0x43, 0x2b, 0x10, 0x56, 0x25, 0x9c, 0x28, - 0x07, 0x1a, 0x04, 0x72, 0x80, 0x1e, 0x90, 0x38, 0xa6, 0x2d, 0x52, 0x44, 0x85, 0x14, 0xb7, 0xbd, - 0x70, 0xb1, 0x36, 0xde, 0x51, 0x58, 0xd5, 0xf6, 0x3a, 0xde, 0x71, 0xd5, 0xbc, 0x05, 0xef, 0xc2, - 0x3b, 0xa0, 0x1e, 0x7b, 0xec, 0x29, 0x82, 0xf4, 0xd6, 0x23, 0x4f, 0x80, 0x76, 0x63, 0x04, 0x51, - 0xca, 0x9f, 0x20, 0x71, 0x4a, 0xbc, 0xf3, 0xf9, 0x7e, 0x34, 0x9e, 0x59, 0x99, 0xb6, 0x72, 0x94, - 0x51, 0x37, 0x52, 0xa3, 0x2e, 0x9c, 0x41, 0x82, 0xe9, 0xb0, 0x8b, 0x10, 0x41, 0x0c, 0x98, 0x4d, - 0xbc, 0x34, 0x53, 0xa8, 0xd8, 0x76, 0xa8, 0xc2, 0xd3, 0x4c, 0xf1, 0xf0, 0x9d, 0x67, 0x58, 0x2f, - 0x52, 0x23, 0xaf, 0x60, 0xb7, 0xef, 0x8e, 0xd4, 0x48, 0x59, 0xac, 0x6b, 0xfe, 0xcd, 0x13, 0xdb, - 0x0f, 0x96, 0x9c, 0xf6, 0x57, 0x17, 0xe5, 0x9d, 0xa5, 0xb2, 0x1e, 0x47, 0x01, 0xcf, 0x85, 0xc4, - 0xe0, 0x47, 0xb0, 0xfd, 0x71, 0x8d, 0x36, 0x8e, 0x78, 0x9c, 0x46, 0x20, 0x06, 0x39, 0x64, 0x13, - 0x76, 0x4c, 0x37, 0x42, 0x15, 0xc7, 0x2a, 0x71, 0x48, 0x8b, 0x74, 0xea, 0xcf, 0x3d, 0xef, 0xe7, - 0xbd, 0x79, 0x7b, 0x96, 0x3c, 0x30, 0x4f, 0xfb, 0x80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0x99, 0x4b, 0x3e, 0xcd, 0x5c, 0xf2, 0xfe, 0xda, 0x2d, 0x5d, 0x5e, - 0xbb, 0xa5, 0xab, 0x6b, 0xb7, 0xf4, 0xb6, 0x52, 0xdc, 0xcb, 0xe1, 0x86, 0xfd, 0x60, 0xed, 0x7e, - 0x0d, 0x00, 0x00, 0xff, 0xff, 0xc3, 0x4d, 0x32, 0x68, 0x4e, 0x05, 0x00, 0x00, + // 700 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0xcb, 0x6e, 0xdb, 0x46, + 0x14, 0x86, 0xc5, 0x5a, 0xd6, 0x65, 0x74, 0x69, 0x31, 0x68, 0x51, 0xc2, 0x40, 0x49, 0x41, 0x8b, + 0x5a, 0x45, 0x0b, 0xa9, 0xad, 0x83, 0x24, 0xc8, 0x52, 0x92, 0x03, 0x10, 0x31, 0x02, 0xe8, 0xe2, + 0x45, 0xb2, 0x21, 0x46, 0x9c, 0x03, 0x65, 0x60, 0x92, 0x43, 0x71, 0x86, 0x86, 0xf5, 0x16, 0x79, + 0x80, 0xbc, 0x45, 0x5e, 0xc2, 0x4b, 0x2f, 0xbd, 0x22, 0x12, 0x7a, 0xe7, 0x65, 0x9e, 0x20, 0x98, + 0x11, 0x7d, 0x83, 0x72, 0x91, 0x16, 0x59, 0x49, 0x3a, 0xe7, 0xfb, 0x3f, 0x1c, 0x0d, 0xe7, 0x48, + 0xa8, 0x95, 0x48, 0xe6, 0xf7, 0x7c, 0x3e, 0xef, 0xc1, 0x29, 0x84, 0x32, 0x9a, 0xf5, 0x24, 0xf8, + 0x10, 0x80, 0x8c, 0x97, 0xdd, 0x28, 0xe6, 0x92, 0xe3, 0x3d, 0x8f, 0x7b, 0x27, 0x31, 0x27, 0xde, + 0x9b, 0xae, 0x62, 0xbb, 0x3e, 0x9f, 0x77, 0x73, 0x76, 0xef, 0xd7, 0x39, 0x9f, 0x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x53, 0x26, 0x64, 0xcc, 0x66, 0x89, 0x64, 0x3c, 0x34, 0x4b, 0x2d, 0xa3, 0x53, + 0xed, 0xef, 0x3f, 0xcc, 0x7c, 0x4a, 0xed, 0xdf, 0x62, 0xa0, 0xc4, 0x93, 0xcf, 0xda, 0x21, 0x0f, + 0x05, 0x84, 0x82, 0x49, 0x76, 0x0a, 0xed, 0xf1, 0x83, 0x30, 0x9e, 0x20, 0x24, 0x40, 0x08, 0xc6, + 0x43, 0x97, 0x51, 0xb3, 0xa2, 0x55, 0x8f, 0xb2, 0xd4, 0xae, 0x4e, 0x56, 0x55, 0x67, 0xb8, 0xa9, + 0xb7, 0x9a, 0x7b, 0x1c, 0x8a, 0x07, 0xa8, 0x42, 0x89, 0x24, 0x33, 0x22, 0xc0, 0xac, 0x6e, 0x37, + 0xdd, 0x6d, 0x10, 0xbf, 0x42, 0x75, 0x21, 0x89, 0x84, 0x00, 0x42, 0xa9, 0x66, 0x43, 0x5a, 0xf4, + 0x38, 0x4b, 0xed, 0xda, 0xe4, 0xa6, 0xbe, 0xf9, 0x74, 0xb5, 0x5b, 0x97, 0x43, 0xb1, 0x8b, 0x9a, + 0x32, 0x26, 0xa1, 0x20, 0x9e, 0xcc, 0xbf, 0x78, 0x4d, 0xcb, 0x9f, 0x66, 0xa9, 0xdd, 0x98, 0xde, + 0x75, 0x36, 0xd7, 0x37, 0xee, 0xf9, 0x1c, 0xda, 0x7e, 0xbf, 0x8b, 0x7e, 0x1f, 0x90, 0x48, 0x26, + 0x31, 0x50, 0x27, 0xa4, 0x70, 0x76, 0x2c, 0xc8, 0x1c, 0xd4, 0xd8, 0xe2, 0x07, 0x6d, 0x4a, 0x07, + 0xfd, 0x22, 0xb9, 0x24, 0xbe, 0x1b, 0x03, 0xa1, 0xae, 0xc7, 0x93, 0x50, 0xea, 0xb5, 0x29, 0x8e, + 0x9b, 0xba, 0x3e, 0x06, 0x42, 0x07, 0xaa, 0x8a, 0x87, 0xa8, 0xea, 0x13, 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0xff, 0xff, 0x35, 0xac, 0x03, 0xe6, 0xa4, 0x06, 0x00, 0x00, } func (m *SampledQuery) Marshal() (dAtA []byte, err error) { @@ -188,6 +202,34 @@ func (m *SampledQuery) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.TransactionID) > 0 { + i -= len(m.TransactionID) + copy(dAtA[i:], m.TransactionID) + i = encodeVarintTelemetry(dAtA, i, uint64(len(m.TransactionID))) + i-- + dAtA[i] = 0x5a + } + if len(m.StatementID) > 0 { + i -= len(m.StatementID) + copy(dAtA[i:], m.StatementID) + i = encodeVarintTelemetry(dAtA, i, uint64(len(m.StatementID))) + i-- + dAtA[i] = 0x52 + } + if len(m.Database) > 0 { + i -= len(m.Database) + copy(dAtA[i:], m.Database) + i = encodeVarintTelemetry(dAtA, i, uint64(len(m.Database))) + i-- + dAtA[i] = 0x4a + } + if len(m.SessionID) > 0 { + i -= len(m.SessionID) + copy(dAtA[i:], m.SessionID) + i = encodeVarintTelemetry(dAtA, i, uint64(len(m.SessionID))) + i-- + dAtA[i] = 0x42 + } if len(m.Distribution) > 0 { i -= len(m.Distribution) copy(dAtA[i:], m.Distribution) @@ -375,6 +417,22 @@ func (m *SampledQuery) Size() (n int) { if l > 0 { n += 1 + l + sovTelemetry(uint64(l)) } + l = len(m.SessionID) + if l > 0 { + n += 1 + l + sovTelemetry(uint64(l)) + } + l = len(m.Database) + if l > 0 { + n += 1 + l + sovTelemetry(uint64(l)) + } + l = len(m.StatementID) + if l > 0 { + n += 1 + l + sovTelemetry(uint64(l)) + } + l = len(m.TransactionID) + if l > 0 { + n += 1 + l + sovTelemetry(uint64(l)) + } return n } @@ -620,6 +678,134 @@ func (m *SampledQuery) Unmarshal(dAtA []byte) error { } m.Distribution = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SessionID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTelemetry + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTelemetry + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTelemetry + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SessionID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Database", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTelemetry + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTelemetry + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTelemetry + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Database = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StatementID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTelemetry + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTelemetry + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTelemetry + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StatementID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TransactionID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTelemetry + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTelemetry + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTelemetry + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TransactionID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTelemetry(dAtA[iNdEx:]) diff --git a/pkg/util/log/eventpb/telemetry.proto b/pkg/util/log/eventpb/telemetry.proto index 446401bd7f22..1432ed0324a0 100644 --- a/pkg/util/log/eventpb/telemetry.proto +++ b/pkg/util/log/eventpb/telemetry.proto @@ -43,6 +43,18 @@ message SampledQuery { // The distribution of the DistSQL query plan (local, full, or partial). string distribution = 6 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""]; + + // SessionID is the ID of the session that initiated the query. + string session_id = 8 [(gogoproto.customname) = "SessionID", (gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""]; + + // Name of the database that initiated the query. + string database = 9 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""]; + + // Statement ID of the query. + string statement_id = 10 [(gogoproto.customname) = "StatementID", (gogoproto.jsontag) = ',omitempty', (gogoproto.moretags) = "redact:\"nonsensitive\""]; + + // Transaction ID of the query. + string transaction_id = 11 [(gogoproto.customname) = "TransactionID", (gogoproto.jsontag) = ',omitempty', (gogoproto.moretags) = "redact:\"nonsensitive\""]; } // CapturedIndexUsageStats