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
258d2f2e
Commit
258d2f2e
authored
Aug 30, 2021
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track all CI template inclusions
Changelog: other
parent
c6e9a0f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
7 deletions
+51
-7
config/feature_flags/development/track_all_ci_template_inclusions.yml
...re_flags/development/track_all_ci_template_inclusions.yml
+8
-0
lib/gitlab/usage_data_counters/ci_template_unique_counter.rb
lib/gitlab/usage_data_counters/ci_template_unique_counter.rb
+15
-3
spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb
...ab/usage_data_counters/ci_template_unique_counter_spec.rb
+28
-4
No files found.
config/feature_flags/development/track_all_ci_template_inclusions.yml
0 → 100644
View file @
258d2f2e
---
name
:
track_all_ci_template_inclusions
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/69204
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/339684
milestone
:
'
14.3'
type
:
development
group
:
group::pipeline authoring
default_enabled
:
false
lib/gitlab/usage_data_counters/ci_template_unique_counter.rb
View file @
258d2f2e
...
...
@@ -28,12 +28,24 @@ module Gitlab::UsageDataCounters
private
def
unique_project_event
(
template
,
config_source
)
if
name
=
TEMPLATE_TO_EVENT
[
template
]
prefix
=
'implicit_'
if
config_source
.
to_s
==
'auto_devops_source'
if
TEMPLATE_TO_EVENT
[
template
]
template_inclusion_name
(
config_source
,
TEMPLATE_TO_EVENT
[
template
])
end
"p_
#{
REDIS_SLOT
}
_
#{
prefix
}#{
name
}
"
if
Feature
.
enabled?
(
:track_all_ci_template_inclusions
)
template_inclusion_name
(
config_source
,
template_to_event
(
template
))
end
end
def
template_inclusion_name
(
config_source
,
name
)
prefix
=
'implicit_'
if
config_source
.
to_s
==
'auto_devops_source'
"p_
#{
REDIS_SLOT
}
_
#{
prefix
}#{
name
}
"
end
def
template_to_event
(
template
)
File
.
basename
(
template
,
'.gitlab-ci.yml'
).
underscore
end
end
end
end
spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb
View file @
258d2f2e
...
...
@@ -77,13 +77,37 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
let
(
:project_id
)
{
1
}
let
(
:config_source
)
{
:repository_source
}
Dir
.
glob
(
File
.
join
(
'lib'
,
'gitlab'
,
'ci'
,
'templates'
,
'**'
),
base:
Rails
.
root
)
do
|
template
|
Dir
.
glob
(
'**/*.gitlab-ci.yml'
,
base:
Rails
.
root
.
join
(
'lib/gitlab/ci/templates'
)
)
do
|
template
|
next
if
described_class
::
TEMPLATE_TO_EVENT
.
key?
(
template
)
it
"does not track
#{
template
}
"
do
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
not_to
(
receive
(
:track_event
))
it
'has an event defined'
do
expect
do
described_class
.
track_unique_project_event
(
project_id:
project_id
,
template:
described_class
.
send
(
:template_to_event
,
template
),
config_source:
config_source
)
end
.
not_to
raise_error
end
described_class
.
track_unique_project_event
(
project_id:
project_id
,
template:
template
,
config_source:
config_source
)
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
track_all_ci_template_inclusions:
false
)
end
it
"does not track
#{
template
}
"
do
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
not_to
(
receive
(
:track_event
))
described_class
.
track_unique_project_event
(
project_id:
project_id
,
template:
template
,
config_source:
config_source
)
end
end
context
'when feature flag is enabled'
do
before
do
stub_feature_flags
(
track_all_ci_template_inclusions:
true
)
end
it
"tracks
#{
template
}
"
do
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
to
(
receive
(
:track_event
)).
with
(
"p_ci_templates_
#{
File
.
basename
(
template
,
'.gitlab-ci.yml'
).
underscore
}
"
,
values:
project_id
)
described_class
.
track_unique_project_event
(
project_id:
project_id
,
template:
template
,
config_source:
config_source
)
end
end
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