Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d6814e03
Commit
d6814e03
authored
Apr 08, 2022
by
Niko Belokolodov
Committed by
Heinrich Lee Yu
Apr 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move p_ci_templates metrics to Snowplow
parent
197edba5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
19 deletions
+48
-19
app/services/event_create_service.rb
app/services/event_create_service.rb
+3
-2
lib/gitlab/ci/pipeline/chain/template_usage.rb
lib/gitlab/ci/pipeline/chain/template_usage.rb
+1
-1
lib/gitlab/usage_data_counters/ci_template_unique_counter.rb
lib/gitlab/usage_data_counters/ci_template_unique_counter.rb
+7
-2
spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb
spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb
+1
-1
spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb
...ab/usage_data_counters/ci_template_unique_counter_spec.rb
+33
-11
spec/services/event_create_service_spec.rb
spec/services/event_create_service_spec.rb
+3
-2
No files found.
app/services/event_create_service.rb
View file @
d6814e03
...
...
@@ -184,8 +184,9 @@ class EventCreateService
track_event
(
event_action: :pushed
,
event_target:
Project
,
author_id:
current_user
.
id
)
if
Feature
.
enabled?
(
:route_hll_to_snowplow
,
project
,
default_enabled: :yaml
)
Gitlab
::
Tracking
.
event
(
self
.
class
.
to_s
,
'action_active_users_project_repo'
,
namespace:
project
,
user:
current_user
)
namespace
=
project
.
namespace
if
Feature
.
enabled?
(
:route_hll_to_snowplow
,
namespace
,
default_enabled: :yaml
)
Gitlab
::
Tracking
.
event
(
self
.
class
.
to_s
,
'action_active_users_project_repo'
,
namespace:
namespace
,
user:
current_user
,
project:
project
)
end
Users
::
LastPushEventService
.
new
(
current_user
)
...
...
lib/gitlab/ci/pipeline/chain/template_usage.rb
View file @
d6814e03
...
...
@@ -19,7 +19,7 @@ module Gitlab
def
track_event
(
template
)
Gitlab
::
UsageDataCounters
::
CiTemplateUniqueCounter
.
track_unique_project_event
(
project
_id:
pipeline
.
project_id
,
template:
template
,
config_source:
pipeline
.
config_source
)
.
track_unique_project_event
(
project
:
pipeline
.
project
,
template:
template
,
config_source:
pipeline
.
config_source
,
user:
current_user
)
end
def
included_templates
...
...
lib/gitlab/usage_data_counters/ci_template_unique_counter.rb
View file @
d6814e03
...
...
@@ -6,13 +6,18 @@ module Gitlab::UsageDataCounters
KNOWN_EVENTS_FILE_PATH
=
File
.
expand_path
(
'known_events/ci_templates.yml'
,
__dir__
)
class
<<
self
def
track_unique_project_event
(
project
_id
:,
template
:,
config_source
:)
def
track_unique_project_event
(
project
:,
template
:,
config_source
:,
user
:)
expanded_template_name
=
expand_template_name
(
template
)
return
unless
expanded_template_name
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
track_event
(
ci_template_event_name
(
expanded_template_name
,
config_source
),
values:
project
_
id
ci_template_event_name
(
expanded_template_name
,
config_source
),
values:
project
.
id
)
namespace
=
project
.
namespace
if
Feature
.
enabled?
(
:route_hll_to_snowplow
,
namespace
,
default_enabled: :yaml
)
Gitlab
::
Tracking
.
event
(
name
,
'ci_templates_unique'
,
namespace:
namespace
,
user:
user
,
project:
project
)
end
end
def
ci_templates
(
relative_base
=
'lib/gitlab/ci/templates'
)
...
...
spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb
View file @
d6814e03
...
...
@@ -28,7 +28,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::TemplateUsage do
%w(Template-1 Template-2)
.
each
do
|
expected_template
|
expect
(
Gitlab
::
UsageDataCounters
::
CiTemplateUniqueCounter
).
to
(
receive
(
:track_unique_project_event
)
.
with
(
project
_id:
project
.
id
,
template:
expected_template
,
config_source:
pipeline
.
config_source
)
.
with
(
project
:
project
,
template:
expected_template
,
config_source:
pipeline
.
config_source
,
user:
user
)
)
end
...
...
spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb
View file @
d6814e03
...
...
@@ -5,30 +5,52 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
UsageDataCounters
::
CiTemplateUniqueCounter
do
describe
'.track_unique_project_event'
do
using
RSpec
::
Parameterized
::
TableSyntax
include
SnowplowHelpers
let
(
:project_id
)
{
1
}
let
(
:project
)
{
build
(
:project
)
}
let
(
:user
)
{
build
(
:user
)
}
shared_examples
'tracks template'
do
let
(
:subject
)
{
described_class
.
track_unique_project_event
(
project:
project
,
template:
template_path
,
config_source:
config_source
,
user:
user
)
}
it
"has an event defined for template"
do
expect
do
described_class
.
track_unique_project_event
(
project_id:
project_id
,
template:
template_path
,
config_source:
config_source
)
subject
end
.
not_to
raise_error
end
it
"tracks template"
do
expanded_template_name
=
described_class
.
expand_template_name
(
template_path
)
expected_template_event_name
=
described_class
.
ci_template_event_name
(
expanded_template_name
,
config_source
)
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
to
(
receive
(
:track_event
)).
with
(
expected_template_event_name
,
values:
project_id
)
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
to
(
receive
(
:track_event
)).
with
(
expected_template_event_name
,
values:
project
.
id
)
subject
end
context
'Snowplow'
do
it
'event is not tracked if FF is disabled'
do
stub_feature_flags
(
route_hll_to_snowplow:
false
)
subject
described_class
.
track_unique_project_event
(
project_id:
project_id
,
template:
template_path
,
config_source:
config_source
)
expect_no_snowplow_event
end
it
'tracks event'
do
subject
expect_snowplow_event
(
category:
described_class
.
to_s
,
action:
'ci_templates_unique'
,
namespace:
project
.
namespace
,
user:
user
,
project:
project
)
end
end
end
context
'with explicit includes'
do
context
'with explicit includes'
,
:snowplow
do
let
(
:config_source
)
{
:repository_source
}
(
described_class
.
ci_templates
-
[
'Verify/Browser-Performance.latest.gitlab-ci.yml'
,
'Verify/Browser-Performance.gitlab-ci.yml'
]).
each
do
|
template
|
...
...
@@ -40,7 +62,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
end
end
context
'with implicit includes'
do
context
'with implicit includes'
,
:snowplow
do
let
(
:config_source
)
{
:auto_devops_source
}
[
...
...
@@ -60,7 +82,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
it
'expands short template names'
do
expect
do
described_class
.
track_unique_project_event
(
project
_id:
1
,
template:
'Dependency-Scanning.gitlab-ci.yml'
,
config_source: :repository_source
)
described_class
.
track_unique_project_event
(
project
:
project
,
template:
'Dependency-Scanning.gitlab-ci.yml'
,
config_source: :repository_source
,
user:
user
)
end
.
not_to
raise_error
end
end
...
...
spec/services/event_create_service_spec.rb
View file @
d6814e03
...
...
@@ -35,8 +35,9 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
expect_snowplow_event
(
category:
described_class
.
to_s
,
action:
'action_active_users_project_repo'
,
namespace:
project
,
user:
user
namespace:
project
.
namespace
,
user:
user
,
project:
project
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment