Skip to content

Commit

Permalink
Add Gauge metric back in for queue latency (#23)
Browse files Browse the repository at this point in the history
* add Gauge

* update tests

* include other gauge call

* change name in case of collision

* update tests
  • Loading branch information
jagonalez authored Aug 16, 2022
1 parent d32c5e2 commit d0d87c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ func TestMetrics(t *testing.T) {
mockDoer.EXPECT().Gauge("jobs.dead.count", float64(0), gomock.Any(), gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Gauge("jobs.enqueued.count", float64(8), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Gauge("jobs.enqueued.default.count", float64(1), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Timing("jobs.enqueued.default.time", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Gauge("jobs.enqueued.default.time", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Timing("jobs.enqueued.default.time_hist", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Gauge("jobs.enqueued.builds.count", float64(6), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Timing("jobs.enqueued.builds.time", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Gauge("jobs.enqueued.builds.time", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Timing("jobs.enqueued.builds.time_hist", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Gauge("jobs.enqueued.tests.count", float64(1), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Timing("jobs.enqueued.tests.time", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Gauge("jobs.enqueued.tests.time", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)
mockDoer.EXPECT().Timing("jobs.enqueued.tests.time_hist", gomock.Any(), tags, gomock.Any()).Return(nil).Times(1)

// create 15 jobs
// default queue
Expand Down
6 changes: 5 additions & 1 deletion metrics/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (m *metricsTask) Execute() error {
}

queueLatencyMetricName := m.Subsystem.PrefixMetricName(fmt.Sprintf("enqueued.%s.time", queue.Name()))
queueLatencyMetricNameHist := m.Subsystem.PrefixMetricName(fmt.Sprintf("enqueued.%s.time_hist", queue.Name()))
var timeElapsed time.Duration = 0
// This does an LRANGE on the queue
// start is the offset from the left of the queue
Expand All @@ -82,7 +83,10 @@ func (m *metricsTask) Execute() error {

return nil
})
if err := m.Subsystem.StatsDClient().Timing(queueLatencyMetricName, timeElapsed, m.Subsystem.Options.Tags, 1); err != nil {
if err := m.Subsystem.StatsDClient().Gauge(queueLatencyMetricName, float64(timeElapsed.Milliseconds()), m.Subsystem.Options.Tags, 1); err != nil {
util.Warnf("unable to submit metric: %v", err)
}
if err := m.Subsystem.StatsDClient().Timing(queueLatencyMetricNameHist, timeElapsed, m.Subsystem.Options.Tags, 1); err != nil {
util.Warnf("unable to submit metric: %v", err)
}

Expand Down

0 comments on commit d0d87c1

Please sign in to comment.