Skip to content

Commit

Permalink
add generic metric increment report method
Browse files Browse the repository at this point in the history
  • Loading branch information
Moises Silva committed Feb 6, 2019
1 parent d7cd32b commit b7af02f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions extensions/datadog_statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ func (s *StatsD) ReportGoStats(
s.Client.Gauge("next_gc_bytes", float64(nextGCBytes), tags, 1)
}

// ReportMetricIncrement reports a custom metric increment in statsd
func (s *StatsD) ReportMetricIncrement(
metric string,
game, platform string,
) {
hostname, _ := os.Hostname()
tags := []string{
fmt.Sprintf("hostname:%s", hostname),
fmt.Sprintf("game:%s", game),
fmt.Sprintf("platform:%s", platform),
}
s.Client.Incr(metric, tags, 1)
}

//Cleanup closes statsd connection
func (s *StatsD) Cleanup() error {
s.Client.Close()
Expand Down
21 changes: 21 additions & 0 deletions extensions/datadog_statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ var _ = Describe("StatsD Extension", func() {
Expect(mockClient.Count["failed"]).To(Equal(2))
})
})

Describe("Reporting metric increment", func() {
It("should report metric increment in statsd", func() {
statsd, err := NewStatsD(config, logger, mockClient)
Expect(err).NotTo(HaveOccurred())
defer statsd.Cleanup()

statsd.ReportMetricIncrement("tokens_to_delete", "game", "apns")
statsd.ReportMetricIncrement("tokens_to_delete", "game", "apns")
statsd.ReportMetricIncrement("tokens_to_delete", "game", "apns")

statsd.ReportMetricIncrement("tokens_deleted", "game", "apns")
statsd.ReportMetricIncrement("tokens_deleted", "game", "apns")

statsd.ReportMetricIncrement("tokens_deletion_failed", "game", "apns")

Expect(mockClient.Count["tokens_to_delete"]).To(Equal(3))
Expect(mockClient.Count["tokens_deleted"]).To(Equal(2))
Expect(mockClient.Count["tokens_deletion_failed"]).To(Equal(1))
})
})
})

Describe("[Integration]", func() {
Expand Down
1 change: 1 addition & 0 deletions interfaces/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ type StatsReporter interface {
HandleNotificationSuccess(game string, platform string)
HandleNotificationFailure(game string, platform string, err *errors.PushError)
ReportGoStats(numGoRoutines int, allocatedAndNotFreed, heapObjects, nextGCBytes, pauseGCNano uint64)
ReportMetricIncrement(metric string, game, platform string)
}

0 comments on commit b7af02f

Please sign in to comment.