Merge pull request #4035 from hashicorp/node-events-timestamps

Properly format node event timestamps
This commit is contained in:
Chelsea Komlo 2018-03-27 16:57:39 -04:00 committed by GitHub
commit 92a51471e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 11 additions and 10 deletions

View file

@ -212,7 +212,7 @@ type NodeEvent struct {
Message string
Subsystem string
Details map[string]string
Timestamp int64
Timestamp time.Time
CreateIndex uint64
}

View file

@ -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)
}

View file

@ -429,7 +429,7 @@ func (c *NodeStatusCommand) outputNodeEvent(events []*api.NodeEvent) {
}
for i, event := range events {
timestamp := formatUnixNanoTime(event.Timestamp)
timestamp := formatTime(event.Timestamp)
subsystem := event.Subsystem
msg := event.Message
if c.verbose {

View file

@ -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}

View file

@ -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}}

View file

@ -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

View file

@ -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{

View file

@ -1188,7 +1188,7 @@ type NodeEvent struct {
Message string
Subsystem string
Details map[string]string
Timestamp int64
Timestamp time.Time
CreateIndex uint64
}
@ -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 {