diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2019-07-19 16:31:52 +0200 |
---|---|---|
committer | Francisco Javier López <fjlopez@gitlab.com> | 2019-07-19 17:06:34 +0200 |
commit | 1c60e06bdabed1b37acf5923dba9e77e2e614b89 (patch) | |
tree | 1d24d79d57de184d2e97a8574a8da07e7a3a75e9 | |
parent | 4c30b0a1cf5ead26d20845b82ae528fcbdf98728 (diff) | |
download | gitlab-ce-fj-avoid-incresaing-usage-ping-when-not-enabled.tar.gz |
Avoid increasing redis counters when usage_ping is disabledfj-avoid-incresaing-usage-ping-when-not-enabled
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 |