From 3605e9ccd498f4d5920c57c32809f3706a20b31d Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Fri, 18 Dec 2020 18:12:01 +0100 Subject: [PATCH] eventpb: make the Timestamp field an int64 While exploring how to use the data in practice, I noticed that the timestamp was encoded as a string in the JSON output, and that was making the events hard to parse and to use. There are many more functions that can operate on a number. Moreover, the integer representation is just more compact. Release note (api change): The 'Timestamp' field of structured notable events is now numeric, and encodes a number of nanoseconds since the unix epoch. (Note that this API has not yet been published in a released version of CockroachDB. The release note exists only to track the list of relevant items for the doc project.) --- docs/generated/eventlog.md | 110 +++++++++++++++--------------- pkg/server/node.go | 2 +- pkg/server/server.go | 2 +- pkg/sql/event_log.go | 11 ++- pkg/util/log/event_log.go | 6 +- pkg/util/log/eventpb/BUILD.bazel | 1 - pkg/util/log/eventpb/events.pb.go | 95 +++++++++++--------------- pkg/util/log/eventpb/events.proto | 5 +- 8 files changed, 105 insertions(+), 127 deletions(-) diff --git a/docs/generated/eventlog.md b/docs/generated/eventlog.md index 5299402c395d..af3fbb3633ae 100644 --- a/docs/generated/eventlog.md +++ b/docs/generated/eventlog.md @@ -23,7 +23,7 @@ decommissioned. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `RequestingNodeID` | The node ID where the event was originated. | | `TargetNodeID` | The node ID affected by the operation. | @@ -40,7 +40,7 @@ decommissioning. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `RequestingNodeID` | The node ID where the event was originated. | | `TargetNodeID` | The node ID affected by the operation. | @@ -56,7 +56,7 @@ An event of type `node_join` is recorded when a node joins the cluster. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `NodeID` | The node ID where the event was originated. | | `StartedAt` | The time when this node was last started. | @@ -74,7 +74,7 @@ recommissioned. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `RequestingNodeID` | The node ID where the event was originated. | | `TargetNodeID` | The node ID affected by the operation. | @@ -91,7 +91,7 @@ after being offline. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `NodeID` | The node ID where the event was originated. | | `StartedAt` | The time when this node was last started. | @@ -123,7 +123,7 @@ An event of type `set_cluster_setting` is recorded when a cluster setting is cha | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -158,7 +158,7 @@ An event of type `alter_index` is recorded when an index is altered. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -178,7 +178,7 @@ An event of type `alter_sequence` is recorded when a sequence is altered. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -200,7 +200,7 @@ An event of type `alter_table` is recorded when a table is altered. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -220,7 +220,7 @@ EventAlterType is recorded when a user-defined type is altered. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -243,7 +243,7 @@ An event of type `comment_on_column` is recorded when a column is commented. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -265,7 +265,7 @@ CommentOnTable is recorded when a database is commented. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -288,7 +288,7 @@ An event of type `comment_on_index` is recorded when an index is commented. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -310,7 +310,7 @@ An event of type `comment_on_table` is recorded when a table is commented. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -331,7 +331,7 @@ An event of type `convert_to_schema` is recorded when a database is converted to | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -351,7 +351,7 @@ An event of type `create_database` is recorded when a database is created. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -373,7 +373,7 @@ An event of type `create_index` is recorded when an index is created. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -394,7 +394,7 @@ An event of type `create_schema` is recorded when a schema is created. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -415,7 +415,7 @@ An event of type `create_sequence` is recorded when a sequence is created. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -439,7 +439,7 @@ Events of this type are only collected when the cluster setting | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -460,7 +460,7 @@ An event of type `create_table` is recorded when a table is created. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -481,7 +481,7 @@ An event of type `create_type` is recorded when a user-defined type is created. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -503,7 +503,7 @@ An event of type `create_view` is recorded when a view is created. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -524,7 +524,7 @@ An event of type `drop_database` is recorded when a database is dropped. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -547,7 +547,7 @@ An event of type `drop_index` is recorded when an index is dropped. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -567,7 +567,7 @@ An event of type `drop_schema` is recorded when a schema is dropped. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -587,7 +587,7 @@ An event of type `drop_sequence` is recorded when a sequence is dropped. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -608,7 +608,7 @@ An event of type `drop_table` is recorded when a table is dropped. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -628,7 +628,7 @@ An event of type `drop_type` is recorded when a user-defined type is dropped. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -649,7 +649,7 @@ An event of type `drop_view` is recorded when a view is dropped. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -667,7 +667,7 @@ change has completed. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `InstanceID` | The instance ID (not tenant ID) of the SQL server where the event was originated. | | `DescriptorID` | The primary object descriptor affected by the operation. Set to zero for operations that don't affect descriptors. | @@ -685,7 +685,7 @@ initiated schema change rollback has completed. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `InstanceID` | The instance ID (not tenant ID) of the SQL server where the event was originated. | | `DescriptorID` | The primary object descriptor affected by the operation. Set to zero for operations that don't affect descriptors. | @@ -706,7 +706,7 @@ An event of type `rename_database` is recorded when a database is renamed. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -727,7 +727,7 @@ An event of type `rename_schema` is recorded when a schema is renamed. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -748,7 +748,7 @@ An event of type `rename_table` is recorded when a table, sequence or view is re | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -769,7 +769,7 @@ An event of type `rename_type` is recorded when a user-defined type is renamed. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -791,7 +791,7 @@ encounters a problem and is reversed. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `InstanceID` | The instance ID (not tenant ID) of the SQL server where the event was originated. | | `DescriptorID` | The primary object descriptor affected by the operation. Set to zero for operations that don't affect descriptors. | @@ -811,7 +811,7 @@ An event of type `truncate_table` is recorded when a table is truncated. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -839,7 +839,7 @@ patch releases without advance notice. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -867,7 +867,7 @@ patch releases without advance notice. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -891,7 +891,7 @@ using crdb_internal.unsafe_upsert_descriptor(). | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -921,7 +921,7 @@ patch releases without advance notice. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -955,7 +955,7 @@ An event of type `alter_database_owner` is recorded when a database's owner is c | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -976,7 +976,7 @@ An event of type `alter_schema_owner` is recorded when a schema's owner is chang | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -997,7 +997,7 @@ An event of type `alter_table_owner` is recorded when the owner of a table, view | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1018,7 +1018,7 @@ An event of type `alter_type_owner` is recorded when the owner of a user-defiend | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1039,7 +1039,7 @@ added to / removed from a user for a database object. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1063,7 +1063,7 @@ removed from a user for a schema object. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1087,7 +1087,7 @@ from a user for a table, sequence or view object. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1111,7 +1111,7 @@ removed from a user for a type object. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1147,7 +1147,7 @@ An event of type `alter_role` is recorded when a role is altered. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1167,7 +1167,7 @@ An event of type `create_role` is recorded when a role is created. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1187,7 +1187,7 @@ An event of type `drop_role` is recorded when a role is dropped. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1220,7 +1220,7 @@ An event of type `remove_zone_config` is recorded when a zone config is removed. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | @@ -1240,7 +1240,7 @@ An event of type `set_zone_config` is recorded when a zone config is changed. | Field | Description | |--|--| -| `Timestamp` | The timestamp of the event. | +| `Timestamp` | The timestamp of the event. Expressed as nanoseconds since the Unix epoch. | | `EventType` | The type of the event. | | `Statement` | A normalized copy of the SQL statement that triggered the event. | | `User` | The user account that triggered the event. | diff --git a/pkg/server/node.go b/pkg/server/node.go index 14c46702c75a..970180b2b5f5 100644 --- a/pkg/server/node.go +++ b/pkg/server/node.go @@ -797,7 +797,7 @@ func (n *Node) recordJoinEvent(ctx context.Context) { nodeDetails = &ev.CommonNodeEventDetails nodeDetails.LastUp = n.startedAt } - event.CommonDetails().Timestamp = timeutil.Now() + event.CommonDetails().Timestamp = timeutil.Now().UnixNano() nodeDetails.StartedAt = n.startedAt nodeDetails.NodeID = int32(n.Descriptor.NodeID) diff --git a/pkg/server/server.go b/pkg/server/server.go index e01f1e885c7c..32e8a93191ed 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -2032,7 +2032,7 @@ func (s *Server) Decommission( } else { panic("unexpected target membership status") } - event.CommonDetails().Timestamp = timeutil.Now() + event.CommonDetails().Timestamp = timeutil.Now().UnixNano() nodeDetails.RequestingNodeID = int32(s.NodeID()) for _, nodeID := range nodeIDs { diff --git a/pkg/sql/event_log.go b/pkg/sql/event_log.go index 8bf879b9ecc6..9eb1e4f2efe2 100644 --- a/pkg/sql/event_log.go +++ b/pkg/sql/event_log.go @@ -13,7 +13,6 @@ package sql import ( "context" "encoding/json" - "time" "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/kv" @@ -23,6 +22,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/log/eventpb" + "github.com/cockroachdb/cockroach/pkg/util/timeutil" "github.com/cockroachdb/errors" ) @@ -49,7 +49,7 @@ func logEventInternalForSchemaChanges( mutationID descpb.MutationID, event eventpb.EventPayload, ) error { - event.CommonDetails().Timestamp = txn.ReadTimestamp().GoTime() + event.CommonDetails().Timestamp = txn.ReadTimestamp().WallTime scCommon, ok := event.(eventpb.EventWithCommonSchemaChangePayload) if !ok { return errors.AssertionFailedf("unknown event type: %T", event) @@ -84,7 +84,7 @@ func logEventInternalForSQLStatements( event eventpb.EventPayload, ) error { // Inject the common fields into the payload provided by the caller. - event.CommonDetails().Timestamp = txn.ReadTimestamp().GoTime() + event.CommonDetails().Timestamp = txn.ReadTimestamp().WallTime sqlCommon, ok := event.(eventpb.EventWithCommonSQLPayload) if !ok { return errors.AssertionFailedf("unknown event type: %T", event) @@ -135,8 +135,7 @@ func InsertEventRecord( info.CommonDetails().EventType = eventType // The caller is responsible for the timestamp field. - var zeroTime time.Time - if info.CommonDetails().Timestamp == zeroTime { + if info.CommonDetails().Timestamp == 0 { return errors.AssertionFailedf("programming error: timestamp field in event not populated: %T", info) } @@ -160,7 +159,7 @@ VALUES( ) ` args := []interface{}{ - info.CommonDetails().Timestamp, + timeutil.Unix(0, info.CommonDetails().Timestamp), eventType, targetID, reportingID, diff --git a/pkg/util/log/event_log.go b/pkg/util/log/event_log.go index aef95b12ede4..b58869e2009b 100644 --- a/pkg/util/log/event_log.go +++ b/pkg/util/log/event_log.go @@ -13,7 +13,6 @@ package log import ( "context" "encoding/json" - "time" "github.com/cockroachdb/cockroach/pkg/util/log/eventpb" "github.com/cockroachdb/cockroach/pkg/util/log/severity" @@ -24,9 +23,8 @@ import ( func StructuredEvent(ctx context.Context, event eventpb.EventPayload) { // Populate the missing common fields. common := event.CommonDetails() - var zeroTime time.Time - if common.Timestamp == zeroTime { - common.Timestamp = timeutil.Now() + if common.Timestamp == 0 { + common.Timestamp = timeutil.Now().UnixNano() } if len(common.EventType) == 0 { common.EventType = eventpb.GetEventTypeName(event) diff --git a/pkg/util/log/eventpb/BUILD.bazel b/pkg/util/log/eventpb/BUILD.bazel index c46efe8ac63d..2249b5836819 100644 --- a/pkg/util/log/eventpb/BUILD.bazel +++ b/pkg/util/log/eventpb/BUILD.bazel @@ -19,6 +19,5 @@ go_library( deps = [ "//pkg/util/log/logpb", "//vendor/github.com/gogo/protobuf/proto", - "//vendor/github.com/gogo/protobuf/types", ], ) diff --git a/pkg/util/log/eventpb/events.pb.go b/pkg/util/log/eventpb/events.pb.go index 8671fc81b7b1..04c3439a7cab 100644 --- a/pkg/util/log/eventpb/events.pb.go +++ b/pkg/util/log/eventpb/events.pb.go @@ -7,17 +7,12 @@ import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" -import time "time" - -import github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - import io "io" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf -var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -27,8 +22,9 @@ const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package // CommonEventDetails contains the fields common to all events. type CommonEventDetails struct { - // The timestamp of the event. - Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:",omitempty"` + // The timestamp of the event. Expressed as nanoseconds since + // the Unix epoch. + Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:",omitempty"` // The type of the event. EventType string `protobuf:"bytes,2,opt,name=event_type,json=eventType,proto3" json:",omitempty"` } @@ -37,7 +33,7 @@ func (m *CommonEventDetails) Reset() { *m = CommonEventDetails{} } func (m *CommonEventDetails) String() string { return proto.CompactTextString(m) } func (*CommonEventDetails) ProtoMessage() {} func (*CommonEventDetails) Descriptor() ([]byte, []int) { - return fileDescriptor_events_c14fc1553166d5db, []int{0} + return fileDescriptor_events_af259c089003d773, []int{0} } func (m *CommonEventDetails) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -78,7 +74,7 @@ func (m *CommonSQLEventDetails) Reset() { *m = CommonSQLEventDetails{} } func (m *CommonSQLEventDetails) String() string { return proto.CompactTextString(m) } func (*CommonSQLEventDetails) ProtoMessage() {} func (*CommonSQLEventDetails) Descriptor() ([]byte, []int) { - return fileDescriptor_events_c14fc1553166d5db, []int{1} + return fileDescriptor_events_af259c089003d773, []int{1} } func (m *CommonSQLEventDetails) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -122,14 +118,11 @@ func (m *CommonEventDetails) MarshalTo(dAtA []byte) (int, error) { _ = i var l int _ = l - dAtA[i] = 0xa - i++ - i = encodeVarintEvents(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp))) - n1, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i:]) - if err != nil { - return 0, err + if m.Timestamp != 0 { + dAtA[i] = 0x8 + i++ + i = encodeVarintEvents(dAtA, i, uint64(m.Timestamp)) } - i += n1 if len(m.EventType) > 0 { dAtA[i] = 0x12 i++ @@ -189,8 +182,9 @@ func (m *CommonEventDetails) Size() (n int) { } var l int _ = l - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp) - n += 1 + l + sovEvents(uint64(l)) + if m.Timestamp != 0 { + n += 1 + sovEvents(uint64(m.Timestamp)) + } l = len(m.EventType) if l > 0 { n += 1 + l + sovEvents(uint64(l)) @@ -261,10 +255,10 @@ func (m *CommonEventDetails) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 2 { + if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) } - var msglen int + m.Timestamp = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvents @@ -274,22 +268,11 @@ func (m *CommonEventDetails) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= (int(b) & 0x7F) << shift + m.Timestamp |= (int64(b) & 0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { - return ErrInvalidLengthEvents - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EventType", wireType) @@ -573,31 +556,29 @@ var ( ) func init() { - proto.RegisterFile("util/log/eventpb/events.proto", fileDescriptor_events_c14fc1553166d5db) + proto.RegisterFile("util/log/eventpb/events.proto", fileDescriptor_events_af259c089003d773) } -var fileDescriptor_events_c14fc1553166d5db = []byte{ - // 338 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xc1, 0x4e, 0xfa, 0x30, - 0x1c, 0xc7, 0xd7, 0xff, 0xdf, 0x68, 0x56, 0xc1, 0xc3, 0xa2, 0x86, 0x2c, 0xb1, 0x23, 0x9c, 0x30, - 0xc1, 0x2e, 0xd1, 0x37, 0x18, 0x78, 0x20, 0xf1, 0xa0, 0xc8, 0xc9, 0x0b, 0x19, 0xa3, 0xce, 0xc5, - 0x95, 0x5f, 0xb3, 0xfd, 0x30, 0xe1, 0x2d, 0xb8, 0xf8, 0x1a, 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ed, 0x17, 0x4f, 0x01, 0x58, 0x35, 0xba, 0x37, 0x4a, 0x45, 0xf2, 0xc7, 0x85, 0x7a, 0x66, - 0x35, 0x69, 0x79, 0x20, 0xd2, 0x20, 0x89, 0x14, 0x42, 0xd2, 0x8b, 0x06, 0x95, 0xff, 0x55, 0x52, - 0x2f, 0x7b, 0x2c, 0x5b, 0x38, 0xa5, 0x56, 0x31, 0x68, 0xb7, 0x7e, 0x84, 0x4b, 0xdb, 0x50, 0x7b, - 0xe0, 0x9d, 0x4f, 0x3f, 0x99, 0x31, 0xcd, 0x18, 0x99, 0x65, 0x8c, 0xcc, 0x33, 0x46, 0x3e, 0x32, - 0x46, 0x26, 0x4b, 0x66, 0xcc, 0x96, 0xcc, 0x98, 0x2f, 0x99, 0xf1, 0x70, 0xb0, 0xfe, 0xaa, 0xfe, - 0xbe, 0x7e, 0xc1, 0xab, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x6e, 0x0b, 0x2e, 0xa7, 0xee, 0x01, - 0x00, 0x00, +var fileDescriptor_events_af259c089003d773 = []byte{ + // 310 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0xd1, 0xcd, 0x4e, 0x02, 0x31, + 0x10, 0x07, 0xf0, 0xad, 0x18, 0x0d, 0x0d, 0x78, 0xd8, 0x68, 0x42, 0x48, 0x2c, 0x84, 0x13, 0x26, + 0xb8, 0x7b, 0xf0, 0x0d, 0x00, 0x0f, 0x24, 0x5e, 0xfc, 0x38, 0x79, 0x21, 0xcb, 0x32, 0xd6, 0xc6, + 0x2d, 0x53, 0xb7, 0x83, 0x09, 0x6f, 0xe1, 0x93, 0xf8, 0x1c, 0x1c, 0x39, 0x72, 0x22, 0xba, 0xdc, + 0x7c, 0x0a, 0x43, 0x97, 0x2c, 0x09, 0xea, 0xa9, 0x6d, 0xe6, 0x37, 0xf3, 0x6f, 0x5a, 0x7e, 0x3e, +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x62, 0xfe, 0x25, 0xbc, 0x79, 0x26, 0xd8, 0x22, 0x13, 0x6c, + 0x99, 0x09, 0xf6, 0x99, 0x09, 0xf6, 0xbe, 0x16, 0xde, 0x62, 0x2d, 0xbc, 0xe5, 0x5a, 0x78, 0x8f, + 0xc7, 0xdb, 0x5f, 0x18, 0x1d, 0xb9, 0x57, 0xbd, 0xfa, 0x09, 0x00, 0x00, 0xff, 0xff, 0xac, 0x31, + 0x05, 0x15, 0xc9, 0x01, 0x00, 0x00, } diff --git a/pkg/util/log/eventpb/events.proto b/pkg/util/log/eventpb/events.proto index 639d0a45c2a5..ca2a1314c7de 100644 --- a/pkg/util/log/eventpb/events.proto +++ b/pkg/util/log/eventpb/events.proto @@ -24,8 +24,9 @@ import "google/protobuf/timestamp.proto"; // CommonEventDetails contains the fields common to all events. message CommonEventDetails { - // The timestamp of the event. - google.protobuf.Timestamp timestamp = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true, (gogoproto.jsontag) = ",omitempty"]; + // The timestamp of the event. Expressed as nanoseconds since + // the Unix epoch. + int64 timestamp = 1 [(gogoproto.jsontag) = ",omitempty"]; // The type of the event. string event_type = 2 [(gogoproto.jsontag) = ",omitempty"]; }