From eef559824312dad7e2ee11d20f946d073eeb5599 Mon Sep 17 00:00:00 2001 From: HuangCong <409438984@qq.com> Date: Fri, 2 Feb 2018 16:51:59 +0800 Subject: [PATCH] feat(message): 1.adapt time in message to local timezone 2.adapt duration unit --- alert/types.go | 11 +++++++++-- edge/messages.go | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/alert/types.go b/alert/types.go index f0d4dab8a..13659addf 100644 --- a/alert/types.go +++ b/alert/types.go @@ -18,12 +18,18 @@ type Event struct { } func (e Event) AlertData() Data { + // adopt time to local timezone + e.State.Time = e.State.Time.Local() + + // transform duration to string for human readability + d := e.State.Duration.String() + return Data{ ID: e.State.ID, Message: e.State.Message, Details: e.State.Details, Time: e.State.Time, - Duration: e.State.Duration, + Duration: d, Level: e.State.Level, Data: e.Data.Result, PreviousLevel: e.previousState.Level, @@ -175,7 +181,8 @@ type Data struct { Message string `json:"message"` Details string `json:"details"` Time time.Time `json:"time"` - Duration time.Duration `json:"duration"` + //Duration time.Duration `json:"duration"` + Duration string `json:"duration"` Level Level `json:"level"` Data models.Result `json:"data"` PreviousLevel Level `json:"previousLevel"` diff --git a/edge/messages.go b/edge/messages.go index 88a9b7f6a..7c10a6da3 100644 --- a/edge/messages.go +++ b/edge/messages.go @@ -325,6 +325,10 @@ func (pm *pointMessage) ToRow() *models.Row { row.Values = make([][]interface{}, 1) row.Values[0] = make([]interface{}, len(row.Columns)) + + // adopt time to local timezone, before store it into row + pm.time = pm.time.Local() + row.Values[0][0] = pm.time for i, c := range row.Columns[1:] { if v, ok := pm.fields[c]; ok {