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
400c4cf5
Verified
Commit
400c4cf5
authored
Apr 03, 2019
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it possible to disable gathering number of created jobs
parent
01e38af8
Pipeline
#108689
passed with stage
in 1 minute and 4 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
22 deletions
+57
-22
config/gitlab-monitor.yml.example
config/gitlab-monitor.yml.example
+2
-1
lib/gitlab_monitor/database/ci_builds.rb
lib/gitlab_monitor/database/ci_builds.rb
+15
-14
spec/database/ci_builds_spec.rb
spec/database/ci_builds_spec.rb
+40
-7
No files found.
config/gitlab-monitor.yml.example
View file @
400c4cf5
...
...
@@ -46,6 +46,7 @@ probes:
opts:
<<: *db_common_opts
allowed_repeated_commands_count: 2
count_created_builds: false
tuple_stats:
class_name: Database::TuplesProber
<<: *db_common
...
...
lib/gitlab_monitor/database/ci_builds.rb
View file @
400c4cf5
...
...
@@ -24,7 +24,7 @@ module GitLab
JOIN application_settings
ON application_settings.id = 1
WHERE ci_builds.type = 'Ci::Build'
AND ci_builds.status
IN ('created', 'pending')
AND ci_builds.status
= '%s'
AND projects.pending_delete = 'f'
GROUP BY
projects.namespace_id,
...
...
@@ -46,7 +46,7 @@ module GitLab
JOIN projects
ON projects.id = ci_builds.project_id
WHERE ci_builds.type = 'Ci::Build'
AND ci_builds.status
IN ('created', 'pending')
AND ci_builds.status
= '%s'
AND projects.pending_delete = 'f'
GROUP BY
projects.namespace_id,
...
...
@@ -232,15 +232,20 @@ module GitLab
subquery.status
SQL
STATUS_CREATED
=
"created"
.
freeze
STATUS_PENDING
=
"pending"
.
freeze
def
initialize
(
opts
)
super
(
opts
)
@allowed_repeated_commands_count
=
opts
[
:allowed_repeated_commands_count
]
@count_created_builds
=
opts
[
:count_created_builds
]
end
def
run
results
=
{}
results
.
merge!
(
builds
)
results
[
:created_builds
]
=
builds
(
STATUS_CREATED
)
if
@count_created_builds
results
[
:pending_builds
]
=
builds
(
STATUS_PENDING
)
results
[
:stale_builds
]
=
stale_builds
results
[
:per_runner
]
=
per_runner_builds
results
[
:repeated_commands
]
=
repeated_commands
...
...
@@ -249,18 +254,13 @@ module GitLab
private
def
builds
results
=
{
pending_builds:
[],
created_builds:
[]
}
def
builds
(
status
)
results
=
[]
query
=
mirror_column?
?
BUILDS_QUERY_EE
:
BUILDS_QUERY_CE
query
=
query
%
[
status
]
# rubocop:disable Style/FormatString
exec_query_with_custom_random_page_cost
(
query
).
each
do
|
row
|
row_data
=
transform_builds_row_to_values
(
row
)
if
row
[
"status"
]
==
"pending"
results
[
:pending_builds
].
push
(
row_data
)
elsif
row
[
"status"
]
==
"created"
results
[
:created_builds
].
push
(
row_data
)
end
results
<<
transform_builds_row_to_values
(
row
)
end
results
...
...
@@ -377,15 +377,16 @@ module GitLab
@metrics
=
metrics
collector_opts
=
{
connection_string:
opts
[
:connection_string
],
allowed_repeated_commands_count:
opts
[
:allowed_repeated_commands_count
]
}
allowed_repeated_commands_count:
opts
[
:allowed_repeated_commands_count
],
count_created_builds:
opts
[
:count_created_builds
]
}
@collector
=
CiBuildsCollector
.
new
(
collector_opts
)
end
def
probe_db
@results
=
@collector
.
run
ci_builds_metrics
(
@results
[
:created_builds
],
"ci_created_builds"
)
if
@results
[
:created_builds
]
ci_builds_metrics
(
@results
[
:pending_builds
],
"ci_pending_builds"
)
ci_builds_metrics
(
@results
[
:created_builds
],
"ci_created_builds"
)
ci_stale_builds_metrics
metrics_per_runner
repeated_commands_metrics
...
...
spec/database/ci_builds_spec.rb
View file @
400c4cf5
...
...
@@ -15,6 +15,7 @@ describe GitLab::Monitor::Database do
let
(
:connection_pool
)
{
double
(
"connection pool"
)
}
let
(
:connection
)
{
double
(
"connection"
)
}
let
(
:allowed_repeated_commands_count
)
{
5
}
let
(
:count_created_builds
)
{
false
}
def
stub_ee
allow
(
connection
).
to
receive
(
:exec
).
with
(
mirror_column_query
).
and_return
([{
"exists"
=>
"t"
}])
...
...
@@ -142,7 +143,11 @@ describe GitLab::Monitor::Database do
end
describe
GitLab
::
Monitor
::
Database
::
CiBuildsCollector
do
let
(
:collector
)
{
described_class
.
new
(
connection_string:
"host=localhost"
,
allowed_repeated_commands_count:
allowed_repeated_commands_count
)
}
let
(
:collector
)
do
described_class
.
new
(
connection_string:
"host=localhost"
,
allowed_repeated_commands_count:
allowed_repeated_commands_count
,
count_created_builds:
count_created_builds
)
end
let
(
:expected_stale_builds
)
{
2
}
shared_examples
"data collector"
do
...
...
@@ -156,9 +161,22 @@ describe GitLab::Monitor::Database do
expect
(
subject
[
:pending_builds
]).
to
include
(
*
expected_pending_builds
)
end
context
"when count_created_build is set to true"
do
let
(
:count_created_builds
)
{
true
}
it
"returns raw created_builds data"
do
expect
(
subject
).
to
have_key
(
:created_builds
)
expect
(
subject
[
:created_builds
]).
to
include
(
*
expected_created_builds
)
end
end
context
"when count_created_build is set to false"
do
let
(
:count_created_builds
)
{
false
}
it
"doesn't return raw created_builds data"
do
expect
(
subject
).
not_to
have_key
(
:created_builds
)
end
end
it
"returns raw stale_builds data"
do
expect
(
subject
[
:stale_builds
]).
to
eq
(
expected_stale_builds
)
...
...
@@ -238,7 +256,8 @@ describe GitLab::Monitor::Database do
let
(
:writer
)
{
StringIO
.
new
}
let
(
:prober
)
do
opts
=
{
connection_string:
"host=localhost"
,
allowed_repeated_commands_count:
allowed_repeated_commands_count
}
allowed_repeated_commands_count:
allowed_repeated_commands_count
,
count_created_builds:
count_created_builds
}
described_class
.
new
(
opts
,
metrics:
GitLab
::
Monitor
::
PrometheusMetrics
.
new
(
include_timestamp:
false
))
end
...
...
@@ -255,11 +274,25 @@ describe GitLab::Monitor::Database do
end
context
"when PG exceptions aren't raised"
do
context
"when count_created_builds is set to true"
do
let
(
:count_created_builds
)
{
true
}
it
"responds with created builds Prometheus metrics"
do
ci_created_builds_expected_lines
.
each
do
|
expected_line
|
expect
(
subject
).
to
match
(
Regexp
.
new
(
"^
#{
expected_line
}
$"
,
Regexp
::
MULTILINE
))
end
end
end
context
"when count_created_builds is set to false"
do
let
(
:count_created_builds
)
{
false
}
it
"doesn't respond with created builds Prometheus metrics"
do
ci_created_builds_expected_lines
.
each
do
|
expected_line
|
expect
(
subject
).
not_to
match
(
Regexp
.
new
(
"^
#{
expected_line
}
$"
,
Regexp
::
MULTILINE
))
end
end
end
it
"responds with pending builds Prometheus metrics"
do
ci_pending_builds_expected_lines
.
each
do
|
expected_line
|
...
...
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