Commit 35694e4c authored by Bob Van Landuyt's avatar Bob Van Landuyt

Skip recording ES-metrics when there are none

This skips calling out into the Prometheus Client library entirely for
requests that didn't call out to ElasticSearch.

Incrementing the counter by 0 would be a no-op anyway.
parent a475c31f
......@@ -24,12 +24,12 @@ module Gitlab
query_time = ::Gitlab::Instrumentation::ElasticsearchTransport.query_time
request_count = ::Gitlab::Instrumentation::ElasticsearchTransport.get_request_count
return unless request_count > 0
transaction.increment(:http_elasticsearch_requests_total, request_count) do
docstring 'Amount of calls to Elasticsearch servers during web requests'
end
return unless request_count > 0
transaction.observe(:http_elasticsearch_requests_duration_seconds, query_time) do
docstring 'Query time for Elasticsearch servers during web requests'
buckets HISTOGRAM_BUCKETS
......
......@@ -42,8 +42,9 @@ RSpec.describe Gitlab::Metrics::ElasticsearchRackMiddleware do
context 'when there are no elasticsearch requests' do
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(:increment).with(:http_elasticsearch_requests_total, 0)
middleware.call(env)
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