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
403dc77e
Commit
403dc77e
authored
Jul 09, 2020
by
Alper Akgun
Committed by
Ash McKenzie
Jul 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Harden deployment counters
Use a more specialized index and use start and finish parameters
parent
e20b5649
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
8 deletions
+54
-8
changelogs/unreleased/221184-optimize-rolling-28-counters-for-.yml
...s/unreleased/221184-optimize-rolling-28-counters-for-.yml
+5
-0
db/post_migrate/20200704161600_add_index_on_id_and_status_and_created_at_to_deployments.rb
...d_index_on_id_and_status_and_created_at_to_deployments.rb
+19
-0
db/structure.sql
db/structure.sql
+2
-1
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+24
-6
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+4
-1
No files found.
changelogs/unreleased/221184-optimize-rolling-28-counters-for-.yml
0 → 100644
View file @
403dc77e
---
title
:
Optimize deployment counters for last 28 days
merge_request
:
35892
author
:
type
:
performance
db/post_migrate/20200704161600_add_index_on_id_and_status_and_created_at_to_deployments.rb
0 → 100644
View file @
403dc77e
# frozen_string_literal: true
class
AddIndexOnIdAndStatusAndCreatedAtToDeployments
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:deployments
,
[
:id
,
:status
,
:created_at
]
remove_concurrent_index
:deployments
,
[
:id
,
:status
]
end
def
down
add_concurrent_index
:deployments
,
[
:id
,
:status
]
remove_concurrent_index
:deployments
,
[
:id
,
:status
,
:created_at
]
end
end
db/structure.sql
View file @
403dc77e
...
...
@@ -18986,7 +18986,7 @@ CREATE INDEX index_deployments_on_environment_id_and_iid_and_project_id ON publi
CREATE
INDEX
index_deployments_on_environment_id_and_status
ON
public
.
deployments
USING
btree
(
environment_id
,
status
);
CREATE
INDEX
index_deployments_on_id_and_status
ON
public
.
deployments
USING
btree
(
id
,
status
);
CREATE
INDEX
index_deployments_on_id_and_status
_and_created_at
ON
public
.
deployments
USING
btree
(
id
,
status
,
created_at
);
CREATE
INDEX
index_deployments_on_id_where_cluster_id_present
ON
public
.
deployments
USING
btree
(
id
)
WHERE
(
cluster_id
IS
NOT
NULL
);
...
...
@@ -23639,6 +23639,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200702123805
20200703154822
20200704143633
20200704161600
20200706005325
20200706170536
20200707071941
...
...
lib/gitlab/usage_data.rb
View file @
403dc77e
...
...
@@ -84,9 +84,9 @@ module Gitlab
auto_devops_enabled:
count
(
::
ProjectAutoDevops
.
enabled
),
auto_devops_disabled:
count
(
::
ProjectAutoDevops
.
disabled
),
deploy_keys:
count
(
DeployKey
),
deployments:
count
(
Deployment
),
successful_deployments:
count
(
Deployment
.
success
),
failed_deployments:
count
(
Deployment
.
failed
),
deployments:
deployment_
count
(
Deployment
),
successful_deployments:
deployment_
count
(
Deployment
.
success
),
failed_deployments:
deployment_
count
(
Deployment
.
failed
),
environments:
count
(
::
Environment
),
clusters:
count
(
::
Clusters
::
Cluster
),
clusters_enabled:
count
(
::
Clusters
::
Cluster
.
enabled
),
...
...
@@ -169,9 +169,9 @@ module Gitlab
def
system_usage_data_monthly
{
counts_monthly:
{
deployments:
count
(
Deployment
.
where
(
last_28_days_time_period
)),
successful_deployments:
count
(
Deployment
.
success
.
where
(
last_28_days_time_period
)),
failed_deployments:
count
(
Deployment
.
failed
.
where
(
last_28_days_time_period
)),
deployments:
deployment_
count
(
Deployment
.
where
(
last_28_days_time_period
)),
successful_deployments:
deployment_
count
(
Deployment
.
success
.
where
(
last_28_days_time_period
)),
failed_deployments:
deployment_
count
(
Deployment
.
failed
.
where
(
last_28_days_time_period
)),
personal_snippets:
count
(
PersonalSnippet
.
where
(
last_28_days_time_period
)),
project_snippets:
count
(
ProjectSnippet
.
where
(
last_28_days_time_period
))
}.
tap
do
|
data
|
...
...
@@ -616,12 +616,26 @@ module Gitlab
end
end
def
deployment_minimum_id
strong_memoize
(
:deployment_minimum_id
)
do
::
Deployment
.
minimum
(
:id
)
end
end
def
deployment_maximum_id
strong_memoize
(
:deployment_maximum_id
)
do
::
Deployment
.
maximum
(
:id
)
end
end
def
clear_memoized
clear_memoization
(
:issue_minimum_id
)
clear_memoization
(
:issue_maximum_id
)
clear_memoization
(
:user_minimum_id
)
clear_memoization
(
:user_maximum_id
)
clear_memoization
(
:unique_visit_service
)
clear_memoization
(
:deployment_minimum_id
)
clear_memoization
(
:deployment_maximum_id
)
end
# rubocop: disable CodeReuse/ActiveRecord
...
...
@@ -645,6 +659,10 @@ module Gitlab
def
filtered_omniauth_provider_names
omniauth_provider_names
.
reject
{
|
name
|
name
.
starts_with?
(
'ldap'
)
}
end
def
deployment_count
(
relation
)
count
relation
,
start:
deployment_minimum_id
,
finish:
deployment_maximum_id
end
end
end
end
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
403dc77e
...
...
@@ -18,7 +18,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
it
'clears memoized values'
do
%i(issue_minimum_id issue_maximum_id user_minimum_id user_maximum_id unique_visit_service)
.
each
do
|
key
|
values
=
%i(issue_minimum_id issue_maximum_id
user_minimum_id user_maximum_id unique_visit_service
deployment_minimum_id deployment_maximum_id)
values
.
each
do
|
key
|
expect
(
described_class
).
to
receive
(
:clear_memoization
).
with
(
key
)
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