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
b94f9fdb
Commit
b94f9fdb
authored
Apr 10, 2020
by
David Fernandez
Committed by
Igor Drozdov
Apr 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add container expiration policies tracking to usage data
parent
cbde7f72
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
1 deletion
+81
-1
app/models/container_expiration_policy.rb
app/models/container_expiration_policy.rb
+1
-0
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+24
-1
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+37
-0
spec/support/helpers/usage_data_helpers.rb
spec/support/helpers/usage_data_helpers.rb
+19
-0
No files found.
app/models/container_expiration_policy.rb
View file @
b94f9fdb
...
...
@@ -2,6 +2,7 @@
class
ContainerExpirationPolicy
<
ApplicationRecord
include
Schedulable
include
UsageStatistics
belongs_to
:project
,
inverse_of: :container_expiration_policy
...
...
lib/gitlab/usage_data.rb
View file @
b94f9fdb
...
...
@@ -160,8 +160,31 @@ module Gitlab
signup_enabled:
alt_usage_data
{
Gitlab
::
CurrentSettings
.
allow_signup?
},
web_ide_clientside_preview_enabled:
alt_usage_data
{
Gitlab
::
CurrentSettings
.
web_ide_clientside_preview_enabled?
},
ingress_modsecurity_enabled:
Feature
.
enabled?
(
:ingress_modsecurity
)
}
}.
merge
(
features_usage_data_container_expiration_policies
)
end
# rubocop: disable CodeReuse/ActiveRecord
def
features_usage_data_container_expiration_policies
results
=
{}
start
=
::
Project
.
minimum
(
:id
)
finish
=
::
Project
.
maximum
(
:id
)
results
[
:projects_with_expiration_policy_disabled
]
=
distinct_count
(
::
ContainerExpirationPolicy
.
where
(
enabled:
false
),
:project_id
,
start:
start
,
finish:
finish
)
base
=
::
ContainerExpirationPolicy
.
active
results
[
:projects_with_expiration_policy_enabled
]
=
distinct_count
(
base
,
:project_id
,
start:
start
,
finish:
finish
)
%i[keep_n cadence older_than]
.
each
do
|
option
|
::
ContainerExpirationPolicy
.
public_send
(
"
#{
option
}
_options"
).
keys
.
each
do
|
value
|
# rubocop: disable GitlabSecurity/PublicSend
results
[
"projects_with_expiration_policy_enabled_with_
#{
option
}
_set_to_
#{
value
}
"
.
to_sym
]
=
distinct_count
(
base
.
where
(
option
=>
value
),
:project_id
,
start:
start
,
finish:
finish
)
end
end
results
[
:projects_with_expiration_policy_enabled_with_keep_n_unset
]
=
distinct_count
(
base
.
where
(
keep_n:
nil
),
:project_id
,
start:
start
,
finish:
finish
)
results
[
:projects_with_expiration_policy_enabled_with_older_than_unset
]
=
distinct_count
(
base
.
where
(
older_than:
nil
),
:project_id
,
start:
start
,
finish:
finish
)
results
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [Hash<Symbol, Integer>]
def
usage_counters
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
b94f9fdb
...
...
@@ -142,6 +142,43 @@ describe Gitlab::UsageData, :aggregate_failures do
expect
(
subject
[
:gitlab_shared_runners_enabled
]).
to
eq
(
Gitlab
.
config
.
gitlab_ci
.
shared_runners_enabled
)
expect
(
subject
[
:web_ide_clientside_preview_enabled
]).
to
eq
(
Gitlab
::
CurrentSettings
.
web_ide_clientside_preview_enabled?
)
end
context
'with existing container expiration policies'
do
let_it_be
(
:disabled
)
{
create
(
:container_expiration_policy
,
enabled:
false
)
}
let_it_be
(
:enabled
)
{
create
(
:container_expiration_policy
,
enabled:
true
)
}
%i[keep_n cadence older_than]
.
each
do
|
attribute
|
ContainerExpirationPolicy
.
send
(
"
#{
attribute
}
_options"
).
keys
.
each
do
|
value
|
let_it_be
(
"container_expiration_policy_with_
#{
attribute
}
_set_to_
#{
value
}
"
)
{
create
(
:container_expiration_policy
,
attribute
=>
value
)
}
end
end
let
(
:inactive_policies
)
{
::
ContainerExpirationPolicy
.
where
(
enabled:
false
)
}
let
(
:active_policies
)
{
::
ContainerExpirationPolicy
.
active
}
it
'gathers usage data'
do
expect
(
subject
[
:projects_with_expiration_policy_enabled
]).
to
eq
16
expect
(
subject
[
:projects_with_expiration_policy_disabled
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_unset
]).
to
eq
10
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_1
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_5
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_10
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_25
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_50
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_unset
]).
to
eq
12
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_7d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_14d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_30d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_90d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_1d
]).
to
eq
12
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_7d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_14d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_1month
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_3month
]).
to
eq
1
end
end
end
describe
'#components_usage_data'
do
...
...
spec/support/helpers/usage_data_helpers.rb
View file @
b94f9fdb
...
...
@@ -131,5 +131,24 @@ module UsageDataHelpers
prometheus_metrics_enabled
web_ide_clientside_preview_enabled
ingress_modsecurity_enabled
projects_with_expiration_policy_disabled
projects_with_expiration_policy_enabled
projects_with_expiration_policy_enabled_with_keep_n_unset
projects_with_expiration_policy_enabled_with_older_than_unset
projects_with_expiration_policy_enabled_with_keep_n_set_to_1
projects_with_expiration_policy_enabled_with_keep_n_set_to_5
projects_with_expiration_policy_enabled_with_keep_n_set_to_10
projects_with_expiration_policy_enabled_with_keep_n_set_to_25
projects_with_expiration_policy_enabled_with_keep_n_set_to_50
projects_with_expiration_policy_enabled_with_keep_n_set_to_100
projects_with_expiration_policy_enabled_with_cadence_set_to_1d
projects_with_expiration_policy_enabled_with_cadence_set_to_7d
projects_with_expiration_policy_enabled_with_cadence_set_to_14d
projects_with_expiration_policy_enabled_with_cadence_set_to_1month
projects_with_expiration_policy_enabled_with_cadence_set_to_3month
projects_with_expiration_policy_enabled_with_older_than_set_to_7d
projects_with_expiration_policy_enabled_with_older_than_set_to_14d
projects_with_expiration_policy_enabled_with_older_than_set_to_30d
projects_with_expiration_policy_enabled_with_older_than_set_to_90d
)
.
freeze
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