Skip to content
Snippets Groups Projects
Commit 71691d93 authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Count comments on notes and merge requests

This extends our existing `Gitlab::UsageDataCounters::NoteCounter` to
also count notes on commits and merge requests
parent 535c2d3c
No related branches found
No related tags found
No related merge requests found
---
title: Count comments on commits and merge requests
merge_request: 31912
author:
type: other
Loading
Loading
@@ -4,7 +4,7 @@ module Gitlab::UsageDataCounters
class NoteCounter < BaseCounter
KNOWN_EVENTS = %w[create].freeze
PREFIX = 'note'
COUNTABLE_TYPES = %w[Snippet].freeze
COUNTABLE_TYPES = %w[Snippet Commit MergeRequest].freeze
 
class << self
def redis_key(event, noteable_type)
Loading
Loading
@@ -24,9 +24,9 @@ module Gitlab::UsageDataCounters
end
 
def totals
{
snippet_comment: read(:create, 'Snippet')
}
COUNTABLE_TYPES.map do |countable_type|
[:"#{countable_type.underscore}_comment", read(:create, countable_type)]
end.to_h
end
 
private
Loading
Loading
Loading
Loading
@@ -26,16 +26,22 @@ describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_stat
end
 
it_behaves_like 'a note usage counter', :create, 'Snippet'
it_behaves_like 'a note usage counter', :create, 'MergeRequest'
it_behaves_like 'a note usage counter', :create, 'Commit'
 
describe '.totals' do
let(:combinations) do
[
[:create, 'Snippet', 3]
[:create, 'Snippet', 3],
[:create, 'MergeRequest', 4],
[:create, 'Commit', 5]
]
end
 
let(:expected_totals) do
{ snippet_comment: 3 }
{ snippet_comment: 3,
merge_request_comment: 4,
commit_comment: 5 }
end
 
before do
Loading
Loading
@@ -57,14 +63,18 @@ describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_stat
let(:unknown_event_error) { Gitlab::UsageDataCounters::BaseCounter::UnknownEvent }
 
where(:event, :noteable_type, :expected_count, :should_raise) do
:create | 'Snippet' | 1 | false
:wibble | 'Snippet' | 0 | true
:create | 'Issue' | 0 | false
:wibble | 'Issue' | 0 | false
:create | 'Snippet' | 1 | false
:wibble | 'Snippet' | 0 | true
:create | 'MergeRequest' | 1 | false
:wibble | 'MergeRequest' | 0 | true
:create | 'Commit' | 1 | false
:wibble | 'Commit' | 0 | true
:create | 'Issue' | 0 | false
:wibble | 'Issue' | 0 | false
end
 
with_them do
it "handles event" do
it 'handles event' do
if should_raise
expect { described_class.count(event, noteable_type) }.to raise_error(unknown_event_error)
else
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
 
describe Gitlab::UsageData do
Loading
Loading
@@ -34,7 +36,7 @@ describe Gitlab::UsageData do
 
subject { described_class.data }
 
it "gathers usage data" do
it 'gathers usage data' do
expect(subject.keys).to include(*%i(
active_user_count
counts
Loading
Loading
@@ -66,6 +68,8 @@ describe Gitlab::UsageData do
snippet_create: a_kind_of(Integer),
snippet_update: a_kind_of(Integer),
snippet_comment: a_kind_of(Integer),
merge_request_comment: a_kind_of(Integer),
commit_comment: a_kind_of(Integer),
wiki_pages_create: a_kind_of(Integer),
wiki_pages_update: a_kind_of(Integer),
wiki_pages_delete: a_kind_of(Integer),
Loading
Loading
@@ -78,7 +82,7 @@ describe Gitlab::UsageData do
)
end
 
it "gathers usage counts" do
it 'gathers usage counts' do
expected_keys = %i(
assignee_lists
boards
Loading
Loading
@@ -253,7 +257,7 @@ describe Gitlab::UsageData do
describe '#license_usage_data' do
subject { described_class.license_usage_data }
 
it "gathers license data" do
it 'gathers license data' do
expect(subject[:uuid]).to eq(Gitlab::CurrentSettings.uuid)
expect(subject[:version]).to eq(Gitlab::VERSION)
expect(subject[:installation_type]).to eq('gitlab-development-kit')
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment