Skip to content

Commit

Permalink
fix on worker metrics report
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed May 14, 2019
1 parent 710dc12 commit 18da58b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions metrics/prometheus_reporter.go
Expand Up @@ -234,8 +234,8 @@ func (p *PrometheusReporter) registerMetrics(
append([]string{"queue"}, additionalLabelsKeys...),
)

p.countReportersMap[WorkerJobsTotal] = prometheus.NewCounterVec(
prometheus.CounterOpts{
p.gaugeReportersMap[WorkerJobsTotal] = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "pitaya",
Subsystem: "worker",
Name: WorkerJobsTotal,
Expand Down
6 changes: 4 additions & 2 deletions worker/report.go
Expand Up @@ -44,12 +44,14 @@ func reportQueueSizes(r metrics.Reporter, queues map[string]string) {
}

func reportJobsTotal(r metrics.Reporter, failed, processed int) {
err := r.ReportCount(metrics.WorkerJobsTotal, map[string]string{
// "failed" and "processed" always grow up,
// so they work as count but must be reported as gauge
err := r.ReportGauge(metrics.WorkerJobsTotal, map[string]string{
"status": "failed",
}, float64(failed))
checkReportErr(metrics.WorkerJobsTotal, err)

err = r.ReportCount(metrics.WorkerJobsTotal, map[string]string{
err = r.ReportGauge(metrics.WorkerJobsTotal, map[string]string{
"status": "ok",
}, float64(processed))
checkReportErr(metrics.WorkerJobsTotal, err)
Expand Down
4 changes: 2 additions & 2 deletions worker/report_test.go
Expand Up @@ -73,12 +73,12 @@ func TestReportJobsTotal(t *testing.T) {
defer ctrl.Finish()

mockReporter := mocks.NewMockReporter(ctrl)
mockReporter.EXPECT().ReportCount(
mockReporter.EXPECT().ReportGauge(
metrics.WorkerJobsTotal,
map[string]string{"status": "failed"},
float64(10))

mockReporter.EXPECT().ReportCount(
mockReporter.EXPECT().ReportGauge(
metrics.WorkerJobsTotal,
map[string]string{"status": "ok"},
float64(20))
Expand Down

0 comments on commit 18da58b

Please sign in to comment.