Skip to content

Commit

Permalink
Ensures that the timestamp is set
Browse files Browse the repository at this point in the history
This issue was first reported in intelsdi-x#1118 but didn't address the TimeStamp.  This commit does.
  • Loading branch information
jcooklin committed Aug 19, 2016
1 parent 4e6b19d commit 7293a37
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions grpc/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,24 @@ func (m *metric) Unit() string { return m.unit }

// Convert common.Metric to core.Metric
func ToCoreMetric(mt *Metric) core.Metric {
var lastAdvertisedTime time.Time
var lastAdvertisedTime, timeStamp time.Time
// if the lastAdvertisedTime is not set we handle. -62135596800 represents the
// number of seconds from 0001-1970 and is the default value for time.Unix.
if mt.LastAdvertisedTime.Sec == int64(-62135596800) {
lastAdvertisedTime = time.Unix(time.Now().Unix(), int64(time.Now().Nanosecond()))
} else {
lastAdvertisedTime = time.Unix(mt.LastAdvertisedTime.Sec, mt.LastAdvertisedTime.Nsec)
}
if mt.Timestamp.Sec == int64(-62135596800) {
timeStamp = time.Unix(time.Now().Unix(), int64(time.Now().Nanosecond()))
} else {
timeStamp = time.Unix(mt.Timestamp.Sec, mt.Timestamp.Nsec)
}
ret := &metric{
namespace: ToCoreNamespace(mt.Namespace),
version: int(mt.Version),
tags: mt.Tags,
timeStamp: time.Unix(mt.Timestamp.Sec, mt.Timestamp.Nsec),
timeStamp: timeStamp,
lastAdvertisedTime: lastAdvertisedTime,
config: ConfigMapToConfig(mt.Config),
description: mt.Description,
Expand Down

0 comments on commit 7293a37

Please sign in to comment.