Skip to content

Commit

Permalink
Use decrement and increment for gauge metric
Browse files Browse the repository at this point in the history
  • Loading branch information
svkrieger committed Oct 5, 2023
1 parent 35d0221 commit 716a3e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/cloud_controller/metrics/request_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def start_request
@statsd.gauge('cc.requests.outstanding.gauge', @counter)
@statsd.increment 'cc.requests.outstanding'

@prometheus_updater.update_gauge_metric(:cc_requests_outstanding_gauge, @counter, 'Requests Outstanding Gauge')
@prometheus_updater.increment_gauge_metric(:cc_requests_outstanding_gauge, 'Requests Outstanding Gauge')
end

def complete_request(status)
Expand All @@ -28,7 +28,7 @@ def complete_request(status)
batch.increment http_status_metric
end

@prometheus_updater.update_gauge_metric(:cc_requests_outstanding_gauge, @counter, 'Requests Outstanding Gauge')
@prometheus_updater.decrement_gauge_metric(:cc_requests_outstanding_gauge, 'Requests Outstanding Gauge')
@prometheus_updater.increment_gauge_metric(:cc_requests_completed, 'Requests Completed')
end
end
Expand Down
13 changes: 11 additions & 2 deletions spec/unit/lib/cloud_controller/metrics/request_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ module VCAP::CloudController::Metrics

expect(statsd_client).to have_received(:gauge).with('cc.requests.outstanding.gauge', 1)
expect(statsd_client).to have_received(:increment).with('cc.requests.outstanding')
expect(prometheus_client).to have_received(:update_gauge_metric).with(:cc_requests_outstanding_gauge, 1, kind_of(String))
end

it 'increments outstanding requests for prometheus' do
request_metrics.start_request

expect(prometheus_client).to have_received(:increment_gauge_metric).with(:cc_requests_outstanding_gauge, kind_of(String))
end
end

Expand All @@ -46,8 +51,12 @@ module VCAP::CloudController::Metrics
expect(batch).to have_received(:decrement).with('cc.requests.outstanding')
expect(batch).to have_received(:increment).with('cc.requests.completed')
expect(batch).to have_received(:increment).with('cc.http_status.2XX')
end

it 'increments completed and decrements outstanding for prometheus' do
request_metrics.complete_request(status)

expect(prometheus_client).to have_received(:update_gauge_metric).with(:cc_requests_outstanding_gauge, -1, kind_of(String))
expect(prometheus_client).to have_received(:decrement_gauge_metric).with(:cc_requests_outstanding_gauge, kind_of(String))
expect(prometheus_client).to have_received(:increment_gauge_metric).with(:cc_requests_completed, kind_of(String))
end

Expand Down

0 comments on commit 716a3e2

Please sign in to comment.