summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage_data_counters/issue_activity_unique_counter.rb
blob: a59ea36961d100fad7d0048fffb5b4057721a9e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# frozen_string_literal: true

module Gitlab
  module UsageDataCounters
    module IssueActivityUniqueCounter
      ISSUE_CATEGORY = 'issues_edit'
      ISSUE_ACTION = 'perform_issue_action'
      ISSUE_LABEL = 'redis_hll_counters.issues_edit.issues_edit_total_unique_counts_monthly'

      ISSUE_ASSIGNEE_CHANGED = 'g_project_management_issue_assignee_changed'
      ISSUE_CREATED = 'g_project_management_issue_created'
      ISSUE_CLOSED = 'g_project_management_issue_closed'
      ISSUE_DESCRIPTION_CHANGED = 'g_project_management_issue_description_changed'
      ISSUE_LABEL_CHANGED = 'g_project_management_issue_label_changed'
      ISSUE_MADE_CONFIDENTIAL = 'g_project_management_issue_made_confidential'
      ISSUE_MADE_VISIBLE = 'g_project_management_issue_made_visible'
      ISSUE_MILESTONE_CHANGED = 'g_project_management_issue_milestone_changed'
      ISSUE_REOPENED = 'g_project_management_issue_reopened'
      ISSUE_TITLE_CHANGED = 'g_project_management_issue_title_changed'
      ISSUE_CROSS_REFERENCED = 'g_project_management_issue_cross_referenced'
      ISSUE_MOVED = 'g_project_management_issue_moved'
      ISSUE_RELATED = 'g_project_management_issue_related'
      ISSUE_CLONED = 'g_project_management_issue_cloned'
      ISSUE_UNRELATED = 'g_project_management_issue_unrelated'
      ISSUE_MARKED_AS_DUPLICATE = 'g_project_management_issue_marked_as_duplicate'
      ISSUE_LOCKED = 'g_project_management_issue_locked'
      ISSUE_UNLOCKED = 'g_project_management_issue_unlocked'
      ISSUE_DESIGNS_ADDED = 'g_project_management_issue_designs_added'
      ISSUE_DESIGNS_MODIFIED = 'g_project_management_issue_designs_modified'
      ISSUE_DESIGNS_REMOVED = 'g_project_management_issue_designs_removed'
      ISSUE_DUE_DATE_CHANGED = 'g_project_management_issue_due_date_changed'
      ISSUE_TIME_ESTIMATE_CHANGED = 'g_project_management_issue_time_estimate_changed'
      ISSUE_TIME_SPENT_CHANGED = 'g_project_management_issue_time_spent_changed'
      ISSUE_COMMENT_ADDED = 'g_project_management_issue_comment_added'
      ISSUE_COMMENT_EDITED = 'g_project_management_issue_comment_edited'
      ISSUE_COMMENT_REMOVED = 'g_project_management_issue_comment_removed'
      ISSUE_DESIGN_COMMENT_REMOVED = 'g_project_management_issue_design_comments_removed'

      class << self
        def track_issue_created_action(author:, project:)
          track_snowplow_action(ISSUE_CREATED, author, project)
          track_unique_action(ISSUE_CREATED, author)
        end

        def track_issue_title_changed_action(author:, project:)
          track_snowplow_action(ISSUE_TITLE_CHANGED, author, project)
          track_unique_action(ISSUE_TITLE_CHANGED, author)
        end

        def track_issue_description_changed_action(author:, project:)
          track_snowplow_action(ISSUE_DESCRIPTION_CHANGED, author, project)
          track_unique_action(ISSUE_DESCRIPTION_CHANGED, author)
        end

        def track_issue_assignee_changed_action(author:, project:)
          track_snowplow_action(ISSUE_ASSIGNEE_CHANGED, author, project)
          track_unique_action(ISSUE_ASSIGNEE_CHANGED, author)
        end

        def track_issue_made_confidential_action(author:, project:)
          track_snowplow_action(ISSUE_MADE_CONFIDENTIAL, author, project)
          track_unique_action(ISSUE_MADE_CONFIDENTIAL, author)
        end

        def track_issue_made_visible_action(author:, project:)
          track_snowplow_action(ISSUE_MADE_VISIBLE, author, project)
          track_unique_action(ISSUE_MADE_VISIBLE, author)
        end

        def track_issue_closed_action(author:, project:)
          track_snowplow_action(ISSUE_CLOSED, author, project)
          track_unique_action(ISSUE_CLOSED, author)
        end

        def track_issue_reopened_action(author:, project:)
          track_snowplow_action(ISSUE_REOPENED, author, project)
          track_unique_action(ISSUE_REOPENED, author)
        end

        def track_issue_label_changed_action(author:, project:)
          track_snowplow_action(ISSUE_LABEL_CHANGED, author, project)
          track_unique_action(ISSUE_LABEL_CHANGED, author)
        end

        def track_issue_milestone_changed_action(author:, project:)
          track_snowplow_action(ISSUE_MILESTONE_CHANGED, author, project)
          track_unique_action(ISSUE_MILESTONE_CHANGED, author)
        end

        def track_issue_cross_referenced_action(author:, project:)
          track_snowplow_action(ISSUE_CROSS_REFERENCED, author, project)
          track_unique_action(ISSUE_CROSS_REFERENCED, author)
        end

        def track_issue_moved_action(author:, project:)
          track_snowplow_action(ISSUE_MOVED, author, project)
          track_unique_action(ISSUE_MOVED, author)
        end

        def track_issue_related_action(author:, project:)
          track_snowplow_action(ISSUE_RELATED, author, project)
          track_unique_action(ISSUE_RELATED, author)
        end

        def track_issue_unrelated_action(author:, project:)
          track_snowplow_action(ISSUE_UNRELATED, author, project)
          track_unique_action(ISSUE_UNRELATED, author)
        end

        def track_issue_marked_as_duplicate_action(author:, project:)
          track_snowplow_action(ISSUE_MARKED_AS_DUPLICATE, author, project)
          track_unique_action(ISSUE_MARKED_AS_DUPLICATE, author)
        end

        def track_issue_locked_action(author:, project:)
          track_snowplow_action(ISSUE_LOCKED, author, project)
          track_unique_action(ISSUE_LOCKED, author)
        end

        def track_issue_unlocked_action(author:, project:)
          track_snowplow_action(ISSUE_UNLOCKED, author, project)
          track_unique_action(ISSUE_UNLOCKED, author)
        end

        def track_issue_designs_added_action(author:, project:)
          track_snowplow_action(ISSUE_DESIGNS_ADDED, author, project)
          track_unique_action(ISSUE_DESIGNS_ADDED, author)
        end

        def track_issue_designs_modified_action(author:, project:)
          track_snowplow_action(ISSUE_DESIGNS_MODIFIED, author, project)
          track_unique_action(ISSUE_DESIGNS_MODIFIED, author)
        end

        def track_issue_designs_removed_action(author:, project:)
          track_snowplow_action(ISSUE_DESIGNS_REMOVED, author, project)
          track_unique_action(ISSUE_DESIGNS_REMOVED, author)
        end

        def track_issue_due_date_changed_action(author:, project:)
          track_snowplow_action(ISSUE_DUE_DATE_CHANGED, author, project)
          track_unique_action(ISSUE_DUE_DATE_CHANGED, author)
        end

        def track_issue_time_estimate_changed_action(author:, project:)
          track_snowplow_action(ISSUE_TIME_ESTIMATE_CHANGED, author, project)
          track_unique_action(ISSUE_TIME_ESTIMATE_CHANGED, author)
        end

        def track_issue_time_spent_changed_action(author:, project:)
          track_snowplow_action(ISSUE_TIME_SPENT_CHANGED, author, project)
          track_unique_action(ISSUE_TIME_SPENT_CHANGED, author)
        end

        def track_issue_comment_added_action(author:, project:)
          track_snowplow_action(ISSUE_COMMENT_ADDED, author, project)
          track_unique_action(ISSUE_COMMENT_ADDED, author)
        end

        def track_issue_comment_edited_action(author:, project:)
          track_snowplow_action(ISSUE_COMMENT_EDITED, author, project)
          track_unique_action(ISSUE_COMMENT_EDITED, author)
        end

        def track_issue_comment_removed_action(author:, project:)
          track_snowplow_action(ISSUE_COMMENT_REMOVED, author, project)
          track_unique_action(ISSUE_COMMENT_REMOVED, author)
        end

        def track_issue_cloned_action(author:, project:)
          track_snowplow_action(ISSUE_CLONED, author, project)
          track_unique_action(ISSUE_CLONED, author)
        end

        def track_issue_design_comment_removed_action(author:, project:)
          track_snowplow_action(ISSUE_DESIGN_COMMENT_REMOVED, author, project)
          track_unique_action(ISSUE_DESIGN_COMMENT_REMOVED, author)
        end

        private

        def track_snowplow_action(event_name, author, project)
          return unless Feature.enabled?(:route_hll_to_snowplow_phase2, project.namespace)
          return unless author

          Gitlab::Tracking.event(
            ISSUE_CATEGORY,
            ISSUE_ACTION,
            label: ISSUE_LABEL,
            property: event_name,
            project: project,
            namespace: project.namespace,
            user: author,
            context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: event_name).to_context]
          )
        end

        def track_unique_action(event_name, author)
          return unless author

          Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event_name, values: author.id)
        end
      end
    end
  end
end

Gitlab::UsageDataCounters::IssueActivityUniqueCounter.prepend_mod_with('Gitlab::UsageDataCounters::IssueActivityUniqueCounter')