From bb65cb1fd5698a12976c670f63e3db4acec3e55d Mon Sep 17 00:00:00 2001 From: Andrew Newdigate Date: Thu, 12 Jul 2018 17:37:51 +0000 Subject: [PATCH] Remove healthchecks from prometheus endpoint --- app/services/metrics_service.rb | 21 +------- .../an-no-healthcheck-until-brooklyn.yml | 5 ++ spec/controllers/metrics_controller_spec.rb | 49 ++----------------- 3 files changed, 11 insertions(+), 64 deletions(-) create mode 100644 changelogs/unreleased/an-no-healthcheck-until-brooklyn.yml diff --git a/app/services/metrics_service.rb b/app/services/metrics_service.rb index 51ff9eff5e4..c237d2ae8c9 100644 --- a/app/services/metrics_service.rb +++ b/app/services/metrics_service.rb @@ -1,35 +1,16 @@ require 'prometheus/client/formats/text' class MetricsService - CHECKS = [ - Gitlab::HealthChecks::DbCheck, - Gitlab::HealthChecks::Redis::RedisCheck, - Gitlab::HealthChecks::Redis::CacheCheck, - Gitlab::HealthChecks::Redis::QueuesCheck, - Gitlab::HealthChecks::Redis::SharedStateCheck, - Gitlab::HealthChecks::GitalyCheck - ].freeze - def prometheus_metrics_text Prometheus::Client::Formats::Text.marshal_multiprocess(multiprocess_metrics_path) end - def health_metrics_text - metrics = CHECKS.flat_map(&:metrics) - - formatter.marshal(metrics) - end - def metrics_text - prometheus_metrics_text.concat(health_metrics_text) + prometheus_metrics_text end private - def formatter - @formatter ||= Gitlab::HealthChecks::PrometheusTextFormat.new - end - def multiprocess_metrics_path ::Prometheus::Client.configuration.multiprocess_files_dir end diff --git a/changelogs/unreleased/an-no-healthcheck-until-brooklyn.yml b/changelogs/unreleased/an-no-healthcheck-until-brooklyn.yml new file mode 100644 index 00000000000..4942688d00f --- /dev/null +++ b/changelogs/unreleased/an-no-healthcheck-until-brooklyn.yml @@ -0,0 +1,5 @@ +--- +title: Remove healthchecks from prometheus endpoint +merge_request: 20565 +author: +type: fixed diff --git a/spec/controllers/metrics_controller_spec.rb b/spec/controllers/metrics_controller_spec.rb index 7376841fac8..c7c83369d7c 100644 --- a/spec/controllers/metrics_controller_spec.rb +++ b/spec/controllers/metrics_controller_spec.rb @@ -15,55 +15,16 @@ describe MetricsController do allow(Prometheus::Client.configuration).to receive(:multiprocess_files_dir).and_return(metrics_multiproc_dir) allow(Gitlab::Metrics).to receive(:prometheus_metrics_enabled?).and_return(true) allow(Settings.monitoring).to receive(:ip_whitelist).and_return([whitelisted_ip, whitelisted_ip_range]) + allow_any_instance_of(MetricsService).to receive(:metrics_text).and_return("prometheus_counter 1") end describe '#index' do shared_examples_for 'endpoint providing metrics' do - it 'returns DB ping metrics' do + it 'returns prometheus metrics' do get :index - expect(response.body).to match(/^db_ping_timeout 0$/) - expect(response.body).to match(/^db_ping_success 1$/) - expect(response.body).to match(/^db_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns Redis ping metrics' do - get :index - - expect(response.body).to match(/^redis_ping_timeout 0$/) - expect(response.body).to match(/^redis_ping_success 1$/) - expect(response.body).to match(/^redis_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns Caching ping metrics' do - get :index - - expect(response.body).to match(/^redis_cache_ping_timeout 0$/) - expect(response.body).to match(/^redis_cache_ping_success 1$/) - expect(response.body).to match(/^redis_cache_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns Queues ping metrics' do - get :index - - expect(response.body).to match(/^redis_queues_ping_timeout 0$/) - expect(response.body).to match(/^redis_queues_ping_success 1$/) - expect(response.body).to match(/^redis_queues_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns SharedState ping metrics' do - get :index - - expect(response.body).to match(/^redis_shared_state_ping_timeout 0$/) - expect(response.body).to match(/^redis_shared_state_ping_success 1$/) - expect(response.body).to match(/^redis_shared_state_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns Gitaly metrics' do - get :index - - expect(response.body).to match(/^gitaly_health_check_success{shard="default"} 1$/) - expect(response.body).to match(/^gitaly_health_check_latency_seconds{shard="default"} [0-9\.]+$/) + expect(response.status).to eq(200) + expect(response.body).to match(/^prometheus_counter 1$/) end context 'prometheus metrics are disabled' do @@ -101,7 +62,7 @@ describe MetricsController do allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip) end - it 'returns proper response' do + it 'returns the expected error response' do get :index expect(response.status).to eq(404)