Skip to content

Commit

Permalink
Merge pull request #126 from circonus-labs/v3
Browse files Browse the repository at this point in the history
v3.4.4
  • Loading branch information
maier authored Apr 30, 2021
2 parents 383c40d + a862b73 commit 90603b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions circonus-gometrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
18 changes: 16 additions & 2 deletions metric_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}

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

0 comments on commit 90603b7

Please sign in to comment.