diff --git a/CHANGELOG.md b/CHANGELOG.md index 44c9e45..294fd89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v3.4.4 + +* add: setting submission timestamp +* add: support timestamps on histograms with SerializeB64 + # v3.4.3 * add: submit duration to results diff --git a/circonus-gometrics.go b/circonus-gometrics.go index 11dca4f..a8c518d 100644 --- a/circonus-gometrics.go +++ b/circonus-gometrics.go @@ -140,6 +140,7 @@ type CirconusMetrics struct { counterFuncs map[string]func() uint64 gaugeFuncs map[string]func() int64 counters map[string]uint64 + submitTimestamp *time.Time flushInterval time.Duration flushmu sync.Mutex packagingmu sync.Mutex @@ -311,3 +312,9 @@ func (m *CirconusMetrics) GetBrokerTLSConfig() *tls.Config { func (m *CirconusMetrics) GetCheckBundle() *apiclient.CheckBundle { return m.check.GetCheckBundle() } + +func (m *CirconusMetrics) SetSubmitTimestamp(ts time.Time) { + m.packagingmu.Lock() + defer m.packagingmu.Unlock() + m.submitTimestamp = &ts +} diff --git a/metric_output.go b/metric_output.go index 32e4abe..6764184 100644 --- a/metric_output.go +++ b/metric_output.go @@ -26,7 +26,13 @@ func (m *CirconusMetrics) packageMetrics() (map[string]*apiclient.CheckBundleMet // m.Log.Printf("packaging metrics\n") // } - ts := makeTimestamp(time.Now()) + var ts uint64 + if m.submitTimestamp == nil { + ts = makeTimestamp(time.Now()) + } else { + ts = makeTimestamp(*m.submitTimestamp) + m.Log.Printf("setting custom timestamp %v -> %v (UTC ms)", *m.submitTimestamp, ts) + } newMetrics := make(map[string]*apiclient.CheckBundleMetric) counters, gauges, histograms, text := m.snapshot() @@ -81,7 +87,13 @@ func (m *CirconusMetrics) packageMetrics() (map[string]*apiclient.CheckBundleMet } } if send { - output[name] = Metric{Type: "h", Value: value.DecStrings()} // histograms do NOT get timestamps + buf := bytes.NewBuffer([]byte{}) + if err := value.SerializeB64(buf); err != nil { + m.Log.Printf("[ERR] serializing histogram %s: %s", name, err) + } else { + output[name] = Metric{Type: "h", Value: buf.String(), Timestamp: ts} // histograms b64 serialized support timestamps + } + // output[name] = Metric{Type: "h", Value: value.DecStrings()} // histograms do NOT get timestamps } } @@ -104,6 +116,8 @@ func (m *CirconusMetrics) packageMetrics() (map[string]*apiclient.CheckBundleMet defer m.lastMetrics.metricsmu.Unlock() m.lastMetrics.metrics = &output m.lastMetrics.ts = time.Now() + // reset the submission timestamp + m.submitTimestamp = nil return newMetrics, output }