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 ...@@ -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