diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2019-07-19 20:04:33 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-07-19 20:04:33 +0300 |
commit | 351bc078ca079a95445b54f01a72c34cf5a946bb (patch) | |
tree | 76e6d0ad0378553e3309eddbed7c804c0efa7d94 | |
parent | 2db1317b92a62b8f1b4089c44d85442f0d8263f8 (diff) |
Avoid increasing redis counters when usage_ping is disabled
3 files changed, 40 insertions, 0 deletions
diff --git a/changelogs/unreleased/fj-avoid-incresaing-usage-ping-when-not-enabled.yml b/changelogs/unreleased/fj-avoid-incresaing-usage-ping-when-not-enabled.yml new file mode 100644 index 00000000000..f1077f2d56d --- /dev/null +++ b/changelogs/unreleased/fj-avoid-incresaing-usage-ping-when-not-enabled.yml @@ -0,0 +1,5 @@ +--- +title: Avoid increasing redis counters when usage_ping is disabled +merge_request: 30949 +author: +type: changed diff --git a/lib/gitlab/usage_data_counters/redis_counter.rb b/lib/gitlab/usage_data_counters/redis_counter.rb index d10871f704c..75d5a75e3a4 100644 --- a/lib/gitlab/usage_data_counters/redis_counter.rb +++ b/lib/gitlab/usage_data_counters/redis_counter.rb @@ -4,6 +4,8 @@ module Gitlab module UsageDataCounters module RedisCounter def increment(redis_counter_key) + return unless Gitlab::CurrentSettings.usage_ping_enabled + Gitlab::Redis::SharedState.with { |redis| redis.incr(redis_counter_key) } end diff --git a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb new file mode 100644 index 00000000000..c34ac7867ab --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shared_state do + let(:redis_key) { 'foobar' } + + subject { Class.new.extend(described_class) } + + before do + stub_application_setting(usage_ping_enabled: setting_value) + end + + context 'when usage_ping is disabled' do + let(:setting_value) { false } + + it 'counter is not increased' do + expect do + subject.increment(redis_key) + end.not_to change { subject.total_count(redis_key) } + end + end + + context 'when usage_ping is enabled' do + let(:setting_value) { true } + + it 'counter is increased' do + expect do + subject.increment(redis_key) + end.to change { subject.total_count(redis_key) }.by(1) + end + end +end |