From 6e35eec31ea2a841eb36f0a94aaa6d9c7b4e04e9 Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Fri, 23 Mar 2018 14:41:56 -0400 Subject: [PATCH 1/4] properly formatting unix timestamps --- command/node_status.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/node_status.go b/command/node_status.go index b80411434..e3bb9baeb 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -429,7 +429,7 @@ func (c *NodeStatusCommand) outputNodeEvent(events []*api.NodeEvent) { } for i, event := range events { - timestamp := formatUnixNanoTime(event.Timestamp) + timestamp := formatTime(time.Unix(event.Timestamp, 0)) subsystem := event.Subsystem msg := event.Message if c.verbose { From 041786360e8abca73beeac0f0e86a10cca2ff136 Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Tue, 27 Mar 2018 13:22:29 -0400 Subject: [PATCH 2/4] use time.Time for node events for compatibility --- api/nodes.go | 2 +- client/client.go | 2 +- command/node_status.go | 2 +- nomad/state/state_store.go | 3 ++- nomad/structs/structs.go | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/nodes.go b/api/nodes.go index 76e25594f..de73e12c4 100644 --- a/api/nodes.go +++ b/api/nodes.go @@ -212,7 +212,7 @@ type NodeEvent struct { Message string Subsystem string Details map[string]string - Timestamp int64 + Timestamp time.Time CreateIndex uint64 } diff --git a/client/client.go b/client/client.go index f1022f444..432c5b815 100644 --- a/client/client.go +++ b/client/client.go @@ -1069,7 +1069,7 @@ func (c *Client) updateNodeFromDriver(name string, fingerprint, health *structs. event := &structs.NodeEvent{ Subsystem: "Driver", Message: health.HealthDescription, - Timestamp: time.Now().Unix(), + Timestamp: time.Now(), } c.triggerNodeEvent(event) } diff --git a/command/node_status.go b/command/node_status.go index e3bb9baeb..c914950a2 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -429,7 +429,7 @@ func (c *NodeStatusCommand) outputNodeEvent(events []*api.NodeEvent) { } for i, event := range events { - timestamp := formatTime(time.Unix(event.Timestamp, 0)) + timestamp := formatTime(event.Timestamp) subsystem := event.Subsystem msg := event.Message if c.verbose { diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 6e4f3978d..e5ce02838 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -6,6 +6,7 @@ import ( "io" "log" "sort" + "time" "github.com/hashicorp/go-memdb" multierror "github.com/hashicorp/go-multierror" @@ -538,7 +539,7 @@ func (s *StateStore) UpsertNode(index uint64, node *structs.Node) error { nodeEvent := &structs.NodeEvent{ Message: "Node Registered", Subsystem: "Cluster", - Timestamp: node.StatusUpdatedAt, + Timestamp: time.Unix(node.StatusUpdatedAt, 0), } node.Events = []*structs.NodeEvent{nodeEvent} node.CreateIndex = index diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index ed18588f5..570fccb2c 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1188,7 +1188,7 @@ type NodeEvent struct { Message string Subsystem string Details map[string]string - Timestamp int64 + Timestamp time.Time CreateIndex uint64 } From 4dd4c37d17454e12308f7346f4dfe2fcae567bcb Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Tue, 27 Mar 2018 13:50:09 -0400 Subject: [PATCH 3/4] move tests to use time.Time --- nomad/fsm_test.go | 2 +- nomad/node_endpoint_test.go | 2 +- nomad/state/state_store_test.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nomad/fsm_test.go b/nomad/fsm_test.go index ed8cf2df5..47ac8f05b 100644 --- a/nomad/fsm_test.go +++ b/nomad/fsm_test.go @@ -91,7 +91,7 @@ func TestFSM_UpsertNodeEvents(t *testing.T) { nodeEvent := &structs.NodeEvent{ Message: "Heartbeating failed", Subsystem: "Heartbeat", - Timestamp: time.Now().Unix(), + Timestamp: time.Now(), } nodeEvents := []*structs.NodeEvent{nodeEvent} diff --git a/nomad/node_endpoint_test.go b/nomad/node_endpoint_test.go index cf89d98a6..5cace3140 100644 --- a/nomad/node_endpoint_test.go +++ b/nomad/node_endpoint_test.go @@ -2864,7 +2864,7 @@ func TestClientEndpoint_EmitEvents(t *testing.T) { nodeEvent := &structs.NodeEvent{ Message: "Registration failed", Subsystem: "Server", - Timestamp: time.Now().Unix(), + Timestamp: time.Now(), } nodeEvents := map[string][]*structs.NodeEvent{node.ID: {nodeEvent}} diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 9f13dd10b..dd085bb9e 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -802,7 +802,7 @@ func TestStateStore_AddSingleNodeEvent(t *testing.T) { nodeEvent := &structs.NodeEvent{ Message: "failed", Subsystem: "Driver", - Timestamp: time.Now().Unix(), + Timestamp: time.Now(), } nodeEvents := map[string][]*structs.NodeEvent{ node.ID: {nodeEvent}, @@ -845,7 +845,7 @@ func TestStateStore_NodeEvents_RetentionWindow(t *testing.T) { nodeEvent := &structs.NodeEvent{ Message: fmt.Sprintf("%dith failed", i), Subsystem: "Driver", - Timestamp: time.Now().Unix(), + Timestamp: time.Now(), } nodeEvents := map[string][]*structs.NodeEvent{ From 5c51404e8b6eb2e4c9d4104fec35bc832877286b Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Tue, 27 Mar 2018 15:21:02 -0400 Subject: [PATCH 4/4] fix up to string to use time.Time --- nomad/structs/structs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 570fccb2c..9e0db1659 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1198,7 +1198,7 @@ func (ne *NodeEvent) String() string { details = append(details, fmt.Sprintf("%s: %s", k, v)) } - return fmt.Sprintf("Message: %s, Subsystem: %s, Details: %s, Timestamp: %d", ne.Message, ne.Subsystem, strings.Join(details, ","), ne.Timestamp) + return fmt.Sprintf("Message: %s, Subsystem: %s, Details: %s, Timestamp: %s", ne.Message, ne.Subsystem, strings.Join(details, ","), ne.Timestamp.String()) } func (ne *NodeEvent) Copy() *NodeEvent {