diff --git a/statsd/aggregator.go b/statsd/aggregator.go index b9b9d15e..65c050ed 100644 --- a/statsd/aggregator.go +++ b/statsd/aggregator.go @@ -14,9 +14,6 @@ type ( bufferedMetricMap map[string]*bufferedMetric ) -// noTimestamp is used as a value for metric without a given timestamp. -const noTimestamp = int64(0) - type aggregator struct { nbContextGauge uint64 nbContextCount uint64 diff --git a/statsd/buffer.go b/statsd/buffer.go index 9a01fbb3..f7bb8b0a 100644 --- a/statsd/buffer.go +++ b/statsd/buffer.go @@ -45,9 +45,7 @@ func (b *statsdBuffer) writeGauge(namespace string, globalTags []string, name st } originalBuffer := b.buffer b.buffer = appendGauge(b.buffer, namespace, globalTags, name, value, tags, rate) - if timestamp != noTimestamp { - b.buffer = appendTimestamp(b.buffer, timestamp) - } + b.buffer = appendTimestamp(b.buffer, timestamp) b.writeSeparator() return b.validateNewElement(originalBuffer) } @@ -58,9 +56,7 @@ func (b *statsdBuffer) writeCount(namespace string, globalTags []string, name st } originalBuffer := b.buffer b.buffer = appendCount(b.buffer, namespace, globalTags, name, value, tags, rate) - if timestamp != noTimestamp { - b.buffer = appendTimestamp(b.buffer, timestamp) - } + b.buffer = appendTimestamp(b.buffer, timestamp) b.writeSeparator() return b.validateNewElement(originalBuffer) } diff --git a/statsd/format.go b/statsd/format.go index 43ea2730..7513edd6 100644 --- a/statsd/format.go +++ b/statsd/format.go @@ -272,7 +272,9 @@ func appendContainerID(buffer []byte) []byte { } func appendTimestamp(buffer []byte, timestamp int64) []byte { - buffer = append(buffer, "|T"...) - buffer = strconv.AppendInt(buffer, timestamp, 10) + if timestamp != noTimestamp { + buffer = append(buffer, "|T"...) + buffer = strconv.AppendInt(buffer, timestamp, 10) + } return buffer } diff --git a/statsd/statsd.go b/statsd/statsd.go index fb85a19b..3d1d99fb 100644 --- a/statsd/statsd.go +++ b/statsd/statsd.go @@ -126,6 +126,9 @@ const ( writerWindowsPipe string = "pipe" ) +// noTimestamp is used as a value for metric without a given timestamp. +const noTimestamp = int64(0) + type metric struct { metricType metricType namespace string @@ -160,17 +163,17 @@ type ClientInterface interface { // Gauge measures the value of a metric at a particular time. Gauge(name string, value float64, tags []string, rate float64) error - // Gauge measures the value of a metric at a given time. - // Even with client side aggregation enabled, there is no aggregation done on a metric - // sent using GaugeWithTimestamp: it is written as is in the serialization buffer. + // GaugeWithTimestamp measures the value of a metric at a given time. + // The value will bypass any aggregation on the client side and agent side. + // This is useful when sending points in the past. GaugeWithTimestamp(name string, value float64, tags []string, rate float64, timestamp time.Time) error // Count tracks how many times something happened per second. Count(name string, value int64, tags []string, rate float64) error // CountWithTimestamp tracks how many times something happened at the given second. - // Even with client side aggregation enabled, there is no aggregation done on a metric - // sent using CountWithTimestamp: it is written as is in the serialization buffer. + // The value will bypass any aggregation on the client side and agent side. + // This is useful when sending points in the past. CountWithTimestamp(name string, value int64, tags []string, rate float64, timestamp time.Time) error // Histogram tracks the statistical distribution of a set of values on each host. @@ -563,9 +566,9 @@ func (c *Client) Gauge(name string, value float64, tags []string, rate float64) return c.send(metric{metricType: gauge, name: name, fvalue: value, tags: tags, rate: rate, globalTags: c.tags, namespace: c.namespace}) } -// Gauge measures the value of a metric at a given time. -// Even with client side aggregation enabled, there is no aggregation done on a metric -// sent using GaugeWithTimestamp: it is written as is in the serialization buffer. +// GaugeWithTimestamp measures the value of a metric at a given time. +// The value will bypass any aggregation on the client side and agent side. +// This is useful when sending points in the past. func (c *Client) GaugeWithTimestamp(name string, value float64, tags []string, rate float64, timestamp time.Time) error { if c == nil { return ErrNoClient @@ -586,9 +589,9 @@ func (c *Client) Count(name string, value int64, tags []string, rate float64) er return c.send(metric{metricType: count, name: name, ivalue: value, tags: tags, rate: rate, globalTags: c.tags, namespace: c.namespace}) } -// Count tracks how many times something happened at the given second. -// Even with client side aggregation enabled, there is no aggregation done on a metric -// sent using CountWithTimestamp: it is written as is in the serialization buffer. +// CountWithTimestamp tracks how many times something happened at the given second. +// The value will bypass any aggregation on the client side and agent side. +// This is useful when sending points in the past. func (c *Client) CountWithTimestamp(name string, value int64, tags []string, rate float64, timestamp time.Time) error { if c == nil { return ErrNoClient