Commit 2562dcab authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'bvl-skip-metrics-es-rack' into 'master'

Skip recording ES-metrics when there are none

Closes #233858

See merge request gitlab-org/gitlab!38831
parents e6ab5eff 35694e4c
...@@ -24,12 +24,12 @@ module Gitlab ...@@ -24,12 +24,12 @@ module Gitlab
query_time = ::Gitlab::Instrumentation::ElasticsearchTransport.query_time query_time = ::Gitlab::Instrumentation::ElasticsearchTransport.query_time
request_count = ::Gitlab::Instrumentation::ElasticsearchTransport.get_request_count request_count = ::Gitlab::Instrumentation::ElasticsearchTransport.get_request_count
return unless request_count > 0
transaction.increment(:http_elasticsearch_requests_total, request_count) do transaction.increment(:http_elasticsearch_requests_total, request_count) do
docstring 'Amount of calls to Elasticsearch servers during web requests' docstring 'Amount of calls to Elasticsearch servers during web requests'
end end
return unless request_count > 0
transaction.observe(:http_elasticsearch_requests_duration_seconds, query_time) do transaction.observe(:http_elasticsearch_requests_duration_seconds, query_time) do
docstring 'Query time for Elasticsearch servers during web requests' docstring 'Query time for Elasticsearch servers during web requests'
buckets HISTOGRAM_BUCKETS buckets HISTOGRAM_BUCKETS
......
...@@ -42,8 +42,9 @@ RSpec.describe Gitlab::Metrics::ElasticsearchRackMiddleware do ...@@ -42,8 +42,9 @@ RSpec.describe Gitlab::Metrics::ElasticsearchRackMiddleware do
context 'when there are no elasticsearch requests' do context 'when there are no elasticsearch requests' do
let(:elasticsearch_requests_count) { 0 } let(:elasticsearch_requests_count) { 0 }
it 'does not record duration if there were no ES calls' do it 'does not record any metrics' do
expect(transaction).not_to receive(:observe).with(:http_elasticsearch_requests_duration_seconds) expect(transaction).not_to receive(:observe).with(:http_elasticsearch_requests_duration_seconds)
expect(transaction).not_to receive(:increment).with(:http_elasticsearch_requests_total, 0)
middleware.call(env) middleware.call(env)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment