From 2d9ba062fa66dd9214c38eaa74f1e67218bbbb07 Mon Sep 17 00:00:00 2001 From: Cody Roseborough Date: Mon, 22 Aug 2016 12:01:31 -0700 Subject: [PATCH] Address PR comments --- control/plugin/client/native.go | 16 ++++++++++++++-- control/plugin/rpc/plugin.go | 13 ++++++++++++- scheduler/scheduler.go | 2 -- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/control/plugin/client/native.go b/control/plugin/client/native.go index a42040401..7c92237fc 100644 --- a/control/plugin/client/native.go +++ b/control/plugin/client/native.go @@ -94,16 +94,26 @@ func (p *PluginNativeClient) Kill(reason string) error { return err } +// Used to catch zero values for times and overwrite with current time +// the 0 value for time.Time is year 1 which isn't a valid value for metric +// collection (until we get a time machine). +func checkTime(in time.Time) time.Time { + if in.Year() < 1970 { + return time.Now() + } + return in +} + func encodeMetrics(metrics []core.Metric) []byte { mts := make([]plugin.MetricType, len(metrics)) for i, m := range metrics { mts[i] = plugin.MetricType{ Namespace_: m.Namespace(), Tags_: m.Tags(), - Timestamp_: m.Timestamp(), + Timestamp_: checkTime(m.Timestamp()), Version_: m.Version(), Config_: m.Config(), - LastAdvertisedTime_: m.LastAdvertisedTime(), + LastAdvertisedTime_: checkTime(m.LastAdvertisedTime()), Unit_: m.Unit(), Description_: m.Description(), Data_: m.Data(), @@ -123,6 +133,8 @@ func decodeMetrics(bts []byte) ([]core.Metric, error) { } var cmetrics []core.Metric for _, mt := range mts { + mt.Timestamp_ = checkTime(mt.Timestamp()) + mt.LastAdvertisedTime_ = checkTime(mt.LastAdvertisedTime()) cmetrics = append(cmetrics, mt) } return cmetrics, nil diff --git a/control/plugin/rpc/plugin.go b/control/plugin/rpc/plugin.go index 3737e65d3..2dfcbd3d3 100644 --- a/control/plugin/rpc/plugin.go +++ b/control/plugin/rpc/plugin.go @@ -3,10 +3,18 @@ package rpc import ( "strings" + log "github.com/Sirupsen/logrus" + "github.com/intelsdi-x/snap/control/plugin/cpolicy" "github.com/intelsdi-x/snap/core/ctypes" ) +var ( + rpcLogger = log.WithFields(log.Fields{ + "_module": "rpc", + }) +) + // NewGetConfigPolicyReply given a config *cpolicy.ConfigPolicy returns a GetConfigPolicyReply. func NewGetConfigPolicyReply(policy *cpolicy.ConfigPolicy) (*GetConfigPolicyReply, error) { ret := &GetConfigPolicyReply{ @@ -98,7 +106,7 @@ func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy { br, err = cpolicy.NewBoolRule(key, val.Required) } if err != nil { - // The only error that can be thrown is empty key error, ignore something with empty key + log.Warn("Empty key found with value %v", val) continue } nodes[k].Add(br) @@ -118,6 +126,7 @@ func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy { sr, err = cpolicy.NewStringRule(key, val.Required) } if err != nil { + log.Warn("Empty key found with value %v", val) continue } @@ -138,6 +147,7 @@ func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy { ir, err = cpolicy.NewIntegerRule(key, val.Required) } if err != nil { + log.Warn("Empty key found with value %v", val) continue } if val.HasMin { @@ -165,6 +175,7 @@ func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy { fr, err = cpolicy.NewFloatRule(key, val.Required) } if err != nil { + log.Warn("Empty key found with value %v", val) continue } diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index ba39afa7b..b863d928f 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -100,12 +100,10 @@ type collectsMetrics interface { type publishesMetrics interface { PublishMetrics([]core.Metric, map[string]ctypes.ConfigValue, string, string, int) []error - //PublishMetrics(contentType string, content []byte, pluginName string, pluginVersion int, config map[string]ctypes.ConfigValue, taskID string) []error } type processesMetrics interface { ProcessMetrics([]core.Metric, map[string]ctypes.ConfigValue, string, string, int) ([]core.Metric, []error) - //ProcessMetrics(contentType string, content []byte, pluginName string, pluginVersion int, config map[string]ctypes.ConfigValue, taskID string) (string, []byte, []error) } type scheduler struct {