Skip to content

Commit

Permalink
Revert "Creates metrics endpoint for use by prom-scraper"
Browse files Browse the repository at this point in the history
This change is dependent on cloudfoundry/cf-deployment#970

This reverts commit b278a04.
  • Loading branch information
MerricdeLauney committed May 31, 2022
1 parent b278a04 commit 8415699
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 820 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ gem 'sequel_pg', require: 'sequel'
gem 'sinatra', '~> 2.2'
gem 'sinatra-contrib'
gem 'statsd-ruby', '~> 1.4.0'
gem 'prometheus-client'
gem 'steno'
gem 'talentbox-delayed_job_sequel', '~> 4.3.0'
gem 'thin'
Expand Down
4 changes: 1 addition & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ GEM
ast (~> 2.4.1)
pg (1.3.5)
posix-spawn (0.3.15)
prometheus-client (3.0.0)
protobuf (3.6.12)
activesupport (>= 3.2)
middleware
Expand Down Expand Up @@ -601,7 +600,6 @@ DEPENDENCIES
parallel_tests
pg
posix-spawn (~> 0.3.15)
prometheus-client
protobuf (= 3.6.12)
pry-byebug
psych (>= 4.0.4)
Expand Down Expand Up @@ -642,4 +640,4 @@ DEPENDENCIES
yajl-ruby

BUNDLED WITH
2.2.26
2.1.4
25 changes: 0 additions & 25 deletions app/controllers/internal/metrics_controller.rb

This file was deleted.

6 changes: 0 additions & 6 deletions app/controllers/internal/staging_completion_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,15 @@ def report_metrics(bbs_staging_response)
duration = Time.now.utc.to_i * 1e9 - bbs_staging_response[:created_at]
if bbs_staging_response[:failed]
statsd_updater.report_staging_failure_metrics(duration)
prometheus_updater.report_staging_failure_metrics(duration)
else
statsd_updater.report_staging_success_metrics(duration)
prometheus_updater.report_staging_success_metrics(duration)
end
end

def statsd_updater
@statsd_updater ||= VCAP::CloudController::Metrics::StatsdUpdater.new
end

def prometheus_updater
@prometheus_updater ||= VCAP::CloudController::Metrics::PrometheusUpdater.new # this should be using singleton
end

attr_reader :stagers

def read_body
Expand Down
17 changes: 2 additions & 15 deletions app/jobs/diego/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,15 @@ module VCAP::CloudController
module Jobs
module Diego
class Sync < VCAP::CloudController::Jobs::CCJob
def initialize(statsd=Statsd.new, prometheus_updater=VCAP::CloudController::Metrics::PrometheusUpdater.new)
def initialize(statsd=Statsd.new)
@statsd = statsd
@prometheus_updater = prometheus_updater
end

def perform
config = CloudController::DependencyLocator.instance.config
begin
## TODO: At some point in the future, start using a monotonic time source, rather than wall-clock time!
start = Time.now
@statsd.time('cc.diego_sync.duration') do
VCAP::CloudController::Diego::ProcessesSync.new(config: config).sync
VCAP::CloudController::Diego::TasksSync.new(config: config).sync
ensure
finish = Time.now
## NOTE: We're taking time in seconds and multiplying by 1000 because we don't have
## access to time in milliseconds. If you ever get access to reliable time in
## milliseconds, then do know that the lack of precision here is not desired
## so feed in the entire value!
elapsed_ms = ((finish - start) * 1000).round

@statsd.timing('cc.diego_sync.duration', elapsed_ms)
@prometheus_updater.report_diego_cell_sync_duration(elapsed_ms)
end
end

Expand Down
8 changes: 0 additions & 8 deletions lib/cloud_controller/dependency_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
require 'cloud_controller/opi/instances_client'
require 'cloud_controller/opi/stager_client'
require 'cloud_controller/opi/task_client'
require 'cloud_controller/metrics/prometheus_updater'

require 'bits_service_client'

Expand Down Expand Up @@ -71,13 +70,6 @@ def runners
@dependencies[:runners] || register(:runners, VCAP::CloudController::Runners.new(config))
end

def prometheus_updater
unless @dependencies[:prometheus_updater]
register(:prometheus_updater, VCAP::CloudController::Metrics::PrometheusUpdater.new)
end
@dependencies[:prometheus_updater]
end

def stagers
@dependencies[:stagers] || register(:stagers, VCAP::CloudController::Stagers.new(config))
end
Expand Down
18 changes: 5 additions & 13 deletions lib/cloud_controller/deployment_updater/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ def start
with_error_logging('cc.deployment_updater') do
config = CloudController::DependencyLocator.instance.config
statsd_client = CloudController::DependencyLocator.instance.statsd_client
prometheus_updater = CloudController::DependencyLocator.instance.prometheus_updater

update_step = proc { update(
update_frequency: config.get(:deployment_updater, :update_frequency_in_seconds),
statsd_client: statsd_client,
prometheus_updater: prometheus_updater
statsd_client: statsd_client
)
}

Expand All @@ -41,20 +39,14 @@ def start

private

def update(update_frequency:, statsd_client:, prometheus_updater:)
def update(update_frequency:, statsd_client:)
logger = Steno.logger('cc.deployment_updater.scheduler')

update_start_time = Time.now
Dispatcher.dispatch
statsd_client.time('cc.deployments.update.duration') do
Dispatcher.dispatch
end
update_duration = Time.now - update_start_time
## NOTE: We're taking time in seconds and multiplying by 1000 because we don't have
## access to time in milliseconds. If you ever get access to reliable time in
## milliseconds, then do know that the lack of precision here is not desired
## so feed in the entire value!
update_duration_ms = update_duration * 1000
statsd_client.timing('cc.deployments.update.duration', update_duration_ms)
prometheus_updater.report_deployment_duration(update_duration_ms)

logger.info("Update loop took #{update_duration}s")

sleep_duration = update_frequency - update_duration
Expand Down
10 changes: 5 additions & 5 deletions lib/cloud_controller/metrics/periodic_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module VCAP::CloudController::Metrics
class PeriodicUpdater
def initialize(start_time, log_counter, logger=Steno.logger, updaters=[StatsdUpdater.new, PrometheusUpdater.new])
def initialize(start_time, log_counter, logger=Steno.logger, updaters=[StatsdUpdater.new])
@start_time = start_time
@updaters = updaters
@log_counter = log_counter
Expand All @@ -15,7 +15,7 @@ def initialize(start_time, log_counter, logger=Steno.logger, updaters=[StatsdUpd

def setup_updates
update!
EM.add_periodic_timer(600) { catch_error { update_user_count } }
EM.add_periodic_timer(600) { catch_error { record_user_count } }
EM.add_periodic_timer(30) { catch_error { update_job_queue_length } }
EM.add_periodic_timer(30) { catch_error { update_thread_info } }
EM.add_periodic_timer(30) { catch_error { update_failed_job_count } }
Expand All @@ -26,7 +26,7 @@ def setup_updates
end

def update!
update_user_count
record_user_count
update_job_queue_length
update_thread_info
update_failed_job_count
Expand Down Expand Up @@ -67,10 +67,10 @@ def update_deploying_count
@updaters.each { |u| u.update_deploying_count(deploying_count) }
end

def update_user_count
def record_user_count
user_count = VCAP::CloudController::User.count

@updaters.each { |u| u.update_user_count(user_count) }
@updaters.each { |u| u.record_user_count(user_count) }
end

def update_job_queue_length
Expand Down
143 changes: 0 additions & 143 deletions lib/cloud_controller/metrics/prometheus_updater.rb

This file was deleted.

15 changes: 2 additions & 13 deletions lib/cloud_controller/metrics/request_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,25 @@
module VCAP::CloudController
module Metrics
class RequestMetrics
def initialize(statsd=Statsd.new, prometheus_updater=PrometheusUpdater.new)
def initialize(statsd=Statsd.new)
@counter = 0
@statsd = statsd
@prometheus_updater = prometheus_updater
end

def start_request
@counter += 1
@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, 'Requests Outstanding')
end

def complete_request(status)
http_status_code = "#{status.to_s[0]}XX"
http_status_metric = "cc.http_status.#{http_status_code}"
@counter -= 1
@statsd.gauge('cc.requests.outstanding.gauge', @counter)
@statsd.batch do |batch|
batch.decrement 'cc.requests.outstanding'
batch.increment 'cc.requests.completed'
batch.increment http_status_metric
batch.increment "cc.http_status.#{status.to_s[0]}XX"
end

@prometheus_updater.update_gauge_metric(:cc_requests_outstanding_gauge, @counter, 'Requests Outstanding Gauge')
@prometheus_updater.decrement_gauge_metric(:cc_requests_outstanding, 'Requests Outstanding')
@prometheus_updater.increment_gauge_metric(:cc_requests_completed, 'Requests Completed')
@prometheus_updater.increment_gauge_metric(http_status_metric.gsub('.', '_').to_sym, "Times HTTP status #{http_status_code} have been received")
end
end
end
Expand Down
Loading

0 comments on commit 8415699

Please sign in to comment.