Skip to content

Commit

Permalink
Rename some prometheus metrics and add/adjust unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svkrieger committed Oct 13, 2023
1 parent ffac886 commit b6ed2b7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 17 deletions.
10 changes: 5 additions & 5 deletions lib/cloud_controller/metrics/prometheus_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def update_summary_metric(metric, value, message)
end

def update_deploying_count(deploying_count)
update_gauge_metric(:cc_deployments_deploying, deploying_count, 'Number of in progress deployments')
update_gauge_metric(:cc_deployments_in_progress_total, deploying_count, 'Number of in progress deployments')
end

def update_user_count(user_count)
update_gauge_metric(:cc_total_users, user_count, 'Number of users')
update_gauge_metric(:cc_users_total, user_count, 'Number of users')
end

def update_job_queue_length(pending_job_count_by_queue)
Expand Down Expand Up @@ -94,12 +94,12 @@ def update_vitals(vitals)
end

def update_task_stats(total_running_tasks, total_memory_in_bytes)
update_gauge_metric(:cc_tasks_running_count, total_running_tasks, 'Total running tasks')
update_gauge_metric(:cc_tasks_running_memory_in_mb, total_memory_in_bytes, 'Total memory consumed by running tasks')
update_gauge_metric(:cc_running_tasks_total, total_running_tasks, 'Total running tasks')
update_gauge_metric(:cc_running_tasks_memory_bytes, total_memory_in_bytes, 'Total memory consumed by running tasks')
end

def start_staging_request_received
increment_counter_metric(:cc_staging_requested, 'Number of staging requests')
increment_counter_metric(:cc_staging_requested_total, 'Number of staging requests')
end

def report_staging_success_metrics(duration_ns)
Expand Down
70 changes: 66 additions & 4 deletions spec/request/internal/metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

expect(last_response.status).to eq 200

expect(last_response.body).to include('cc_total_users 10.0')
expect(last_response.body).to include('cc_users_total 10.0')
end
end

Expand Down Expand Up @@ -120,16 +120,78 @@
it 'reports task stats' do
get '/internal/v4/metrics', nil

expect(last_response.body).to match(/cc_tasks_running_count [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_tasks_running_memory_in_mb [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_running_tasks_total [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_running_tasks_memory_bytes [0-9][0-9]*\.\d+/)
end
end

context 'cc_deploying_count' do
it 'reports deploying_count' do
get '/internal/v4/metrics', nil

expect(last_response.body).to match(/cc_deployments_deploying [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_deployments_in_progress_total [0-9][0-9]*\.\d+/)
end
end

context 'cc_staging_requested' do
it 'reports cc_staging_requested' do
get '/internal/v4/metrics', nil

expect(last_response.body).to match(/cc_staging_requested [0-9][0-9]*\.\d+/)
end
end

context 'cc_staging_succeeded_duration_seconds' do
it 'reports cc_staging_succeeded_duration_seconds' do
get '/internal/v4/metrics', nil

expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="5"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="5"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="10"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="30"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="60"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="300"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="600"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="890"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_bucket{le="\+Inf"} [0-9][0-9]*\.\d+/)

expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_sum [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_succeeded_duration_seconds_count [0-9][0-9]*\.\d+/)
end
end

context 'cc_staging_failed_duration_seconds' do
it 'reports cc_staging_failed_duration_seconds' do
get '/internal/v4/metrics', nil

expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="5"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="5"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="10"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="30"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="60"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="300"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="600"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="890"} [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_bucket{le="\+Inf"} [0-9][0-9]*\.\d+/)

expect(last_response.body).to match(/cc_staging_failed_duration_seconds_sum [0-9][0-9]*\.\d+/)
expect(last_response.body).to match(/cc_staging_failed_duration_seconds_count [0-9][0-9]*\.\d+/)
end
end

context 'cc_requests_completed' do
it 'reports cc_requests_completed' do
get '/internal/v4/metrics', nil

expect(last_response.body).to match(/cc_requests_completed [0-9][0-9]*\.\d+/)
end
end

context 'cc_requests_outstanding_gauge' do
it 'reports cc_requests_outstanding_gauge' do
get '/internal/v4/metrics', nil

expect(last_response.body).to match(/cc_requests_outstanding_gauge [0-9][0-9]*\.\d+/)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ module VCAP::CloudController::Metrics
expected_deploying_count = 7

updater.update_deploying_count(expected_deploying_count)
metric = prom_client.metrics.find { |m| m.name == :cc_deployments_deploying }
metric = prom_client.metrics.find { |m| m.name == :cc_deployments_in_progress_total }
expect(metric).to be_present
expect(metric.get).to eq 7

updater.update_deploying_count(expected_deploying_count)
metric = prom_client.metrics.find { |m| m.name == :cc_deployments_deploying }
metric = prom_client.metrics.find { |m| m.name == :cc_deployments_in_progress_total }
expect(metric).to be_present
expect(metric.get).to eq 7
end
Expand All @@ -38,7 +38,7 @@ module VCAP::CloudController::Metrics
expected_deploying_count = 7

updater.update_deploying_count(expected_deploying_count)
metric = prom_client.metrics.find { |m| m.name == :cc_deployments_deploying }
metric = prom_client.metrics.find { |m| m.name == :cc_deployments_in_progress_total }
expect(metric).to be_present
expect(metric.get).to eq 7
end
Expand All @@ -50,7 +50,7 @@ module VCAP::CloudController::Metrics

updater.update_user_count(expected_user_count)

metric = prom_client.metrics.find { |m| m.name == :cc_total_users }
metric = prom_client.metrics.find { |m| m.name == :cc_users_total }
expect(metric).to be_present
expect(metric.get).to eq 5
end
Expand Down Expand Up @@ -173,10 +173,10 @@ module VCAP::CloudController::Metrics
it 'records the number of running tasks and task memory' do
updater.update_task_stats(5, 512)

metric = prom_client.metrics.find { |m| m.name == :cc_tasks_running_count }
metric = prom_client.metrics.find { |m| m.name == :cc_running_tasks_total }
expect(metric.get).to eq 5

metric = prom_client.metrics.find { |m| m.name == :cc_tasks_running_memory_in_mb }
metric = prom_client.metrics.find { |m| m.name == :cc_running_tasks_memory_bytes }
expect(metric.get).to eq 512
end
end
Expand All @@ -185,12 +185,12 @@ module VCAP::CloudController::Metrics
it 'increments "cc_staging_requested"' do
updater.start_staging_request_received

metric = prom_client.metrics.find { |m| m.name == :cc_staging_requested }
metric = prom_client.metrics.find { |m| m.name == :cc_staging_requested_total }
expect(metric.get).to eq 1

updater.start_staging_request_received

metric = prom_client.metrics.find { |m| m.name == :cc_staging_requested }
metric = prom_client.metrics.find { |m| m.name == :cc_staging_requested_total }
expect(metric.get).to eq 2
end
end
Expand Down

0 comments on commit b6ed2b7

Please sign in to comment.