Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
IRCody committed Aug 22, 2016
1 parent 168d842 commit 2d9ba06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
16 changes: 14 additions & 2 deletions control/plugin/client/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion control/plugin/rpc/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 0 additions & 2 deletions scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2d9ba06

Please sign in to comment.