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
f2a5493c
Commit
f2a5493c
authored
Apr 10, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch 'improve-jobs-queuing-time-metric' into 'master'"
This reverts merge request !17730
parent
174950b6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
4 additions
and
104 deletions
+4
-104
app/services/ci/register_job_service.rb
app/services/ci/register_job_service.rb
+2
-17
changelogs/unreleased/improve-jobs-queuing-time-metric.yml
changelogs/unreleased/improve-jobs-queuing-time-metric.yml
+0
-5
spec/factories/ci/builds.rb
spec/factories/ci/builds.rb
+0
-1
spec/services/ci/register_job_service_spec.rb
spec/services/ci/register_job_service_spec.rb
+2
-81
No files found.
app/services/ci/register_job_service.rb
View file @
f2a5493c
...
@@ -4,9 +4,6 @@ module Ci
...
@@ -4,9 +4,6 @@ module Ci
class
RegisterJobService
class
RegisterJobService
attr_reader
:runner
attr_reader
:runner
JOB_QUEUE_DURATION_SECONDS_BUCKETS
=
[
1
,
3
,
10
,
30
].
freeze
JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET
=
5
.
freeze
Result
=
Struct
.
new
(
:build
,
:valid?
)
Result
=
Struct
.
new
(
:build
,
:valid?
)
def
initialize
(
runner
)
def
initialize
(
runner
)
...
@@ -107,22 +104,10 @@ module Ci
...
@@ -107,22 +104,10 @@ module Ci
end
end
def
register_success
(
job
)
def
register_success
(
job
)
labels
=
{
shared_runner:
runner
.
shared?
,
job_queue_duration_seconds
.
observe
({
shared_runner:
@runner
.
shared?
},
Time
.
now
-
job
.
created_at
)
jobs_running_for_project:
jobs_running_for_project
(
job
)
}
job_queue_duration_seconds
.
observe
(
labels
,
Time
.
now
-
job
.
queued_at
)
attempt_counter
.
increment
attempt_counter
.
increment
end
end
def
jobs_running_for_project
(
job
)
return
'+Inf'
unless
runner
.
shared?
# excluding currently started job
running_jobs_count
=
job
.
project
.
builds
.
running
.
where
(
runner:
Ci
::
Runner
.
shared
)
.
limit
(
JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET
+
1
).
count
-
1
running_jobs_count
<
JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET
?
running_jobs_count
:
"
#{
JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET
}
+"
end
def
failed_attempt_counter
def
failed_attempt_counter
@failed_attempt_counter
||=
Gitlab
::
Metrics
.
counter
(
:job_register_attempts_failed_total
,
"Counts the times a runner tries to register a job"
)
@failed_attempt_counter
||=
Gitlab
::
Metrics
.
counter
(
:job_register_attempts_failed_total
,
"Counts the times a runner tries to register a job"
)
end
end
...
@@ -132,7 +117,7 @@ module Ci
...
@@ -132,7 +117,7 @@ module Ci
end
end
def
job_queue_duration_seconds
def
job_queue_duration_seconds
@job_queue_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:job_queue_duration_seconds
,
'Request handling execution time'
,
{},
JOB_QUEUE_DURATION_SECONDS_BUCKETS
)
@job_queue_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:job_queue_duration_seconds
,
'Request handling execution time'
)
end
end
end
end
end
end
changelogs/unreleased/improve-jobs-queuing-time-metric.yml
deleted
100644 → 0
View file @
174950b6
---
title
:
Partition job_queue_duration_seconds with jobs_running_for_project
merge_request
:
17730
author
:
type
:
changed
spec/factories/ci/builds.rb
View file @
f2a5493c
...
@@ -62,7 +62,6 @@ FactoryBot.define do
...
@@ -62,7 +62,6 @@ FactoryBot.define do
end
end
trait
:pending
do
trait
:pending
do
queued_at
'Di 29. Okt 09:50:59 CET 2013'
status
'pending'
status
'pending'
end
end
...
...
spec/services/ci/register_job_service_spec.rb
View file @
f2a5493c
...
@@ -370,89 +370,10 @@ module Ci
...
@@ -370,89 +370,10 @@ module Ci
it_behaves_like
'validation is not active'
it_behaves_like
'validation is not active'
end
end
end
end
end
describe
'#register_success'
do
let!
(
:current_time
)
{
Time
.
new
(
2018
,
4
,
5
,
14
,
0
,
0
)
}
let!
(
:attempt_counter
)
{
double
(
'Gitlab::Metrics::NullMetric'
)
}
let!
(
:job_queue_duration_seconds
)
{
double
(
'Gitlab::Metrics::NullMetric'
)
}
before
do
allow
(
Time
).
to
receive
(
:now
).
and_return
(
current_time
)
# Stub defaults for any metrics other than the ones we're testing
allow
(
Gitlab
::
Metrics
).
to
receive
(
:counter
)
.
with
(
any_args
)
.
and_return
(
Gitlab
::
Metrics
::
NullMetric
.
instance
)
allow
(
Gitlab
::
Metrics
).
to
receive
(
:histogram
)
.
with
(
any_args
)
.
and_return
(
Gitlab
::
Metrics
::
NullMetric
.
instance
)
# Stub tested metrics
allow
(
Gitlab
::
Metrics
).
to
receive
(
:counter
)
.
with
(
:job_register_attempts_total
,
anything
)
.
and_return
(
attempt_counter
)
allow
(
Gitlab
::
Metrics
).
to
receive
(
:histogram
)
.
with
(
:job_queue_duration_seconds
,
anything
,
anything
,
anything
)
.
and_return
(
job_queue_duration_seconds
)
project
.
update
(
shared_runners_enabled:
true
)
pending_job
.
update
(
created_at:
current_time
-
3600
,
queued_at:
current_time
-
1800
)
end
shared_examples
'metrics collector'
do
it
'increments attempt counter'
do
allow
(
job_queue_duration_seconds
).
to
receive
(
:observe
)
expect
(
attempt_counter
).
to
receive
(
:increment
)
execute
(
runner
)
end
it
'counts job queuing time histogram with expected labels'
do
allow
(
attempt_counter
).
to
receive
(
:increment
)
expect
(
job_queue_duration_seconds
).
to
receive
(
:observe
)
.
with
({
shared_runner:
expected_shared_runner
,
jobs_running_for_project:
expected_jobs_running_for_project_first_job
},
1800
)
execute
(
runner
)
end
context
'when project already has running jobs'
do
let!
(
:build2
)
{
create
(
:ci_build
,
:running
,
pipeline:
pipeline
,
runner:
shared_runner
)
}
let!
(
:build3
)
{
create
(
:ci_build
,
:running
,
pipeline:
pipeline
,
runner:
shared_runner
)
}
it
'counts job queuing time histogram with expected labels'
do
allow
(
attempt_counter
).
to
receive
(
:increment
)
expect
(
job_queue_duration_seconds
).
to
receive
(
:observe
)
.
with
({
shared_runner:
expected_shared_runner
,
jobs_running_for_project:
expected_jobs_running_for_project_third_job
},
1800
)
execute
(
runner
)
end
end
end
context
'when shared runner is used'
do
let
(
:runner
)
{
shared_runner
}
let
(
:expected_shared_runner
)
{
true
}
let
(
:expected_jobs_running_for_project_first_job
)
{
0
}
let
(
:expected_jobs_running_for_project_third_job
)
{
2
}
it_behaves_like
'metrics collector'
end
context
'when specific runner is used'
do
let
(
:runner
)
{
specific_runner
}
let
(
:expected_shared_runner
)
{
false
}
let
(
:expected_jobs_running_for_project_first_job
)
{
'+Inf'
}
let
(
:expected_jobs_running_for_project_third_job
)
{
'+Inf'
}
it_behaves_like
'metrics collector'
end
end
def
execute
(
runner
)
def
execute
(
runner
)
described_class
.
new
(
runner
).
execute
.
build
described_class
.
new
(
runner
).
execute
.
build
end
end
end
end
end
end
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