Commit 84f57b1e authored by Alper Akgun's avatar Alper Akgun

Harden jira_usage counters

Return -1 for fallback, and 0 when no data exists
parent 9a9ef1cd
---
title: Harden jira usage data
merge_request: 27973
author:
type: performance
...@@ -202,7 +202,7 @@ module Gitlab ...@@ -202,7 +202,7 @@ module Gitlab
results = { results = {
projects_jira_server_active: 0, projects_jira_server_active: 0,
projects_jira_cloud_active: 0, projects_jira_cloud_active: 0,
projects_jira_active: -1 projects_jira_active: 0
} }
Service.active Service.active
...@@ -217,14 +217,12 @@ module Gitlab ...@@ -217,14 +217,12 @@ module Gitlab
results[:projects_jira_server_active] += counts[:server].count if counts[:server] results[:projects_jira_server_active] += counts[:server].count if counts[:server]
results[:projects_jira_cloud_active] += counts[:cloud].count if counts[:cloud] results[:projects_jira_cloud_active] += counts[:cloud].count if counts[:cloud]
if results[:projects_jira_active] == -1
results[:projects_jira_active] = services.size
else
results[:projects_jira_active] += services.size results[:projects_jira_active] += services.size
end end
end
results results
rescue ActiveRecord::StatementInvalid
{ projects_jira_server_active: -1, projects_jira_cloud_active: -1, projects_jira_active: -1 }
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -85,6 +85,13 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -85,6 +85,13 @@ describe Gitlab::UsageData, :aggregate_failures do
expect { subject }.not_to raise_error expect { subject }.not_to raise_error
end end
it 'jira usage works when queries time out' do
allow_any_instance_of(ActiveRecord::Relation)
.to receive(:find_in_batches).and_raise(ActiveRecord::StatementInvalid.new(''))
expect { described_class.jira_usage }.not_to raise_error
end
end end
describe '#usage_data_counters' do describe '#usage_data_counters' do
......
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