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
1da4cd2e
Commit
1da4cd2e
authored
May 19, 2017
by
Zeger-Jan van de Weg
Committed by
Ahmad Sherif
May 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Monitor scheduled jobs
parent
06964419
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
37 deletions
+70
-37
.gitlab-ci.yml
.gitlab-ci.yml
+1
-1
.rubocop.yml
.rubocop.yml
+13
-3
lib/gitlab_monitor/database/ci_builds.rb
lib/gitlab_monitor/database/ci_builds.rb
+48
-29
spec/database/ci_builds_spec.rb
spec/database/ci_builds_spec.rb
+8
-4
No files found.
.gitlab-ci.yml
View file @
1da4cd2e
image
:
"
ruby:2.
2
"
image
:
"
ruby:2.
3
"
before_script
:
-
git config --global user.email "bot@gitlab.com"
...
...
.rubocop.yml
View file @
1da4cd2e
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength
:
Max
:
120
AllCops
:
TargetRubyVersion
:
2.3
# Just use double quotes please
Style/StringLiterals
:
...
...
@@ -16,8 +15,19 @@ Style/SignalException:
Style/RaiseArgs
:
EnforcedStyle
:
compact
# Lets not freeze all the strings by default
Style/FrozenStringLiteralComment
:
Enabled
:
false
Metrics/MethodLength
:
Max
:
15
Metrics/AbcSize
:
Enabled
:
false
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength
:
Max
:
120
Metrics/ClassLength
:
Max
:
150
lib/gitlab_monitor/database/ci_builds.rb
View file @
1da4cd2e
...
...
@@ -28,26 +28,34 @@ module GitLab
" AND ci_builds.updated_at < NOW() - INTERVAL '1 hour'"
.
freeze
PER_RUNNER_QUERY
=
"SELECT "
\
" ci_builds.runner_id, "
\
" ci_runners.is_shared, "
\
" projects.mirror, "
\
" projects.pending_delete, "
\
" projects.mirror_trigger_builds, "
\
" COUNT(*) AS count "
\
" FROM ci_builds "
\
" JOIN ci_runners "
\
" ON ci_runners.id = ci_builds.runner_id "
\
" JOIN projects "
\
" ON projects.id = ci_builds.project_id "
\
" WHERE ci_builds.type = 'Ci::Build' "
\
" AND ci_builds.status = 'running' "
\
" GROUP BY "
\
" ci_builds.runner_id, "
\
" projects.mirror, "
\
" projects.pending_delete, "
\
" projects.mirror_trigger_builds, "
\
" ci_runners.is_shared"
.
freeze
<<~
SQL
.
freeze
SELECT
ci_builds.runner_id,
ci_runners.is_shared,
projects.mirror,
projects.pending_delete,
projects.mirror_trigger_builds,
ci_pipelines.pipeline_schedule_id,
ci_builds.trigger_request_id,
COUNT(*) AS count
FROM ci_builds
JOIN ci_runners
ON ci_runners.id = ci_builds.runner_id
JOIN projects
ON projects.id = ci_builds.project_id
JOIN ci_pipelines
ON ci_pipelines.id = ci_builds.commit_id
WHERE ci_builds.type = 'Ci::Build'
AND ci_builds.status = 'running'
GROUP BY
ci_builds.runner_id,
projects.mirror,
projects.pending_delete,
projects.mirror_trigger_builds,
ci_runners.is_shared,
ci_pipelines.pipeline_schedule_id,
ci_builds.trigger_request_id
SQL
def
run
results
=
{}
...
...
@@ -65,14 +73,7 @@ module GitLab
results
=
[]
connection
.
exec
(
query
).
each
do
|
row
|
results
.
push
(
runner:
row
[
"runner_id"
].
to_s
,
shared_runner:
row
[
"is_shared"
]
==
"t"
?
"yes"
:
"no"
,
mirror:
row
[
"mirror"
]
==
"t"
?
"yes"
:
"no"
,
pending_delete:
row
[
"pending_delete"
]
==
"t"
?
"yes"
:
"no"
,
mirror_trigger_builds:
row
[
"mirror_trigger_builds"
]
==
"t"
?
"yes"
:
"no"
,
value:
row
[
"count"
].
to_i
)
results
<<
transform_row_to_values
(
row
)
end
results
...
...
@@ -80,6 +81,19 @@ module GitLab
[]
end
def
transform_row_to_values
(
row
)
# rubocop:disable Metrics/CyclomaticComplexity
{
runner:
row
[
"runner_id"
].
to_s
,
shared_runner:
row
[
"is_shared"
]
==
"t"
?
"yes"
:
"no"
,
mirror:
row
[
"mirror"
]
==
"t"
?
"yes"
:
"no"
,
scheduled:
row
[
"pipeline_schedule_id"
]
?
"yes"
:
"no"
,
triggered:
row
[
"trigger_request_id"
]
?
"yes"
:
"no"
,
pending_delete:
row
[
"pending_delete"
]
==
"t"
?
"yes"
:
"no"
,
mirror_trigger_builds:
row
[
"mirror_trigger_builds"
]
==
"t"
?
"yes"
:
"no"
,
value:
row
[
"count"
].
to_i
}
end
def
get_general
(
query
)
connection
.
exec
(
query
)[
0
][
"count"
].
to_i
rescue
PG
::
UndefinedTable
,
PG
::
UndefinedColumn
...
...
@@ -135,10 +149,12 @@ module GitLab
def
ci_builds_metrics
(
results_list
,
metric_name
)
other_value
=
{
"yes"
=>
0
,
"no"
=>
0
}
results_list
.
each
do
|
metric
|
shared_runners
=
metric
[
:shared_runners
]
namespace
=
metric
[
:namespace
]
value
=
metric
[
:value
]
# If we have a low value, put the value into an "other" bucket.
if
value
<
10
other_value
[
shared_runners
]
+=
value
...
...
@@ -146,6 +162,7 @@ module GitLab
@metrics
.
add
(
metric_name
,
value
,
namespace:
namespace
,
shared_runners:
shared_runners
)
end
end
# Add metrics for the "other" bucket.
@metrics
.
add
(
metric_name
,
other_value
[
"yes"
],
namespace:
""
,
shared_runners:
"yes"
)
@metrics
.
add
(
metric_name
,
other_value
[
"no"
],
namespace:
""
,
shared_runners:
"no"
)
...
...
@@ -163,7 +180,9 @@ module GitLab
shared_runner:
metric
[
:shared_runner
],
mirror:
metric
[
:mirror
],
pending_delete:
metric
[
:pending_delete
],
mirror_trigger_builds:
metric
[
:mirror_trigger_builds
])
mirror_trigger_builds:
metric
[
:mirror_trigger_builds
],
scheduled:
metric
[
:scheduled
],
triggered:
metric
[
:triggered
])
end
end
end
...
...
spec/database/ci_builds_spec.rb
View file @
1da4cd2e
...
...
@@ -29,10 +29,14 @@ describe GitLab::Monitor::Database do
"mirror"
=>
"f"
,
"pending_delete"
=>
"f"
,
"mirror_trigger_builds"
=>
"f"
,
"pipeline_schedule_id"
=>
1
,
"trigger_request_id"
=>
nil
,
"count"
=>
15
},
{
"runner_id"
=>
2
,
"is_shared"
=>
"f"
,
"mirror"
=>
"t"
,
"pipeline_schedule_id"
=>
nil
,
"trigger_request_id"
=>
3
,
"pending_delete"
=>
"f"
,
"mirror_trigger_builds"
=>
"t"
,
"count"
=>
5
}])
...
...
@@ -43,8 +47,8 @@ describe GitLab::Monitor::Database do
it
"executes the query"
do
expect
(
collector
.
run
).
to
eq
(
per_runner:
[
{
runner:
"1"
,
shared_runner:
"yes"
,
mirror:
"no"
,
pending_delete:
"no"
,
mirror_trigger_builds:
"no"
,
value:
15
},
{
runner:
"2"
,
shared_runner:
"no"
,
mirror:
"yes"
,
pending_delete:
"no"
,
mirror_trigger_builds:
"yes"
,
value:
5
}
{
runner:
"1"
,
shared_runner:
"yes"
,
mirror:
"no"
,
pending_delete:
"no"
,
mirror_trigger_builds:
"no"
,
scheduled:
"yes"
,
triggered:
"no"
,
value:
15
},
{
runner:
"2"
,
shared_runner:
"no"
,
mirror:
"yes"
,
pending_delete:
"no"
,
mirror_trigger_builds:
"yes"
,
scheduled:
"no"
,
triggered:
"yes"
,
value:
5
}
],
pending_builds:
[
{
namespace:
"1"
,
shared_runners:
"yes"
,
value:
30
},
...
...
@@ -86,8 +90,8 @@ describe GitLab::Monitor::Database do
ci_created_builds{namespace="",shared_runners="yes"} 0
ci_created_builds{namespace="",shared_runners="no"} 0
ci_stale_builds 2
ci_running_builds{runner="1",shared_runner="yes",mirror="no",pending_delete="no",mirror_trigger_builds="no"} 15
ci_running_builds{runner="2",shared_runner="no",mirror="yes",pending_delete="no",mirror_trigger_builds="yes"} 5
ci_running_builds{runner="1",shared_runner="yes",mirror="no",pending_delete="no",mirror_trigger_builds="no"
,scheduled="yes",triggered="no"
} 15
ci_running_builds{runner="2",shared_runner="no",mirror="yes",pending_delete="no",mirror_trigger_builds="yes"
,scheduled="no",triggered="yes"
} 5
OUTPUT
expect
(
writer
.
string
).
to
eq
(
output
.
strip_heredoc
)
...
...
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