Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
gitlab-org
gitlab-exporter
Commits
ce429417
Commit
ce429417
authored
Jan 23, 2018
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for table/column existence before querying rows count
parent
b20fb9f5
Pipeline
#75370
passed with stage
in 2 minutes and 10 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
8 deletions
+25
-8
Gemfile.lock
Gemfile.lock
+1
-1
lib/gitlab_monitor/database/row_count.rb
lib/gitlab_monitor/database/row_count.rb
+22
-5
lib/gitlab_monitor/version.rb
lib/gitlab_monitor/version.rb
+1
-1
spec/database/row_count_spec.rb
spec/database/row_count_spec.rb
+1
-1
No files found.
Gemfile.lock
View file @
ce429417
PATH
remote: .
specs:
gitlab-monitor (2.
3
.0)
gitlab-monitor (2.
5
.0)
connection_pool (~> 2.2.1)
pg (~> 0.18.4)
quantile (~> 0.2.0)
...
...
lib/gitlab_monitor/database/row_count.rb
View file @
ce429417
...
...
@@ -13,7 +13,8 @@ module GitLab
joins:
"INNER JOIN project_mirror_data ON project_mirror_data.project_id = projects.id"
,
where:
"projects.mirror = 't' AND "
\
"projects.import_status NOT IN ('scheduled', 'started') AND "
\
"next_execution_timestamp <= NOW()"
"next_execution_timestamp <= NOW()"
,
check:
"SELECT 1 FROM information_schema.tables WHERE table_name='project_mirror_data'"
},
soft_deleted_projects:
{
select: :projects
,
where:
"pending_delete=true"
},
orphaned_projects:
{
...
...
@@ -27,8 +28,10 @@ module GitLab
def
run
results
=
Hash
.
new
(
0
)
QUERIES
.
each
do
|
key
,
query
|
results
[
key
]
=
execute
(
query
)
QUERIES
.
each
do
|
key
,
query_hash
|
next
if
query_hash
[
:check
]
&&
!
successful_check?
(
query_hash
[
:check
])
results
[
key
]
=
count_from_query_hash
(
query_hash
)
end
results
...
...
@@ -36,12 +39,26 @@ module GitLab
private
def
count_from_query_hash
(
query_hash
)
result
=
execute
(
construct_query
(
query_hash
))
return
0
unless
result
result
[
0
][
"count"
]
end
def
successful_check?
(
query
)
result
=
execute
(
"SELECT EXISTS (
#{
query
}
)"
)
return
unless
result
result
[
0
][
"exists"
]
==
"t"
end
def
execute
(
query
)
with_connection_pool
do
|
conn
|
conn
.
exec
(
construct_query
(
query
))[
0
][
"count"
]
conn
.
exec
(
query
)
end
rescue
PG
::
UndefinedTable
,
PG
::
UndefinedColumn
0
nil
end
# Not private so I can test it without meta programming tricks
...
...
lib/gitlab_monitor/version.rb
View file @
ce429417
module
GitLab
module
Monitor
VERSION
=
"2.
4
.0"
.
freeze
VERSION
=
"2.
5
.0"
.
freeze
end
end
spec/database/row_count_spec.rb
View file @
ce429417
...
...
@@ -11,7 +11,7 @@ describe GitLab::Monitor::Database::RowCountCollector do
end
it
"executes the query"
do
allow
(
collector
).
to
receive
(
:
execute
).
with
(
query
[
:project_1
]).
and_return
(
3
)
allow
(
collector
).
to
receive
(
:
count_from_query_hash
).
with
(
query
[
:project_1
]).
and_return
(
3
)
expect
(
collector
.
run
).
to
eq
(
project_1:
3
)
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