diff --git a/report/controls.go b/report/controls.go index dcf5cb3a6..fda4d1e0e 100644 --- a/report/controls.go +++ b/report/controls.go @@ -1,12 +1,5 @@ package report -import ( - "time" - - "github.com/ugorji/go/codec" - "github.com/weaveworks/common/mtime" -) - // Controls describe the control tags within the Nodes type Controls map[string]Control @@ -58,75 +51,6 @@ func (cs Controls) AddControls(controls []Control) { } } -// NodeControls represent the individual controls that are valid for a given -// node at a given point in time. It's immutable. A zero-value for Timestamp -// indicated this NodeControls is 'not set'. -type NodeControls struct { - Timestamp time.Time - Controls StringSet -} - -var emptyNodeControls = NodeControls{Controls: MakeStringSet()} - -// MakeNodeControls makes a new NodeControls -func MakeNodeControls() NodeControls { - return emptyNodeControls -} - -// Merge returns the newest of the two NodeControls; it does not take the union -// of the valid Controls. -func (nc NodeControls) Merge(other NodeControls) NodeControls { - if nc.Timestamp.Before(other.Timestamp) { - return other - } - return nc -} - -// Add the new control IDs to this NodeControls, producing a fresh NodeControls. -func (nc NodeControls) Add(ids ...string) NodeControls { - return NodeControls{ - Timestamp: mtime.Now(), - Controls: nc.Controls.Add(ids...), - } -} - -// WireNodeControls is the intermediate type for encoding/decoding. -// Only needed for backwards compatibility with probes -// (time.Time is encoded in binary in MsgPack) -type wireNodeControls struct { - Timestamp string `json:"timestamp,omitempty"` - Controls StringSet `json:"controls,omitempty"` - dummySelfer -} - -// CodecEncodeSelf implements codec.Selfer -func (nc *NodeControls) CodecEncodeSelf(encoder *codec.Encoder) { - encoder.Encode(wireNodeControls{ - Timestamp: renderTime(nc.Timestamp), - Controls: nc.Controls, - }) -} - -// CodecDecodeSelf implements codec.Selfer -func (nc *NodeControls) CodecDecodeSelf(decoder *codec.Decoder) { - in := wireNodeControls{} - in.CodecDecodeSelf(decoder) - *nc = NodeControls{ - Timestamp: parseTime(in.Timestamp), - Controls: in.Controls, - } -} - -// MarshalJSON shouldn't be used, use CodecEncodeSelf instead -func (NodeControls) MarshalJSON() ([]byte, error) { - panic("MarshalJSON shouldn't be used, use CodecEncodeSelf instead") -} - -// UnmarshalJSON shouldn't be used, use CodecDecodeSelf instead -func (*NodeControls) UnmarshalJSON(b []byte) error { - panic("UnmarshalJSON shouldn't be used, use CodecDecodeSelf instead") -} - // NodeControlData contains specific information about the control. It // is used as a Value field of LatestEntry in NodeControlDataLatestMap. type NodeControlData struct { diff --git a/report/metric_row.go b/report/metric_row.go index 470491c1f..666e8d006 100644 --- a/report/metric_row.go +++ b/report/metric_row.go @@ -69,7 +69,6 @@ type wiredMetricRow struct { // CodecEncodeSelf marshals this MetricRow. It takes the basic Metric // rendering, then adds some row-specific fields. func (m *MetricRow) CodecEncodeSelf(encoder *codec.Encoder) { - in := m.Metric.ToIntermediate() encoder.Encode(wiredMetricRow{ ID: m.ID, Label: m.Label, @@ -79,9 +78,9 @@ func (m *MetricRow) CodecEncodeSelf(encoder *codec.Encoder) { ValueEmpty: m.ValueEmpty, Priority: m.Priority, URL: m.URL, - Samples: in.Samples, - Min: in.Min, - Max: in.Max, + Samples: m.Metric.Samples, + Min: m.Metric.Min, + Max: m.Metric.Max, }) } @@ -89,12 +88,11 @@ func (m *MetricRow) CodecEncodeSelf(encoder *codec.Encoder) { func (m *MetricRow) CodecDecodeSelf(decoder *codec.Decoder) { var in wiredMetricRow decoder.Decode(&in) - w := WireMetrics{ + metric := Metric{ Samples: in.Samples, Min: in.Min, Max: in.Max, } - metric := w.FromIntermediate() *m = MetricRow{ ID: in.ID, Label: in.Label, diff --git a/report/metrics.go b/report/metrics.go index 2e0458c11..2d0f7e529 100644 --- a/report/metrics.go +++ b/report/metrics.go @@ -3,8 +3,6 @@ package report import ( "math" "time" - - "github.com/ugorji/go/codec" ) // Metrics is a string->metric map. @@ -48,8 +46,9 @@ func (m Metrics) Copy() Metrics { // Metric is a list of timeseries data with some metadata. Clients must use the // Add method to add values. Metrics are immutable. type Metric struct { - Samples []Sample - Min, Max float64 + Samples []Sample `json:"samples,omitempty"` + Min float64 `json:"min"` + Max float64 `json:"max"` } func (m Metric) first() time.Time { return m.Samples[0].Timestamp } @@ -182,71 +181,3 @@ func (m Metric) LastSample() (Sample, bool) { } return m.Samples[len(m.Samples)-1], true } - -// WireMetrics is the on-the-wire representation of Metrics. -// Only needed for backwards compatibility with probes -// (time.Time is encoded in binary in MsgPack) -type WireMetrics struct { - Samples []Sample `json:"samples,omitempty"` - Min float64 `json:"min"` - Max float64 `json:"max"` - dummySelfer -} - -func renderTime(t time.Time) string { - if t.IsZero() { - return "" - } - return t.Format(time.RFC3339Nano) -} - -func parseTime(s string) time.Time { - if s == "" { - return time.Time{} - } - t, _ := time.Parse(time.RFC3339Nano, s) - return t -} - -// ToIntermediate converts the metric to a representation suitable -// for serialization. -func (m Metric) ToIntermediate() WireMetrics { - return WireMetrics{ - Samples: m.Samples, - Max: m.Max, - Min: m.Min, - } -} - -// FromIntermediate obtains the metric from a representation suitable -// for serialization. -func (m WireMetrics) FromIntermediate() Metric { - return Metric{ - Samples: m.Samples, - Max: m.Max, - Min: m.Min, - } -} - -// CodecEncodeSelf implements codec.Selfer -func (m *Metric) CodecEncodeSelf(encoder *codec.Encoder) { - in := m.ToIntermediate() - encoder.Encode(in) -} - -// CodecDecodeSelf implements codec.Selfer -func (m *Metric) CodecDecodeSelf(decoder *codec.Decoder) { - in := WireMetrics{} - in.CodecDecodeSelf(decoder) - *m = in.FromIntermediate() -} - -// MarshalJSON shouldn't be used, use CodecEncodeSelf instead -func (Metric) MarshalJSON() ([]byte, error) { - panic("MarshalJSON shouldn't be used, use CodecEncodeSelf instead") -} - -// UnmarshalJSON shouldn't be used, use CodecDecodeSelf instead -func (*Metric) UnmarshalJSON(b []byte) error { - panic("UnmarshalJSON shouldn't be used, use CodecDecodeSelf instead") -}