Commit 753a3da0 authored by Sean McGivern's avatar Sean McGivern Committed by Bob Van Landuyt

Fix feature_category label in http_requests_total metric

When the feature category header from the application was an empty
string, we'd set an empty label in Prometheus, rather than the default
of 'unknown'.
parent 5949f62a
...@@ -63,7 +63,7 @@ module Gitlab ...@@ -63,7 +63,7 @@ module Gitlab
if health_endpoint if health_endpoint
RequestsRackMiddleware.http_health_requests_total.increment(status: status, method: method) RequestsRackMiddleware.http_health_requests_total.increment(status: status, method: method)
else else
RequestsRackMiddleware.http_request_total.increment(status: status, method: method, feature_category: feature_category || FEATURE_CATEGORY_DEFAULT) RequestsRackMiddleware.http_request_total.increment(status: status, method: method, feature_category: feature_category.presence || FEATURE_CATEGORY_DEFAULT)
end end
end end
end end
......
...@@ -113,6 +113,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -113,6 +113,7 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
end end
end end
context 'feature category header' do
context 'when a feature category header is present' do context 'when a feature category header is present' do
before do before do
allow(app).to receive(:call).and_return([200, { described_class::FEATURE_CATEGORY_HEADER => 'issue_tracking' }, nil]) allow(app).to receive(:call).and_return([200, { described_class::FEATURE_CATEGORY_HEADER => 'issue_tracking' }, nil])
...@@ -134,6 +135,19 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do ...@@ -134,6 +135,19 @@ RSpec.describe Gitlab::Metrics::RequestsRackMiddleware do
end end
end end
context 'when the feature category header is an empty string' do
before do
allow(app).to receive(:call).and_return([200, { described_class::FEATURE_CATEGORY_HEADER => '' }, nil])
end
it 'sets the feature category to unknown' do
expect(described_class).to receive_message_chain(:http_request_total, :increment).with(method: 'get', status: 200, feature_category: 'unknown')
subject.call(env)
end
end
end
describe '.initialize_http_request_duration_seconds' do describe '.initialize_http_request_duration_seconds' do
it "sets labels" do it "sets labels" do
expected_labels = [] expected_labels = []
......
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