From 955825cd684d9a02aa41d2c4d3e97f4eed2da5be Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Mon, 14 Jun 2021 16:38:33 +0200 Subject: [PATCH] sql,log: new structured event `FirstQuery` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change aims to expose “time to first query”, a product metric that correlates with how easy it is for a user to start using CockroachDB. The naive approach to do this would be to store a boolean "has the first query been reported in telemetry yet" inside a system table. This naive approach is defective because it incurs a storage read-eval-write cycle with an access to KV storage, or disk, or a fan-out across the network, upon every query. This is an unacceptable performance overhead. Instead, we want the collection of this metric to have virtually no performance impact on the common case of workloads beyond the first query. To get to a better design, we need to better understand the requirement. A naive interpretation of the requirement would be to assume that we need the time to first query to be reported *exactly once*. Besides the fact that this is strictly impossible from a computer-theoretical perspective [1], an exactly-once approach would also incur unacceptable performance overhead, due to the need to synchronize between multiple nodes, when the first query is sent through a load balancer. So what can we do instead? In an initial implementation (#63812), we tried to *approximate* “exactly once” reporting with a design that combines “at least once” with a best effort of “at most once”. This was achieved using a cluster setting. That solution was storing the time of the first query inside a cluster setting, and relying on the auto-propagation of setting changes through the cluster to announce to other nodes that the first query had been reported already. The use of a cluster setting also takes care of persisting this information across node restarts, again towards the need to approximate “at most once”. After further discussion with stakeholders, it appears that there is no strong requirement to reach “at most once”. The data processing pipeline that consumes the "first query" event is only interested to trigger the first time the event is recognized for a given cluster and can be easily configured to ignore events reported after that. The only practical consideration is to minimize the amount of telemetry data (to ensure scalability over the CockroachCloud fleet), and so we are not interested to send a "first query" event for *every single query executed* either (obviously). Based on this new understanding, this commit simplifies the approach taken in #63812: it makes every CockroachDB *process* report the first SQL query it executes on the TELEMETRY channel. Whether the process has reported the event already or not is stored in a memory-only atomic variable. This approach technically has "at most once" semantics per node (an event can get lost if the logging output is stalled at the moment the event is reported), but approximates "at least once" semantics very well for multi-node clusters, or when nodes restart over time—as, presumably, the logging system will not be clogged all the time. There are two open questions in this approach however: - when a CockroachCloud cluster is initially configured by the CC intrusion control plane), there are “administrative” queries that are *not internal* but also *not user initiated*. With the current patch, the "first query" event will be reported for these administrative SQL queries. Is this desired? (NB: the same question applied to #63812) If not, we will need to agree on a reliable way to identify a user-initiated query. (A similar question exists when the user opens `cockroach sql`, but does not type anything in. The `cockroach sql` command sends queries in the background, and would trigger the "first query" event even without user interaction. Are we OK with this?) - this approach will cause a "first query" event to be logged *at least once per SQL pod* (when multiple pods are running side-by-side), and also *once after every pod restart*. To retrieve the “time **to** first query” (i.e. not “time **of** first query”), the consumer of these events must then compute the minimum timestamp of all the first query events received, and substract the timestamp of cluster creation. (The cluster creation timestamp can be obtained either via an external source, e.g. when the customer initiated the orchestration to create the cluster, or by retrieving the first ``node_restart`` event from the OPS logging channel.) Is this behavior acceptable? Of note: departure from "at most once" delivery has another advantage with regards to product telemetry: it teaches us something about the effective utilization of all the nodes in a cluster. If we know the cluster has 10 nodes but only 3 report "first query" events, that might teach us that the cluster is over-provisioned. [1] in a distributed system, an event can have guaranteed at-least-once delivery, or at-most-once, but never both. We also have the same constraint for CDC. Release note (cli change): CockroachDB now reports a `first_query` structured event on the TELEMETRY channel for the first SQL query executed on each server process. --- Makefile | 3 +- docs/generated/eventlog.md | 38 ++ docs/generated/logging.md | 4 +- pkg/sql/exec_log.go | 17 +- pkg/sql/exec_util.go | 12 + .../eventpb/eventlog_channels_generated.go | 2 +- pkg/util/log/eventpb/events.pb.go | 519 ++++++++++++++++-- pkg/util/log/eventpb/events.proto | 23 + pkg/util/log/eventpb/json_encode_generated.go | 12 +- pkg/util/log/eventpb/sql_audit_events.pb.go | 509 ++--------------- pkg/util/log/eventpb/sql_audit_events.proto | 24 - pkg/util/log/eventpb/telemetry.pb.go | 408 ++++++++++++++ pkg/util/log/eventpb/telemetry.proto | 35 ++ pkg/util/log/log_channels_generated.go | 94 ++-- pkg/util/log/testdata/config | 6 +- 15 files changed, 1108 insertions(+), 598 deletions(-) create mode 100644 pkg/util/log/eventpb/telemetry.pb.go create mode 100644 pkg/util/log/eventpb/telemetry.proto diff --git a/Makefile b/Makefile index 110c86de311d..ecee435cab61 100644 --- a/Makefile +++ b/Makefile @@ -1611,7 +1611,8 @@ EVENTLOG_PROTOS = \ pkg/util/log/eventpb/sql_audit_events.proto \ pkg/util/log/eventpb/cluster_events.proto \ pkg/util/log/eventpb/job_events.proto \ - pkg/util/log/eventpb/health_events.proto + pkg/util/log/eventpb/health_events.proto \ + pkg/util/log/eventpb/telemetry.proto LOGSINKDOC_DEP = pkg/util/log/logconfig/config.go diff --git a/docs/generated/eventlog.md b/docs/generated/eventlog.md index 1616578d6aed..f548ce6ffeb3 100644 --- a/docs/generated/eventlog.md +++ b/docs/generated/eventlog.md @@ -1992,6 +1992,44 @@ An event of type `drop_role` is recorded when a role is dropped. | `ApplicationName` | The application name for the session where the event was emitted. This is included in the event to ease filtering of logging output by application. Application names starting with a dollar sign (`$`) are not considered sensitive. | depends | | `PlaceholderValues` | The mapping of SQL placeholders to their values, for prepared statements. | yes | +## Telemetry events + + + +Events in this category are logged to the `TELEMETRY` channel. + + +### `first_query` + +An event of type `first_query` is reported every time a SQL server process runs a SQL query +on behalf of an external client for the first time. +(This excludes queries ran by internal executors.) + + + + +#### Common fields + +| Field | Description | Sensitive | +|--|--|--| +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | no | +| `EventType` | The type of the event. | no | +| `Statement` | A normalized copy of the SQL statement that triggered the event. | yes | +| `Tag` | The statement tag. This is separate from the statement string, since the statement string can contain sensitive information. The tag is guaranteed not to. | no | +| `User` | The user account that triggered the event. The special usernames `root` and `node` are not considered sensitive. | depends | +| `DescriptorID` | The primary object descriptor affected by the operation. Set to zero for operations that don't affect descriptors. | no | +| `ApplicationName` | The application name for the session where the event was emitted. This is included in the event to ease filtering of logging output by application. Application names starting with a dollar sign (`$`) are not considered sensitive. | depends | +| `PlaceholderValues` | The mapping of SQL placeholders to their values, for prepared statements. | yes | +| `ExecMode` | How the statement was being executed (exec/prepare, etc.) | no | +| `NumRows` | Number of rows returned. For mutation statements (INSERT, etc) that do not produce result rows, this field reports the number of rows affected. | no | +| `SQLSTATE` | The SQLSTATE code for the error, if an error was encountered. Empty/omitted if no error. | no | +| `ErrorText` | The text of the error if any. | yes | +| `Age` | Age of the query in milliseconds. | no | +| `NumRetries` | Number of retries, when the txn was reretried automatically by the server. | no | +| `FullTableScan` | Whether the query contains a full table scan. | no | +| `FullIndexScan` | Whether the query contains a full secondary index scan. | no | +| `TxnCounter` | The sequence number of the SQL transaction inside its session. | no | + ## Zone config events Events in this category pertain to zone configuration changes on diff --git a/docs/generated/logging.md b/docs/generated/logging.md index a7badf854151..5fc22336acea 100644 --- a/docs/generated/logging.md +++ b/docs/generated/logging.md @@ -164,9 +164,9 @@ helping developers of CockroachDB itself. It exists as a separate channel so as to not pollute the `SQL_PERF` logging output with internal troubleshooting details. -## TELEMETRY +### `TELEMETRY` -The TELEMETRY channel reports telemetry events. Telemetry events describe +The `TELEMETRY` channel reports telemetry events. Telemetry events describe feature usage within CockroachDB and anonymizes any application- specific data. diff --git a/pkg/sql/exec_log.go b/pkg/sql/exec_log.go index f95b2733ba02..65a8aa9d99fd 100644 --- a/pkg/sql/exec_log.go +++ b/pkg/sql/exec_log.go @@ -14,6 +14,7 @@ import ( "bytes" "context" "fmt" + "sync/atomic" "time" "github.com/cockroachdb/cockroach/pkg/settings" @@ -161,12 +162,21 @@ func (p *planner) maybeLogStatementInternal( // If hasAdminRoleCache IsSet is true iff AdminAuditLog is enabled. shouldLogToAdminAuditLog := hasAdminRoleCache.IsSet && hasAdminRoleCache.HasAdminRole + // Record the first query timestamp for non-internal statements, if + // not already known. + logFirstQuery := false + if isInternal := execType == executorTypeInternal; !isInternal { + if swapped := atomic.CompareAndSwapInt64(&p.execCfg.firstQueryTimestamp, 0, startTime.UnixNano()); swapped { + logFirstQuery = true + } + } + // Only log to adminAuditLog if the statement is executed by // a user and the user has admin privilege (is directly or indirectly a // member of the admin role). if !logV && !logExecuteEnabled && !auditEventsDetected && !slowQueryLogEnabled && - !shouldLogToAdminAuditLog { + !shouldLogToAdminAuditLog && !logFirstQuery { // Shortcut: avoid the expense of computing anything log-related // if logging is not enabled by configuration. return @@ -347,6 +357,11 @@ func (p *planner) maybeLogStatementInternal( if shouldLogToAdminAuditLog { p.logEventsOnlyExternally(ctx, eventLogEntry{event: &eventpb.AdminQuery{CommonSQLExecDetails: execDetails}}) } + + if logFirstQuery { + p.logEventsOnlyExternally(ctx, + eventLogEntry{event: &eventpb.FirstQuery{CommonSQLExecDetails: execDetails}}) + } } func (p *planner) logEventsOnlyExternally(ctx context.Context, entries ...eventLogEntry) { diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index 42f529de2dba..63872f02d9b8 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -918,6 +918,18 @@ type ExecutorConfig struct { // CompactEngineSpanFunc is used to inform a storage engine of the need to // perform compaction over a key span. CompactEngineSpanFunc tree.CompactEngineSpanFunc + + // firstQueryTimestamp is the timestamp at which the process + // executed a non-internal query for the first time. This + // is used to gate the emission of a FirstQuery telemetry event. + // This is accessed atomically. + // + // TODO(knz): Find a better location for this variable. + // It needs to be common to all executor instances and so + // cannot be stored on the planner. However it is internal + // to the exec log machinery and therefore does not deserve + // to be owned by the SQL stats package. + firstQueryTimestamp int64 } // VersionUpgradeHook is used to run migrations starting in v21.1. diff --git a/pkg/util/log/eventpb/eventlog_channels_generated.go b/pkg/util/log/eventpb/eventlog_channels_generated.go index fb24ff09b5fa..a56b7f086b49 100644 --- a/pkg/util/log/eventpb/eventlog_channels_generated.go +++ b/pkg/util/log/eventpb/eventlog_channels_generated.go @@ -227,7 +227,7 @@ func (m *CreateRole) LoggingChannel() logpb.Channel { return logpb.Channel_USER_ func (m *DropRole) LoggingChannel() logpb.Channel { return logpb.Channel_USER_ADMIN } // LoggingChannel implements the EventPayload interface. -func (m *Dummy) LoggingChannel() logpb.Channel { return logpb.Channel_TELEMETRY } +func (m *FirstQuery) LoggingChannel() logpb.Channel { return logpb.Channel_TELEMETRY } // LoggingChannel implements the EventPayload interface. func (m *RemoveZoneConfig) LoggingChannel() logpb.Channel { return logpb.Channel_OPS } diff --git a/pkg/util/log/eventpb/events.pb.go b/pkg/util/log/eventpb/events.pb.go index 493fd8ae97c4..c584886ecb42 100644 --- a/pkg/util/log/eventpb/events.pb.go +++ b/pkg/util/log/eventpb/events.pb.go @@ -4,6 +4,7 @@ package eventpb import ( + encoding_binary "encoding/binary" fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" @@ -115,6 +116,58 @@ func (m *CommonSQLEventDetails) XXX_DiscardUnknown() { var xxx_messageInfo_CommonSQLEventDetails proto.InternalMessageInfo +// CommonSQLExecDetails contains the field common to all SQL query logs. +type CommonSQLExecDetails struct { + // How the statement was being executed (exec/prepare, etc.) + ExecMode string `protobuf:"bytes,1,opt,name=exec_mode,json=execMode,proto3" json:",omitempty" redact:"nonsensitive"` + // Number of rows returned. For mutation statements (INSERT, etc) that + // do not produce result rows, this field reports the number of rows affected. + NumRows uint64 `protobuf:"varint,2,opt,name=num_rows,json=numRows,proto3" json:",omitempty"` + // The SQLSTATE code for the error, if an error was encountered. Empty/omitted if no error. + SQLSTATE string `protobuf:"bytes,3,opt,name=sqlstate,proto3" json:",omitempty" redact:"nonsensitive"` + // The text of the error if any. + ErrorText string `protobuf:"bytes,4,opt,name=error_text,json=errorText,proto3" json:",omitempty"` + // Age of the query in milliseconds. + Age float32 `protobuf:"fixed32,5,opt,name=age,proto3" json:",omitempty"` + // Number of retries, when the txn was reretried automatically by the server. + NumRetries uint32 `protobuf:"varint,6,opt,name=num_retries,json=numRetries,proto3" json:",omitempty"` + // Whether the query contains a full table scan. + FullTableScan bool `protobuf:"varint,7,opt,name=full_table_scan,json=fullTableScan,proto3" json:",omitempty"` + // Whether the query contains a full secondary index scan. + FullIndexScan bool `protobuf:"varint,8,opt,name=full_index_scan,json=fullIndexScan,proto3" json:",omitempty"` + // The sequence number of the SQL transaction inside its session. + TxnCounter uint32 `protobuf:"varint,9,opt,name=txn_counter,json=txnCounter,proto3" json:",omitempty"` +} + +func (m *CommonSQLExecDetails) Reset() { *m = CommonSQLExecDetails{} } +func (m *CommonSQLExecDetails) String() string { return proto.CompactTextString(m) } +func (*CommonSQLExecDetails) ProtoMessage() {} +func (*CommonSQLExecDetails) Descriptor() ([]byte, []int) { + return fileDescriptor_656955fd5b536468, []int{2} +} +func (m *CommonSQLExecDetails) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CommonSQLExecDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *CommonSQLExecDetails) XXX_Merge(src proto.Message) { + xxx_messageInfo_CommonSQLExecDetails.Merge(m, src) +} +func (m *CommonSQLExecDetails) XXX_Size() int { + return m.Size() +} +func (m *CommonSQLExecDetails) XXX_DiscardUnknown() { + xxx_messageInfo_CommonSQLExecDetails.DiscardUnknown(m) +} + +var xxx_messageInfo_CommonSQLExecDetails proto.InternalMessageInfo + // CommonJobEventDetails contains the fields common to all job events. type CommonJobEventDetails struct { // The ID of the job that triggered the event. @@ -139,7 +192,7 @@ func (m *CommonJobEventDetails) Reset() { *m = CommonJobEventDetails{} } func (m *CommonJobEventDetails) String() string { return proto.CompactTextString(m) } func (*CommonJobEventDetails) ProtoMessage() {} func (*CommonJobEventDetails) Descriptor() ([]byte, []int) { - return fileDescriptor_656955fd5b536468, []int{2} + return fileDescriptor_656955fd5b536468, []int{3} } func (m *CommonJobEventDetails) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -167,48 +220,62 @@ var xxx_messageInfo_CommonJobEventDetails proto.InternalMessageInfo func init() { proto.RegisterType((*CommonEventDetails)(nil), "cockroach.util.log.eventpb.CommonEventDetails") proto.RegisterType((*CommonSQLEventDetails)(nil), "cockroach.util.log.eventpb.CommonSQLEventDetails") + proto.RegisterType((*CommonSQLExecDetails)(nil), "cockroach.util.log.eventpb.CommonSQLExecDetails") proto.RegisterType((*CommonJobEventDetails)(nil), "cockroach.util.log.eventpb.CommonJobEventDetails") } func init() { proto.RegisterFile("util/log/eventpb/events.proto", fileDescriptor_656955fd5b536468) } var fileDescriptor_656955fd5b536468 = []byte{ - // 548 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x5f, 0x6b, 0xd3, 0x50, - 0x18, 0xc6, 0x9b, 0x75, 0xed, 0xec, 0x71, 0x9d, 0x7a, 0xd8, 0x30, 0x16, 0x4c, 0x4a, 0x10, 0xad, - 0x3a, 0x52, 0xc1, 0x2b, 0x07, 0x32, 0xc8, 0xea, 0xa0, 0x43, 0x84, 0x55, 0xf1, 0x42, 0x84, 0x72, - 0x92, 0xbc, 0xcd, 0x4e, 0x4d, 0xf2, 0x86, 0x9c, 0xd3, 0x42, 0xc1, 0x4f, 0xe0, 0x95, 0x97, 0x7e, - 0xa4, 0x5d, 0xee, 0x72, 0x57, 0x45, 0xd3, 0xbb, 0x5d, 0xfa, 0x09, 0x24, 0x49, 0xdb, 0xf5, 0xcf, - 0x6e, 0xe6, 0x55, 0x12, 0xf2, 0x7b, 0x0e, 0xcf, 0xfb, 0x3e, 0xcf, 0x21, 0x8f, 0x07, 0x92, 0xfb, - 0x4d, 0x1f, 0xbd, 0x26, 0x0c, 0x21, 0x94, 0x91, 0x9d, 0x3f, 0x85, 0x19, 0xc5, 0x28, 0x91, 0xd6, - 0x1c, 0x74, 0xbe, 0xc5, 0xc8, 0x9c, 0x33, 0x33, 0x05, 0x4d, 0x1f, 0x3d, 0x73, 0x0a, 0xd6, 0x76, - 0x3d, 0xf4, 0x30, 0xc3, 0x9a, 0xe9, 0x5b, 0xae, 0xa8, 0xe9, 0x1e, 0xa2, 0xe7, 0x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, 0x4c, 0x34, 0xe5, 0x77, - 0xa2, 0x29, 0x3f, 0x27, 0x5a, 0xe1, 0x62, 0xa2, 0x15, 0x2e, 0x27, 0x5a, 0xe1, 0xcb, 0xd6, 0xf4, - 0xda, 0xdb, 0xe5, 0xec, 0x1a, 0xbf, 0xfe, 0x17, 0x00, 0x00, 0xff, 0xff, 0x73, 0xa9, 0xb0, 0x4f, - 0x3a, 0x04, 0x00, 0x00, + // 753 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcf, 0x8f, 0xdb, 0x44, + 0x14, 0xc7, 0xe3, 0xcd, 0xe6, 0xd7, 0x6c, 0xd3, 0xc2, 0x68, 0x2b, 0xcc, 0x4a, 0xd8, 0x91, 0x85, + 0x20, 0x85, 0x92, 0x20, 0x55, 0x42, 0xa2, 0x12, 0xaa, 0xc8, 0xa6, 0x95, 0x52, 0x15, 0xd0, 0x26, + 0x11, 0x07, 0x84, 0x64, 0x8d, 0xed, 0x17, 0xd7, 0x8b, 0x3d, 0xcf, 0x78, 0xc6, 0xdb, 0xac, 0xc4, + 0x5f, 0xc0, 0x89, 0x23, 0x7f, 0x52, 0x8f, 0x3d, 0xf6, 0x14, 0x81, 0xf7, 0xd6, 0x23, 0x57, 0x2e, + 0xc8, 0x63, 0x27, 0x9b, 0x8d, 0x17, 0xa9, 0xdb, 0x53, 0x12, 0xcd, 0xe7, 0x3b, 0xf9, 0xce, 0x7b, + 0xef, 0xfb, 0xc8, 0x47, 0xa9, 0x0c, 0xc2, 0x61, 0x88, 0xfe, 0x10, 0xce, 0x80, 0xcb, 0xd8, 0x29, + 0x3e, 0xc5, 0x20, 0x4e, 0x50, 0x22, 0x3d, 0x72, 0xd1, 0xfd, 0x25, 0x41, 0xe6, 0x3e, 0x1f, 0xe4, + 0xe0, 0x20, 0x44, 0x7f, 0x50, 0x82, 0x47, 0x87, 0x3e, 0xfa, 0xa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x47, 0x57, 0xd0, + 0x47, 0xa4, 0x99, 0xcf, 0x55, 0x2a, 0x6e, 0xba, 0x7f, 0x4a, 0xd9, 0xe8, 0xde, 0xcb, 0xbf, 0x8d, + 0xda, 0xcb, 0xcc, 0xd0, 0x5e, 0x65, 0x86, 0xf6, 0x3a, 0x33, 0xb4, 0xbf, 0x32, 0x43, 0xfb, 0xe3, + 0xc2, 0xa8, 0xbd, 0xba, 0x30, 0x6a, 0xaf, 0x2f, 0x8c, 0xda, 0x4f, 0xad, 0x72, 0xe9, 0x3b, 0x4d, + 0xb5, 0xc4, 0x1f, 0xfc, 0x17, 0x00, 0x00, 0xff, 0xff, 0x52, 0x0d, 0x8c, 0xa1, 0x38, 0x06, 0x00, + 0x00, } func (m *CommonEventDetails) Marshal() (dAtA []byte, err error) { @@ -311,6 +378,91 @@ func (m *CommonSQLEventDetails) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *CommonSQLExecDetails) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CommonSQLExecDetails) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CommonSQLExecDetails) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TxnCounter != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.TxnCounter)) + i-- + dAtA[i] = 0x48 + } + if m.FullIndexScan { + i-- + if m.FullIndexScan { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x40 + } + if m.FullTableScan { + i-- + if m.FullTableScan { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x38 + } + if m.NumRetries != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.NumRetries)) + i-- + dAtA[i] = 0x30 + } + if m.Age != 0 { + i -= 4 + encoding_binary.LittleEndian.PutUint32(dAtA[i:], uint32(math.Float32bits(float32(m.Age)))) + i-- + dAtA[i] = 0x2d + } + if len(m.ErrorText) > 0 { + i -= len(m.ErrorText) + copy(dAtA[i:], m.ErrorText) + i = encodeVarintEvents(dAtA, i, uint64(len(m.ErrorText))) + i-- + dAtA[i] = 0x22 + } + if len(m.SQLSTATE) > 0 { + i -= len(m.SQLSTATE) + copy(dAtA[i:], m.SQLSTATE) + i = encodeVarintEvents(dAtA, i, uint64(len(m.SQLSTATE))) + i-- + dAtA[i] = 0x1a + } + if m.NumRows != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.NumRows)) + i-- + dAtA[i] = 0x10 + } + if len(m.ExecMode) > 0 { + i -= len(m.ExecMode) + copy(dAtA[i:], m.ExecMode) + i = encodeVarintEvents(dAtA, i, uint64(len(m.ExecMode))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *CommonJobEventDetails) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -446,6 +598,45 @@ func (m *CommonSQLEventDetails) Size() (n int) { return n } +func (m *CommonSQLExecDetails) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ExecMode) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + if m.NumRows != 0 { + n += 1 + sovEvents(uint64(m.NumRows)) + } + l = len(m.SQLSTATE) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + l = len(m.ErrorText) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + if m.Age != 0 { + n += 5 + } + if m.NumRetries != 0 { + n += 1 + sovEvents(uint64(m.NumRetries)) + } + if m.FullTableScan { + n += 2 + } + if m.FullIndexScan { + n += 2 + } + if m.TxnCounter != 0 { + n += 1 + sovEvents(uint64(m.TxnCounter)) + } + return n +} + func (m *CommonJobEventDetails) Size() (n int) { if m == nil { return 0 @@ -817,6 +1008,260 @@ func (m *CommonSQLEventDetails) Unmarshal(dAtA []byte) error { } return nil } +func (m *CommonSQLExecDetails) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CommonSQLExecDetails: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CommonSQLExecDetails: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecMode", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExecMode = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NumRows", wireType) + } + m.NumRows = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NumRows |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SQLSTATE", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SQLSTATE = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ErrorText", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ErrorText = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 5 { + return fmt.Errorf("proto: wrong wireType = %d for field Age", wireType) + } + var v uint32 + if (iNdEx + 4) > l { + return io.ErrUnexpectedEOF + } + v = uint32(encoding_binary.LittleEndian.Uint32(dAtA[iNdEx:])) + iNdEx += 4 + m.Age = float32(math.Float32frombits(v)) + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NumRetries", wireType) + } + m.NumRetries = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NumRetries |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FullTableScan", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.FullTableScan = bool(v != 0) + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FullIndexScan", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.FullIndexScan = bool(v != 0) + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TxnCounter", wireType) + } + m.TxnCounter = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TxnCounter |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *CommonJobEventDetails) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/pkg/util/log/eventpb/events.proto b/pkg/util/log/eventpb/events.proto index 7bd41f538d8e..461be2eb07d2 100644 --- a/pkg/util/log/eventpb/events.proto +++ b/pkg/util/log/eventpb/events.proto @@ -60,6 +60,29 @@ message CommonSQLEventDetails { repeated string placeholder_values = 5 [(gogoproto.jsontag) = ",omitempty"]; } +// CommonSQLExecDetails contains the field common to all SQL query logs. +message CommonSQLExecDetails { + // How the statement was being executed (exec/prepare, etc.) + string exec_mode = 1 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""]; + // Number of rows returned. For mutation statements (INSERT, etc) that + // do not produce result rows, this field reports the number of rows affected. + uint64 num_rows = 2 [(gogoproto.jsontag) = ",omitempty"]; + // The SQLSTATE code for the error, if an error was encountered. Empty/omitted if no error. + string sqlstate = 3 [(gogoproto.customname) = "SQLSTATE", (gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""]; + // The text of the error if any. + string error_text = 4 [(gogoproto.jsontag) = ",omitempty"]; + // Age of the query in milliseconds. + float age = 5 [(gogoproto.jsontag) = ",omitempty"]; + // Number of retries, when the txn was reretried automatically by the server. + uint32 num_retries = 6 [(gogoproto.jsontag) = ",omitempty"]; + // Whether the query contains a full table scan. + bool full_table_scan = 7 [(gogoproto.jsontag) = ",omitempty"]; + // Whether the query contains a full secondary index scan. + bool full_index_scan = 8 [(gogoproto.jsontag) = ",omitempty"]; + // The sequence number of the SQL transaction inside its session. + uint32 txn_counter = 9 [(gogoproto.jsontag) = ",omitempty"]; +} + // CommonJobEventDetails contains the fields common to all job events. message CommonJobEventDetails { // The ID of the job that triggered the event. diff --git a/pkg/util/log/eventpb/json_encode_generated.go b/pkg/util/log/eventpb/json_encode_generated.go index b9ec9886c0d0..b9b7dc8f0046 100644 --- a/pkg/util/log/eventpb/json_encode_generated.go +++ b/pkg/util/log/eventpb/json_encode_generated.go @@ -2073,15 +2073,17 @@ func (m *DropView) AppendJSONFields(printComma bool, b redact.RedactableBytes) ( } // AppendJSONFields implements the EventPayload interface. -func (m *Dummy) AppendJSONFields(printComma bool, b redact.RedactableBytes) (bool, redact.RedactableBytes) { +func (m *FinishSchemaChange) AppendJSONFields(printComma bool, b redact.RedactableBytes) (bool, redact.RedactableBytes) { printComma, b = m.CommonEventDetails.AppendJSONFields(printComma, b) + printComma, b = m.CommonSchemaChangeEventDetails.AppendJSONFields(printComma, b) + return printComma, b } // AppendJSONFields implements the EventPayload interface. -func (m *FinishSchemaChange) AppendJSONFields(printComma bool, b redact.RedactableBytes) (bool, redact.RedactableBytes) { +func (m *FinishSchemaChangeRollback) AppendJSONFields(printComma bool, b redact.RedactableBytes) (bool, redact.RedactableBytes) { printComma, b = m.CommonEventDetails.AppendJSONFields(printComma, b) @@ -2091,11 +2093,13 @@ func (m *FinishSchemaChange) AppendJSONFields(printComma bool, b redact.Redactab } // AppendJSONFields implements the EventPayload interface. -func (m *FinishSchemaChangeRollback) AppendJSONFields(printComma bool, b redact.RedactableBytes) (bool, redact.RedactableBytes) { +func (m *FirstQuery) AppendJSONFields(printComma bool, b redact.RedactableBytes) (bool, redact.RedactableBytes) { printComma, b = m.CommonEventDetails.AppendJSONFields(printComma, b) - printComma, b = m.CommonSchemaChangeEventDetails.AppendJSONFields(printComma, b) + printComma, b = m.CommonSQLEventDetails.AppendJSONFields(printComma, b) + + printComma, b = m.CommonSQLExecDetails.AppendJSONFields(printComma, b) return printComma, b } diff --git a/pkg/util/log/eventpb/sql_audit_events.pb.go b/pkg/util/log/eventpb/sql_audit_events.pb.go index 90b2553dc6cd..7c84510e966a 100644 --- a/pkg/util/log/eventpb/sql_audit_events.pb.go +++ b/pkg/util/log/eventpb/sql_audit_events.pb.go @@ -4,7 +4,6 @@ package eventpb import ( - encoding_binary "encoding/binary" fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" @@ -24,58 +23,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// CommonSQLExecDetails contains the field common to all SQL query logs. -type CommonSQLExecDetails struct { - // How the statement was being executed (exec/prepare, etc.) - ExecMode string `protobuf:"bytes,1,opt,name=exec_mode,json=execMode,proto3" json:",omitempty" redact:"nonsensitive"` - // Number of rows returned. For mutation statements (INSERT, etc) that - // do not produce result rows, this field reports the number of rows affected. - NumRows uint64 `protobuf:"varint,2,opt,name=num_rows,json=numRows,proto3" json:",omitempty"` - // The SQLSTATE code for the error, if an error was encountered. Empty/omitted if no error. - SQLSTATE string `protobuf:"bytes,3,opt,name=sqlstate,proto3" json:",omitempty" redact:"nonsensitive"` - // The text of the error if any. - ErrorText string `protobuf:"bytes,4,opt,name=error_text,json=errorText,proto3" json:",omitempty"` - // Age of the query in milliseconds. - Age float32 `protobuf:"fixed32,5,opt,name=age,proto3" json:",omitempty"` - // Number of retries, when the txn was reretried automatically by the server. - NumRetries uint32 `protobuf:"varint,6,opt,name=num_retries,json=numRetries,proto3" json:",omitempty"` - // Whether the query contains a full table scan. - FullTableScan bool `protobuf:"varint,7,opt,name=full_table_scan,json=fullTableScan,proto3" json:",omitempty"` - // Whether the query contains a full secondary index scan. - FullIndexScan bool `protobuf:"varint,8,opt,name=full_index_scan,json=fullIndexScan,proto3" json:",omitempty"` - // The sequence number of the SQL transaction inside its session. - TxnCounter uint32 `protobuf:"varint,9,opt,name=txn_counter,json=txnCounter,proto3" json:",omitempty"` -} - -func (m *CommonSQLExecDetails) Reset() { *m = CommonSQLExecDetails{} } -func (m *CommonSQLExecDetails) String() string { return proto.CompactTextString(m) } -func (*CommonSQLExecDetails) ProtoMessage() {} -func (*CommonSQLExecDetails) Descriptor() ([]byte, []int) { - return fileDescriptor_b7a82d5e93041841, []int{0} -} -func (m *CommonSQLExecDetails) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *CommonSQLExecDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *CommonSQLExecDetails) XXX_Merge(src proto.Message) { - xxx_messageInfo_CommonSQLExecDetails.Merge(m, src) -} -func (m *CommonSQLExecDetails) XXX_Size() int { - return m.Size() -} -func (m *CommonSQLExecDetails) XXX_DiscardUnknown() { - xxx_messageInfo_CommonSQLExecDetails.DiscardUnknown(m) -} - -var xxx_messageInfo_CommonSQLExecDetails proto.InternalMessageInfo - // SensitiveTableAccess is recorded when an access is performed to // a table marked as audited. type SensitiveTableAccess struct { @@ -92,7 +39,7 @@ func (m *SensitiveTableAccess) Reset() { *m = SensitiveTableAccess{} } func (m *SensitiveTableAccess) String() string { return proto.CompactTextString(m) } func (*SensitiveTableAccess) ProtoMessage() {} func (*SensitiveTableAccess) Descriptor() ([]byte, []int) { - return fileDescriptor_b7a82d5e93041841, []int{1} + return fileDescriptor_b7a82d5e93041841, []int{0} } func (m *SensitiveTableAccess) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -129,7 +76,7 @@ func (m *AdminQuery) Reset() { *m = AdminQuery{} } func (m *AdminQuery) String() string { return proto.CompactTextString(m) } func (*AdminQuery) ProtoMessage() {} func (*AdminQuery) Descriptor() ([]byte, []int) { - return fileDescriptor_b7a82d5e93041841, []int{2} + return fileDescriptor_b7a82d5e93041841, []int{1} } func (m *AdminQuery) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -173,7 +120,7 @@ func (m *SlowQuery) Reset() { *m = SlowQuery{} } func (m *SlowQuery) String() string { return proto.CompactTextString(m) } func (*SlowQuery) ProtoMessage() {} func (*SlowQuery) Descriptor() ([]byte, []int) { - return fileDescriptor_b7a82d5e93041841, []int{3} + return fileDescriptor_b7a82d5e93041841, []int{2} } func (m *SlowQuery) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -213,7 +160,7 @@ func (m *SlowQueryInternal) Reset() { *m = SlowQueryInternal{} } func (m *SlowQueryInternal) String() string { return proto.CompactTextString(m) } func (*SlowQueryInternal) ProtoMessage() {} func (*SlowQueryInternal) Descriptor() ([]byte, []int) { - return fileDescriptor_b7a82d5e93041841, []int{4} + return fileDescriptor_b7a82d5e93041841, []int{3} } func (m *SlowQueryInternal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -250,7 +197,7 @@ func (m *QueryExecute) Reset() { *m = QueryExecute{} } func (m *QueryExecute) String() string { return proto.CompactTextString(m) } func (*QueryExecute) ProtoMessage() {} func (*QueryExecute) Descriptor() ([]byte, []int) { - return fileDescriptor_b7a82d5e93041841, []int{5} + return fileDescriptor_b7a82d5e93041841, []int{4} } func (m *QueryExecute) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -276,7 +223,6 @@ func (m *QueryExecute) XXX_DiscardUnknown() { var xxx_messageInfo_QueryExecute proto.InternalMessageInfo func init() { - proto.RegisterType((*CommonSQLExecDetails)(nil), "cockroach.util.log.eventpb.CommonSQLExecDetails") proto.RegisterType((*SensitiveTableAccess)(nil), "cockroach.util.log.eventpb.SensitiveTableAccess") proto.RegisterType((*AdminQuery)(nil), "cockroach.util.log.eventpb.AdminQuery") proto.RegisterType((*SlowQuery)(nil), "cockroach.util.log.eventpb.SlowQuery") @@ -289,131 +235,33 @@ func init() { } var fileDescriptor_b7a82d5e93041841 = []byte{ - // 612 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x95, 0xcf, 0x4f, 0x13, 0x4f, - 0x18, 0xc6, 0xbb, 0x2d, 0x3f, 0xda, 0xb7, 0xf0, 0xfd, 0xc6, 0x09, 0x26, 0x1b, 0x12, 0xb7, 0xcd, - 0x5e, 0x28, 0x89, 0x6e, 0x15, 0x12, 0x0f, 0xde, 0x28, 0x90, 0x48, 0x82, 0x9a, 0xfe, 0x38, 0x79, - 0xd9, 0x0c, 0xd3, 0xd7, 0xba, 0x71, 0x76, 0x06, 0x76, 0x66, 0x61, 0xf9, 0x0f, 0x34, 0x7a, 0xe0, - 0xcf, 0xe2, 0xc8, 0x91, 0x53, 0xa3, 0xe5, 0xc6, 0xd1, 0xab, 0x17, 0x33, 0xb3, 0x05, 0x95, 0xda, - 0x88, 0x67, 0xbc, 0xf5, 0xc7, 0xf3, 0x7c, 0xde, 0x9d, 0x67, 0x9e, 0x37, 0x0b, 0x2b, 0xa9, 0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 0x61, 0x91, 0x0e, 0xcc, 0x98, - 0xb2, 0xd9, 0xc6, 0x54, 0xd7, 0x1e, 0xdf, 0x8e, 0xf9, 0xa3, 0xe6, 0x37, 0x90, 0x96, 0x65, 0x8a, - 0x93, 0xdf, 0x98, 0xa0, 0x31, 0x4e, 0x2b, 0x8e, 0x55, 0xbc, 0xa4, 0x31, 0x92, 0xe7, 0x50, 0xa5, - 0x36, 0xb5, 0x7c, 0x57, 0x66, 0xff, 0x6e, 0x57, 0x20, 0xf7, 0x9a, 0x6d, 0xf1, 0x3f, 0x14, 0x01, - 0x36, 0xfa, 0x71, 0x24, 0xda, 0x29, 0x26, 0xc7, 0x77, 0xfa, 0x12, 0xfc, 0xf7, 0x45, 0xa8, 0x74, - 0xb9, 0x3c, 0xfa, 0x17, 0x85, 0x7f, 0x52, 0x84, 0x7b, 0xd7, 0x51, 0xec, 0x98, 0xc5, 0x15, 0x94, - 0xdf, 0xed, 0x48, 0x3e, 0x16, 0x61, 0xc1, 0xc6, 0x61, 0x84, 0xa9, 0xc6, 0x3b, 0x9d, 0x46, 0x6b, - 0xf5, 0xf4, 0x8b, 0x57, 0x38, 0x1d, 0x79, 0xce, 0xd9, 0xc8, 0x73, 0xce, 0x47, 0x9e, 0xf3, 0x79, - 0xe4, 0x39, 0x27, 0x17, 0x5e, 0xe1, 0xec, 0xc2, 0x2b, 0x9c, 0x5f, 0x78, 0x85, 0xd7, 0xf3, 0x63, - 0xe6, 0xde, 0x9c, 0x7d, 0xed, 0xaf, 0x7f, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x35, 0xbf, 0x4c, 0x0f, - 0x72, 0x08, 0x00, 0x00, -} - -func (m *CommonSQLExecDetails) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CommonSQLExecDetails) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *CommonSQLExecDetails) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.TxnCounter != 0 { - i = encodeVarintSqlAuditEvents(dAtA, i, uint64(m.TxnCounter)) - i-- - dAtA[i] = 0x48 - } - if m.FullIndexScan { - i-- - if m.FullIndexScan { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x40 - } - if m.FullTableScan { - i-- - if m.FullTableScan { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x38 - } - if m.NumRetries != 0 { - i = encodeVarintSqlAuditEvents(dAtA, i, uint64(m.NumRetries)) - i-- - dAtA[i] = 0x30 - } - if m.Age != 0 { - i -= 4 - encoding_binary.LittleEndian.PutUint32(dAtA[i:], uint32(math.Float32bits(float32(m.Age)))) - i-- - dAtA[i] = 0x2d - } - if len(m.ErrorText) > 0 { - i -= len(m.ErrorText) - copy(dAtA[i:], m.ErrorText) - i = encodeVarintSqlAuditEvents(dAtA, i, uint64(len(m.ErrorText))) - i-- - dAtA[i] = 0x22 - } - if len(m.SQLSTATE) > 0 { - i -= len(m.SQLSTATE) - copy(dAtA[i:], m.SQLSTATE) - i = encodeVarintSqlAuditEvents(dAtA, i, uint64(len(m.SQLSTATE))) - i-- - dAtA[i] = 0x1a - } - if m.NumRows != 0 { - i = encodeVarintSqlAuditEvents(dAtA, i, uint64(m.NumRows)) - i-- - dAtA[i] = 0x10 - } - if len(m.ExecMode) > 0 { - i -= len(m.ExecMode) - copy(dAtA[i:], m.ExecMode) - i = encodeVarintSqlAuditEvents(dAtA, i, uint64(len(m.ExecMode))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil + // 411 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x94, 0x4d, 0x8b, 0xd3, 0x40, + 0x1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, 0x12, + 0x67, 0xb1, 0x24, 0xce, 0xab, 0xab, 0x1b, 0xe7, 0x68, 0xd7, 0x5e, 0xfc, 0x0f, 0xbe, 0x06, 0x00, + 0x00, 0xff, 0xff, 0x28, 0xba, 0x8b, 0x21, 0x74, 0x06, 0x00, 0x00, } func (m *SensitiveTableAccess) Marshal() (dAtA []byte, err error) { @@ -706,45 +554,6 @@ func encodeVarintSqlAuditEvents(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *CommonSQLExecDetails) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ExecMode) - if l > 0 { - n += 1 + l + sovSqlAuditEvents(uint64(l)) - } - if m.NumRows != 0 { - n += 1 + sovSqlAuditEvents(uint64(m.NumRows)) - } - l = len(m.SQLSTATE) - if l > 0 { - n += 1 + l + sovSqlAuditEvents(uint64(l)) - } - l = len(m.ErrorText) - if l > 0 { - n += 1 + l + sovSqlAuditEvents(uint64(l)) - } - if m.Age != 0 { - n += 5 - } - if m.NumRetries != 0 { - n += 1 + sovSqlAuditEvents(uint64(m.NumRetries)) - } - if m.FullTableScan { - n += 2 - } - if m.FullIndexScan { - n += 2 - } - if m.TxnCounter != 0 { - n += 1 + sovSqlAuditEvents(uint64(m.TxnCounter)) - } - return n -} - func (m *SensitiveTableAccess) Size() (n int) { if m == nil { return 0 @@ -834,260 +643,6 @@ func sovSqlAuditEvents(x uint64) (n int) { func sozSqlAuditEvents(x uint64) (n int) { return sovSqlAuditEvents(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *CommonSQLExecDetails) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CommonSQLExecDetails: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CommonSQLExecDetails: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExecMode", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - 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 ErrInvalidLengthSqlAuditEvents - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSqlAuditEvents - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ExecMode = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NumRows", wireType) - } - m.NumRows = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NumRows |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SQLSTATE", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - 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 ErrInvalidLengthSqlAuditEvents - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSqlAuditEvents - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SQLSTATE = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ErrorText", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - 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 ErrInvalidLengthSqlAuditEvents - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSqlAuditEvents - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ErrorText = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 5 { - return fmt.Errorf("proto: wrong wireType = %d for field Age", wireType) - } - var v uint32 - if (iNdEx + 4) > l { - return io.ErrUnexpectedEOF - } - v = uint32(encoding_binary.LittleEndian.Uint32(dAtA[iNdEx:])) - iNdEx += 4 - m.Age = float32(math.Float32frombits(v)) - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NumRetries", wireType) - } - m.NumRetries = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NumRetries |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field FullTableScan", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.FullTableScan = bool(v != 0) - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field FullIndexScan", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.FullIndexScan = bool(v != 0) - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TxnCounter", wireType) - } - m.TxnCounter = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSqlAuditEvents - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TxnCounter |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipSqlAuditEvents(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthSqlAuditEvents - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *SensitiveTableAccess) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/pkg/util/log/eventpb/sql_audit_events.proto b/pkg/util/log/eventpb/sql_audit_events.proto index 8cf8981c6b55..4c4538808a89 100644 --- a/pkg/util/log/eventpb/sql_audit_events.proto +++ b/pkg/util/log/eventpb/sql_audit_events.proto @@ -20,30 +20,6 @@ import "util/log/eventpb/events.proto"; // here, not protobuf. // *Really look at doc.go before modifying this file.* -// CommonSQLExecDetails contains the field common to all SQL query logs. -message CommonSQLExecDetails { - // How the statement was being executed (exec/prepare, etc.) - string exec_mode = 1 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""]; - // Number of rows returned. For mutation statements (INSERT, etc) that - // do not produce result rows, this field reports the number of rows affected. - uint64 num_rows = 2 [(gogoproto.jsontag) = ",omitempty"]; - // The SQLSTATE code for the error, if an error was encountered. Empty/omitted if no error. - string sqlstate = 3 [(gogoproto.customname) = "SQLSTATE", (gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""]; - // The text of the error if any. - string error_text = 4 [(gogoproto.jsontag) = ",omitempty"]; - // Age of the query in milliseconds. - float age = 5 [(gogoproto.jsontag) = ",omitempty"]; - // Number of retries, when the txn was reretried automatically by the server. - uint32 num_retries = 6 [(gogoproto.jsontag) = ",omitempty"]; - // Whether the query contains a full table scan. - bool full_table_scan = 7 [(gogoproto.jsontag) = ",omitempty"]; - // Whether the query contains a full secondary index scan. - bool full_index_scan = 8 [(gogoproto.jsontag) = ",omitempty"]; - // The sequence number of the SQL transaction inside its session. - uint32 txn_counter = 9 [(gogoproto.jsontag) = ",omitempty"]; -} - - // Category: SQL Access Audit Events // Channel: SENSITIVE_ACCESS // diff --git a/pkg/util/log/eventpb/telemetry.pb.go b/pkg/util/log/eventpb/telemetry.pb.go new file mode 100644 index 000000000000..0624864834ad --- /dev/null +++ b/pkg/util/log/eventpb/telemetry.pb.go @@ -0,0 +1,408 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: util/log/eventpb/telemetry.proto + +package eventpb + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// FirstQuery is reported every time a SQL server process runs a SQL query +// on behalf of an external client for the first time. +// (This excludes queries ran by internal executors.) +type FirstQuery struct { + CommonEventDetails `protobuf:"bytes,1,opt,name=common,proto3,embedded=common" json:""` + CommonSQLEventDetails `protobuf:"bytes,2,opt,name=sql,proto3,embedded=sql" json:""` + CommonSQLExecDetails `protobuf:"bytes,3,opt,name=exec,proto3,embedded=exec" json:""` +} + +func (m *FirstQuery) Reset() { *m = FirstQuery{} } +func (m *FirstQuery) String() string { return proto.CompactTextString(m) } +func (*FirstQuery) ProtoMessage() {} +func (*FirstQuery) Descriptor() ([]byte, []int) { + return fileDescriptor_3d317b4ad74be4f7, []int{0} +} +func (m *FirstQuery) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FirstQuery) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *FirstQuery) XXX_Merge(src proto.Message) { + xxx_messageInfo_FirstQuery.Merge(m, src) +} +func (m *FirstQuery) XXX_Size() int { + return m.Size() +} +func (m *FirstQuery) XXX_DiscardUnknown() { + xxx_messageInfo_FirstQuery.DiscardUnknown(m) +} + +var xxx_messageInfo_FirstQuery proto.InternalMessageInfo + +func init() { + proto.RegisterType((*FirstQuery)(nil), "cockroach.util.log.eventpb.FirstQuery") +} + +func init() { proto.RegisterFile("util/log/eventpb/telemetry.proto", fileDescriptor_3d317b4ad74be4f7) } + +var fileDescriptor_3d317b4ad74be4f7 = []byte{ + // 259 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x28, 0x2d, 0xc9, 0xcc, + 0xd1, 0xcf, 0xc9, 0x4f, 0xd7, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0x29, 0x48, 0xd2, 0x2f, 0x49, 0xcd, + 0x49, 0xcd, 0x4d, 0x2d, 0x29, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4a, 0xce, + 0x4f, 0xce, 0x2e, 0xca, 0x4f, 0x4c, 0xce,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, 0x51, 0xec, 0x50, 0x33, + 0x93, 0xd8, 0xc0, 0xa1, 0x67, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xaf, 0x73, 0x6a, 0x48, 0xb2, + 0x01, 0x00, 0x00, +} + +func (m *FirstQuery) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *FirstQuery) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FirstQuery) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.CommonSQLExecDetails.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTelemetry(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.CommonSQLEventDetails.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTelemetry(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.CommonEventDetails.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTelemetry(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintTelemetry(dAtA []byte, offset int, v uint64) int { + offset -= sovTelemetry(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *FirstQuery) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.CommonEventDetails.Size() + n += 1 + l + sovTelemetry(uint64(l)) + l = m.CommonSQLEventDetails.Size() + n += 1 + l + sovTelemetry(uint64(l)) + l = m.CommonSQLExecDetails.Size() + n += 1 + l + sovTelemetry(uint64(l)) + return n +} + +func sovTelemetry(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTelemetry(x uint64) (n int) { + return sovTelemetry(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *FirstQuery) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTelemetry + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: FirstQuery: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FirstQuery: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CommonEventDetails", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTelemetry + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTelemetry + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTelemetry + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CommonEventDetails.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CommonSQLEventDetails", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTelemetry + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTelemetry + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTelemetry + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CommonSQLEventDetails.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CommonSQLExecDetails", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTelemetry + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTelemetry + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTelemetry + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CommonSQLExecDetails.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTelemetry(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTelemetry + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTelemetry(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTelemetry + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTelemetry + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTelemetry + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTelemetry + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTelemetry + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTelemetry + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTelemetry = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTelemetry = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTelemetry = fmt.Errorf("proto: unexpected end of group") +) diff --git a/pkg/util/log/eventpb/telemetry.proto b/pkg/util/log/eventpb/telemetry.proto new file mode 100644 index 000000000000..85a50cbb9e0e --- /dev/null +++ b/pkg/util/log/eventpb/telemetry.proto @@ -0,0 +1,35 @@ +// Copyright 2021 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +syntax = "proto3"; +package cockroach.util.log.eventpb; +option go_package = "eventpb"; + +import "gogoproto/gogo.proto"; +import "util/log/eventpb/events.proto"; + +// Category: Telemetry events +// Channel: TELEMETRY +// + +// Notes to CockroachDB maintainers: refer to doc.go at the package +// level for more details. Beware that JSON compatibility rules apply +// here, not protobuf. +// The comment at the top has a specific format for the doc generator. +// *Really look at doc.go before modifying this file.* + +// FirstQuery is reported every time a SQL server process runs a SQL query +// on behalf of an external client for the first time. +// (This excludes queries ran by internal executors.) +message FirstQuery { + CommonEventDetails common = 1 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "", (gogoproto.embed) = true]; + CommonSQLEventDetails sql = 2 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "", (gogoproto.embed) = true]; + CommonSQLExecDetails exec = 3 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "", (gogoproto.embed) = true]; +} diff --git a/pkg/util/log/log_channels_generated.go b/pkg/util/log/log_channels_generated.go index cb63b6d4c835..7363448330c1 100644 --- a/pkg/util/log/log_channels_generated.go +++ b/pkg/util/log/log_channels_generated.go @@ -5296,7 +5296,7 @@ type loggerTelemetry struct{} // Telemetry is a logger that logs to the TELEMETRY channel. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. var Telemetry loggerTelemetry @@ -5312,12 +5312,12 @@ var _ ChannelLogger = Telemetry // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The INFO severity is used for informational messages, when no action -// is required as a result. +// The `INFO` severity is used for informational messages that do not +// require action. func (loggerTelemetry) Infof(ctx context.Context, format string, args ...interface{}) { logfDepth(ctx, 1, severity.INFO, channel.TELEMETRY, format, args...) } @@ -5328,12 +5328,12 @@ func (loggerTelemetry) Infof(ctx context.Context, format string, args ...interfa // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The INFO severity is used for informational messages, when no action -// is required as a result. +// The `INFO` severity is used for informational messages that do not +// require action. func (loggerTelemetry) VInfof(ctx context.Context, level Level, format string, args ...interface{}) { if VDepth(level, 1) { logfDepth(ctx, 1, severity.INFO, channel.TELEMETRY, format, args...) @@ -5344,12 +5344,12 @@ func (loggerTelemetry) VInfof(ctx context.Context, level Level, format string, a // It extracts log tags from the context and logs them along with the given // message. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The INFO severity is used for informational messages, when no action -// is required as a result. +// The `INFO` severity is used for informational messages that do not +// require action. func (loggerTelemetry) Info(ctx context.Context, msg string) { logfDepth(ctx, 1, severity.INFO, channel.TELEMETRY, msg) } @@ -5359,12 +5359,12 @@ func (loggerTelemetry) Info(ctx context.Context, msg string) { // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The INFO severity is used for informational messages, when no action -// is required as a result. +// The `INFO` severity is used for informational messages that do not +// require action. func (loggerTelemetry) InfofDepth(ctx context.Context, depth int, format string, args ...interface{}) { logfDepth(ctx, depth+1, severity.INFO, channel.TELEMETRY, format, args...) } @@ -5373,12 +5373,12 @@ func (loggerTelemetry) InfofDepth(ctx context.Context, depth int, format string, // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The WARNING severity is used for situations which may require special handling, -// while normal operation is expected to resume automatically. +// The `WARNING` severity is used for situations which may require special handling, +// where normal operation is expected to resume automatically. func (loggerTelemetry) Warningf(ctx context.Context, format string, args ...interface{}) { logfDepth(ctx, 1, severity.WARNING, channel.TELEMETRY, format, args...) } @@ -5389,12 +5389,12 @@ func (loggerTelemetry) Warningf(ctx context.Context, format string, args ...inte // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The WARNING severity is used for situations which may require special handling, -// while normal operation is expected to resume automatically. +// The `WARNING` severity is used for situations which may require special handling, +// where normal operation is expected to resume automatically. func (loggerTelemetry) VWarningf(ctx context.Context, level Level, format string, args ...interface{}) { if VDepth(level, 1) { logfDepth(ctx, 1, severity.WARNING, channel.TELEMETRY, format, args...) @@ -5405,12 +5405,12 @@ func (loggerTelemetry) VWarningf(ctx context.Context, level Level, format string // It extracts log tags from the context and logs them along with the given // message. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The WARNING severity is used for situations which may require special handling, -// while normal operation is expected to resume automatically. +// The `WARNING` severity is used for situations which may require special handling, +// where normal operation is expected to resume automatically. func (loggerTelemetry) Warning(ctx context.Context, msg string) { logfDepth(ctx, 1, severity.WARNING, channel.TELEMETRY, msg) } @@ -5420,12 +5420,12 @@ func (loggerTelemetry) Warning(ctx context.Context, msg string) { // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The WARNING severity is used for situations which may require special handling, -// while normal operation is expected to resume automatically. +// The `WARNING` severity is used for situations which may require special handling, +// where normal operation is expected to resume automatically. func (loggerTelemetry) WarningfDepth(ctx context.Context, depth int, format string, args ...interface{}) { logfDepth(ctx, depth+1, severity.WARNING, channel.TELEMETRY, format, args...) } @@ -5434,12 +5434,12 @@ func (loggerTelemetry) WarningfDepth(ctx context.Context, depth int, format stri // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The ERROR severity is used for situations that require special handling, -// when normal operation could not proceed as expected. +// The `ERROR` severity is used for situations that require special handling, +// where normal operation could not proceed as expected. // Other operations can continue mostly unaffected. func (loggerTelemetry) Errorf(ctx context.Context, format string, args ...interface{}) { logfDepth(ctx, 1, severity.ERROR, channel.TELEMETRY, format, args...) @@ -5451,12 +5451,12 @@ func (loggerTelemetry) Errorf(ctx context.Context, format string, args ...interf // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The ERROR severity is used for situations that require special handling, -// when normal operation could not proceed as expected. +// The `ERROR` severity is used for situations that require special handling, +// where normal operation could not proceed as expected. // Other operations can continue mostly unaffected. func (loggerTelemetry) VErrorf(ctx context.Context, level Level, format string, args ...interface{}) { if VDepth(level, 1) { @@ -5468,12 +5468,12 @@ func (loggerTelemetry) VErrorf(ctx context.Context, level Level, format string, // It extracts log tags from the context and logs them along with the given // message. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The ERROR severity is used for situations that require special handling, -// when normal operation could not proceed as expected. +// The `ERROR` severity is used for situations that require special handling, +// where normal operation could not proceed as expected. // Other operations can continue mostly unaffected. func (loggerTelemetry) Error(ctx context.Context, msg string) { logfDepth(ctx, 1, severity.ERROR, channel.TELEMETRY, msg) @@ -5484,12 +5484,12 @@ func (loggerTelemetry) Error(ctx context.Context, msg string) { // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The ERROR severity is used for situations that require special handling, -// when normal operation could not proceed as expected. +// The `ERROR` severity is used for situations that require special handling, +// where normal operation could not proceed as expected. // Other operations can continue mostly unaffected. func (loggerTelemetry) ErrorfDepth(ctx context.Context, depth int, format string, args ...interface{}) { logfDepth(ctx, depth+1, severity.ERROR, channel.TELEMETRY, format, args...) @@ -5499,11 +5499,11 @@ func (loggerTelemetry) ErrorfDepth(ctx context.Context, depth int, format string // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The FATAL severity is used for situations that require an immedate, hard +// The `FATAL` severity is used for situations that require an immedate, hard // server shutdown. A report is also sent to telemetry if telemetry // is enabled. func (loggerTelemetry) Fatalf(ctx context.Context, format string, args ...interface{}) { @@ -5516,11 +5516,11 @@ func (loggerTelemetry) Fatalf(ctx context.Context, format string, args ...interf // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The FATAL severity is used for situations that require an immedate, hard +// The `FATAL` severity is used for situations that require an immedate, hard // server shutdown. A report is also sent to telemetry if telemetry // is enabled. func (loggerTelemetry) VFatalf(ctx context.Context, level Level, format string, args ...interface{}) { @@ -5533,11 +5533,11 @@ func (loggerTelemetry) VFatalf(ctx context.Context, level Level, format string, // It extracts log tags from the context and logs them along with the given // message. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The FATAL severity is used for situations that require an immedate, hard +// The `FATAL` severity is used for situations that require an immedate, hard // server shutdown. A report is also sent to telemetry if telemetry // is enabled. func (loggerTelemetry) Fatal(ctx context.Context, msg string) { @@ -5549,11 +5549,11 @@ func (loggerTelemetry) Fatal(ctx context.Context, msg string) { // It extracts log tags from the context and logs them along with the given // message. Arguments are handled in the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. // -// The FATAL severity is used for situations that require an immedate, hard +// The `FATAL` severity is used for situations that require an immedate, hard // server shutdown. A report is also sent to telemetry if telemetry // is enabled. func (loggerTelemetry) FatalfDepth(ctx context.Context, depth int, format string, args ...interface{}) { @@ -5563,7 +5563,7 @@ func (loggerTelemetry) FatalfDepth(ctx context.Context, depth int, format string // Shout logs to channel TELEMETRY, and also to the real stderr if logging // is currently redirected to a file. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. func (loggerTelemetry) Shout(ctx context.Context, sev Severity, msg string) { @@ -5574,7 +5574,7 @@ func (loggerTelemetry) Shout(ctx context.Context, sev Severity, msg string) { // logging is currently redirected to a file. Arguments are handled in // the manner of fmt.Printf. // -// The TELEMETRY channel reports telemetry events. Telemetry events describe +// The `TELEMETRY` channel reports telemetry events. Telemetry events describe // feature usage within CockroachDB and anonymizes any application- // specific data. func (loggerTelemetry) Shoutf(ctx context.Context, sev Severity, format string, args ...interface{}) { diff --git a/pkg/util/log/testdata/config b/pkg/util/log/testdata/config index 98d2fc7a73e4..3cddc8e669ac 100644 --- a/pkg/util/log/testdata/config +++ b/pkg/util/log/testdata/config @@ -4,8 +4,7 @@ yaml sinks: file-groups: default: - channels: [DEV, OPS, HEALTH, STORAGE, SESSIONS, SQL_SCHEMA, USER_ADMIN, PRIVILEGES, - SENSITIVE_ACCESS, SQL_EXEC, SQL_PERF, SQL_INTERNAL_PERF] + channels: all dir: TMPDIR max-file-size: 10MiB max-group-size: 100MiB @@ -36,8 +35,7 @@ sinks: sinks: file-groups: default: - channels: [DEV, OPS, HEALTH, STORAGE, SESSIONS, SQL_SCHEMA, USER_ADMIN, PRIVILEGES, - SENSITIVE_ACCESS, SQL_EXEC, SQL_PERF, SQL_INTERNAL_PERF] + channels: all dir: TMPDIR max-file-size: 10MiB max-group-size: 100MiB