Commit 603cbbe0 authored by alinamihaila's avatar alinamihaila

Make tests consistent

Update docs
parent 95cf4a76
...@@ -295,7 +295,7 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF ...@@ -295,7 +295,7 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
Arguments: Arguments:
- `event_name`: event name. - `event_name`: event name.
- `values`: values we count unique events - `values`: values counted, one value or array of values.
Example usage: Example usage:
......
...@@ -537,11 +537,14 @@ module API ...@@ -537,11 +537,14 @@ module API
) )
end end
# @param event_name [String] the event name
# @param values [Array|String] the values counted
def increment_unique_values(event_name, values) def increment_unique_values(event_name, values)
raise "values is empty" unless values.present?
feature_name = "usage_data_#{event_name}" feature_name = "usage_data_#{event_name}"
raise "Feature #{feature_name} not enabled" unless Feature.enabled?(feature_name) raise "Feature #{feature_name} not enabled" unless Feature.enabled?(feature_name)
raise "Usage ping not enabled" unless Gitlab::CurrentSettings.usage_ping_enabled? raise "Usage ping not enabled" unless Gitlab::CurrentSettings.usage_ping_enabled?
raise "values is empty" unless values.present?
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(values, event_name) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(values, event_name)
rescue => error rescue => error
......
...@@ -190,7 +190,7 @@ RSpec.describe API::Helpers do ...@@ -190,7 +190,7 @@ RSpec.describe API::Helpers do
end end
describe '#increment_unique_values' do describe '#increment_unique_values' do
let(:value) { "9f302fea-f828-4ca9-aef4-e10bd723c0b3" } let(:value) { '9f302fea-f828-4ca9-aef4-e10bd723c0b3' }
let(:event_name) { 'my_event' } let(:event_name) { 'my_event' }
let(:unknown_event) { 'unknown' } let(:unknown_event) { 'unknown' }
let(:feature) { "usage_data_#{event_name}" } let(:feature) { "usage_data_#{event_name}" }
...@@ -222,6 +222,14 @@ RSpec.describe API::Helpers do ...@@ -222,6 +222,14 @@ RSpec.describe API::Helpers do
subject.increment_unique_values(unknown_event, value) subject.increment_unique_values(unknown_event, value)
end end
it 'log an exception for nil values' do
stub_application_setting(usage_ping_enabled: true)
expect(Rails.logger).to receive(:warn).with("Redis tracking event failed for event: #{unknown_event}, message: values is empty")
subject.increment_unique_values(unknown_event, nil)
end
end end
context 'with feature disabled' do context 'with feature disabled' do
...@@ -229,7 +237,7 @@ RSpec.describe API::Helpers do ...@@ -229,7 +237,7 @@ RSpec.describe API::Helpers do
stub_feature_flags(feature => false) stub_feature_flags(feature => false)
end end
it "logs an exception" do it 'logs an exception' do
expect(Rails.logger).to receive(:warn).with("Redis tracking event failed for event: #{event_name}, message: Feature #{feature} not enabled") expect(Rails.logger).to receive(:warn).with("Redis tracking event failed for event: #{event_name}, message: Feature #{feature} not enabled")
subject.increment_unique_values(event_name, value) subject.increment_unique_values(event_name, value)
......
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