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
cf2dcf04
Commit
cf2dcf04
authored
Nov 16, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor all query config stuff into separate classes and added specs
parent
cbc9f0cd
Changes
25
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
296 additions
and
190 deletions
+296
-190
app/controllers/projects/cycle_analytics/events_controller.rb
...controllers/projects/cycle_analytics/events_controller.rb
+62
-62
app/serializers/entity_date_helper.rb
app/serializers/entity_date_helper.rb
+1
-1
lib/gitlab/cycle_analytics/base_config.rb
lib/gitlab/cycle_analytics/base_config.rb
+17
-0
lib/gitlab/cycle_analytics/code_config.rb
lib/gitlab/cycle_analytics/code_config.rb
+18
-0
lib/gitlab/cycle_analytics/events_fetcher.rb
lib/gitlab/cycle_analytics/events_fetcher.rb
+2
-14
lib/gitlab/cycle_analytics/events_query.rb
lib/gitlab/cycle_analytics/events_query.rb
+7
-8
lib/gitlab/cycle_analytics/issue_config.rb
lib/gitlab/cycle_analytics/issue_config.rb
+16
-0
lib/gitlab/cycle_analytics/plan_config.rb
lib/gitlab/cycle_analytics/plan_config.rb
+17
-0
lib/gitlab/cycle_analytics/production_config.rb
lib/gitlab/cycle_analytics/production_config.rb
+15
-0
lib/gitlab/cycle_analytics/query_config.rb
lib/gitlab/cycle_analytics/query_config.rb
+0
-99
lib/gitlab/cycle_analytics/review_config.rb
lib/gitlab/cycle_analytics/review_config.rb
+16
-0
lib/gitlab/cycle_analytics/staging_config.rb
lib/gitlab/cycle_analytics/staging_config.rb
+14
-0
lib/gitlab/cycle_analytics/test_config.rb
lib/gitlab/cycle_analytics/test_config.rb
+14
-0
spec/lib/gitlab/cycle_analytics/code_config_spec.rb
spec/lib/gitlab/cycle_analytics/code_config_spec.rb
+10
-0
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+5
-1
spec/lib/gitlab/cycle_analytics/issue_config_spec.rb
spec/lib/gitlab/cycle_analytics/issue_config_spec.rb
+10
-0
spec/lib/gitlab/cycle_analytics/plan_config_spec.rb
spec/lib/gitlab/cycle_analytics/plan_config_spec.rb
+10
-0
spec/lib/gitlab/cycle_analytics/production_config_spec.rb
spec/lib/gitlab/cycle_analytics/production_config_spec.rb
+10
-0
spec/lib/gitlab/cycle_analytics/review_config_spec.rb
spec/lib/gitlab/cycle_analytics/review_config_spec.rb
+10
-0
spec/lib/gitlab/cycle_analytics/shared_config_spec.rb
spec/lib/gitlab/cycle_analytics/shared_config_spec.rb
+15
-0
spec/lib/gitlab/cycle_analytics/staging_config_spec.rb
spec/lib/gitlab/cycle_analytics/staging_config_spec.rb
+10
-0
spec/lib/gitlab/cycle_analytics/test_config_spec.rb
spec/lib/gitlab/cycle_analytics/test_config_spec.rb
+10
-0
spec/requests/projects/cycle_analytics_events_spec.rb
spec/requests/projects/cycle_analytics_events_spec.rb
+3
-1
spec/serializers/analytics_generic_entity_spec.rb
spec/serializers/analytics_generic_entity_spec.rb
+2
-2
spec/serializers/analytics_generic_serializer_spec.rb
spec/serializers/analytics_generic_serializer_spec.rb
+2
-2
No files found.
app/controllers/projects/cycle_analytics/events_controller.rb
View file @
cf2dcf04
module
Projects
module
CycleAnalytics
class
EventsController
<
Projects
::
ApplicationController
class
EventsController
<
Projects
::
ApplicationController
include
CycleAnalyticsParams
before_action
:authorize_read_cycle_analytics!
...
...
@@ -62,6 +62,6 @@ class EventsController < Projects::ApplicationController
def
authorize_builds!
return
access_denied!
unless
current_user
.
can?
(
:read_build
,
project
)
end
end
end
end
end
app/serializers/entity_date_helper.rb
View file @
cf2dcf04
lib/gitlab/cycle_analytics/base_config.rb
0 → 100644
View file @
cf2dcf04
module
Gitlab
module
CycleAnalytics
class
BaseConfig
extend
MetricsFetcher
class
<<
self
attr_reader
:start_time_attrs
,
:end_time_attrs
,
:projections
end
def
self
.
order
@order
||
@start_time_attrs
end
def
self
.
query
(
base_query
);
end
end
end
end
lib/gitlab/cycle_analytics/code_config.rb
0 → 100644
View file @
cf2dcf04
module
Gitlab
module
CycleAnalytics
class
CodeConfig
<
BaseConfig
@start_time_attrs
=
issue_metrics_table
[
:first_mentioned_in_commit_at
]
@end_time_attrs
=
mr_table
[
:created_at
]
@projections
=
[
mr_table
[
:title
],
mr_table
[
:iid
],
mr_table
[
:id
],
mr_table
[
:created_at
],
mr_table
[
:state
],
mr_table
[
:author_id
]]
@order
=
mr_table
[
:created_at
]
end
end
end
lib/gitlab/cycle_analytics/events_fetcher.rb
View file @
cf2dcf04
...
...
@@ -8,22 +8,10 @@ module Gitlab
end
def
fetch
(
stage
:)
custom_query
=
"
#{
stage
}
_custom_query"
.
to_sym
@query
.
execute
(
stage
)
do
|
base_query
|
public_send
(
custom_query
,
base_query
)
if
self
.
respond_to?
(
custom_query
)
end
end
def
plan_custom_query
(
base_query
)
base_query
.
join
(
mr_diff_table
).
on
(
mr_diff_table
[
:merge_request_id
].
eq
(
mr_table
[
:id
]))
@query
.
execute
(
stage
)
do
|
stage_class
,
base_query
|
stage_class
.
query
(
base_query
)
end
def
test_custom_query
(
base_query
)
base_query
.
join
(
build_table
).
on
(
mr_metrics_table
[
:pipeline_id
].
eq
(
build_table
[
:commit_id
]))
end
alias_method
:staging_custom_query
,
:test_custom_query
end
end
end
lib/gitlab/cycle_analytics/events_query.rb
View file @
cf2dcf04
...
...
@@ -11,7 +11,6 @@ module Gitlab
def
execute
(
stage
,
&
block
)
@stage
=
stage
@config
=
QueryConfig
.
get
(
stage
)
query
=
build_query
(
&
block
)
ActiveRecord
::
Base
.
connection
.
exec_query
(
query
.
to_sql
)
...
...
@@ -21,15 +20,11 @@ module Gitlab
def
build_query
base_query
=
base_query_for
(
@stage
)
diff_fn
=
subtract_datetimes_diff
(
@config
[
:base_query
],
@config
[
:start_time_attrs
],
@config
[
:end_time_attrs
]
)
diff_fn
=
subtract_datetimes_diff
(
base_query
,
stage_class
.
start_time_attrs
,
stage_class
.
end_time_attrs
)
yield
base_query
if
block_given?
yield
(
stage_class
,
base_query
)
if
block_given?
base_query
.
project
(
extract_epoch
(
diff_fn
).
as
(
'total_time'
),
*
@config
[
:projections
]).
order
(
order
.
desc
)
end
def
order
@config
[
:order
]
||
@config
[
:start_time_attrs
]
base_query
.
project
(
extract_epoch
(
diff_fn
).
as
(
'total_time'
),
*
stage_class
.
projections
).
order
(
stage_class
.
order
.
desc
)
end
def
extract_epoch
(
arel_attribute
)
...
...
@@ -37,6 +32,10 @@ module Gitlab
Arel
.
sql
(
%Q{EXTRACT(EPOCH FROM (
#{
arel_attribute
.
to_sql
}
))}
)
end
def
stage_class
@stage_class
||=
"Gitlab::CycleAnalytics::
#{
@stage
.
to_s
.
camelize
}
Config"
.
constantize
end
end
end
end
lib/gitlab/cycle_analytics/issue_config.rb
0 → 100644
View file @
cf2dcf04
module
Gitlab
module
CycleAnalytics
class
IssueConfig
<
BaseConfig
@start_time_attrs
=
issue_table
[
:created_at
]
@end_time_attrs
=
[
issue_metrics_table
[
:first_associated_with_milestone_at
],
issue_metrics_table
[
:first_added_to_board_at
]]
@projections
=
[
issue_table
[
:title
],
issue_table
[
:iid
],
issue_table
[
:id
],
issue_table
[
:created_at
],
issue_table
[
:author_id
]]
end
end
end
lib/gitlab/cycle_analytics/plan_config.rb
0 → 100644
View file @
cf2dcf04
module
Gitlab
module
CycleAnalytics
class
PlanConfig
<
BaseConfig
@start_time_attrs
=
issue_metrics_table
[
:first_associated_with_milestone_at
]
@end_time_attrs
=
[
issue_metrics_table
[
:first_added_to_board_at
],
issue_metrics_table
[
:first_mentioned_in_commit_at
]]
@projections
=
[
mr_diff_table
[
:st_commits
].
as
(
'commits'
),
issue_metrics_table
[
:first_mentioned_in_commit_at
]]
def
self
.
query
(
base_query
)
base_query
.
join
(
mr_diff_table
).
on
(
mr_diff_table
[
:merge_request_id
].
eq
(
mr_table
[
:id
]))
end
end
end
end
lib/gitlab/cycle_analytics/production_config.rb
0 → 100644
View file @
cf2dcf04
module
Gitlab
module
CycleAnalytics
class
ProductionConfig
<
BaseConfig
@start_time_attrs
=
issue_table
[
:created_at
]
@end_time_attrs
=
mr_metrics_table
[
:first_deployed_to_production_at
]
@projections
=
[
issue_table
[
:title
],
issue_table
[
:iid
],
issue_table
[
:id
],
issue_table
[
:created_at
],
issue_table
[
:author_id
]]
end
end
end
lib/gitlab/cycle_analytics/query_config.rb
deleted
100644 → 0
View file @
cbc9f0cd
module
Gitlab
module
CycleAnalytics
class
QueryConfig
include
MetricsFetcher
def
self
.
get
(
*
args
)
new
(
*
args
).
get
end
def
initialize
(
stage
)
@stage
=
stage
end
def
get
public_send
(
@stage
).
freeze
if
self
.
respond_to?
(
@stage
)
end
def
issue
{
start_time_attrs:
issue_table
[
:created_at
],
end_time_attrs:
[
issue_metrics_table
[
:first_associated_with_milestone_at
],
issue_metrics_table
[
:first_added_to_board_at
]],
projections:
[
issue_table
[
:title
],
issue_table
[
:iid
],
issue_table
[
:id
],
issue_table
[
:created_at
],
issue_table
[
:author_id
]]
}
end
def
plan
{
start_time_attrs:
issue_metrics_table
[
:first_associated_with_milestone_at
],
end_time_attrs:
[
issue_metrics_table
[
:first_added_to_board_at
],
issue_metrics_table
[
:first_mentioned_in_commit_at
]],
projections:
[
mr_diff_table
[
:st_commits
].
as
(
'commits'
),
issue_metrics_table
[
:first_mentioned_in_commit_at
]]
}
end
def
code
{
start_time_attrs:
issue_metrics_table
[
:first_mentioned_in_commit_at
],
end_time_attrs:
mr_table
[
:created_at
],
projections:
[
mr_table
[
:title
],
mr_table
[
:iid
],
mr_table
[
:id
],
mr_table
[
:created_at
],
mr_table
[
:state
],
mr_table
[
:author_id
]],
order:
mr_table
[
:created_at
]
}
end
def
test
{
start_time_attrs:
mr_metrics_table
[
:latest_build_started_at
],
end_time_attrs:
mr_metrics_table
[
:latest_build_finished_at
],
projections:
[
build_table
[
:id
]],
order:
build_table
[
:created_at
]
}
end
def
review
{
start_time_attrs:
mr_table
[
:created_at
],
end_time_attrs:
mr_metrics_table
[
:merged_at
],
projections:
[
mr_table
[
:title
],
mr_table
[
:iid
],
mr_table
[
:id
],
mr_table
[
:created_at
],
mr_table
[
:state
],
mr_table
[
:author_id
]]
}
end
def
staging
{
start_time_attrs:
mr_metrics_table
[
:merged_at
],
end_time_attrs:
mr_metrics_table
[
:first_deployed_to_production_at
],
projections:
[
build_table
[
:id
]],
order:
build_table
[
:created_at
]
}
end
def
production
{
start_time_attrs:
issue_table
[
:created_at
],
end_time_attrs:
mr_metrics_table
[
:first_deployed_to_production_at
],
projections:
[
issue_table
[
:title
],
issue_table
[
:iid
],
issue_table
[
:id
],
issue_table
[
:created_at
],
issue_table
[
:author_id
]]
}
end
end
end
end
lib/gitlab/cycle_analytics/review_config.rb
0 → 100644
View file @
cf2dcf04
module
Gitlab
module
CycleAnalytics
class
ReviewConfig
<
BaseConfig
@start_time_attrs
=
mr_table
[
:created_at
]
@end_time_attrs
=
mr_metrics_table
[
:merged_at
]
@projections
=
[
mr_table
[
:title
],
mr_table
[
:iid
],
mr_table
[
:id
],
mr_table
[
:created_at
],
mr_table
[
:state
],
mr_table
[
:author_id
]]
end
end
end
lib/gitlab/cycle_analytics/staging_config.rb
0 → 100644
View file @
cf2dcf04
module
Gitlab
module
CycleAnalytics
class
StagingConfig
<
BaseConfig
@start_time_attrs
=
mr_metrics_table
[
:merged_at
]
@end_time_attrs
=
mr_metrics_table
[
:first_deployed_to_production_at
]
@projections
=
[
build_table
[
:id
]]
@order
=
build_table
[
:created_at
]
def
self
.
query
(
base_query
)
base_query
.
join
(
build_table
).
on
(
mr_metrics_table
[
:pipeline_id
].
eq
(
build_table
[
:commit_id
]))
end
end
end
end
lib/gitlab/cycle_analytics/test_config.rb
0 → 100644
View file @
cf2dcf04
module
Gitlab
module
CycleAnalytics
class
TestConfig
<
BaseConfig
@start_time_attrs
=
mr_metrics_table
[
:latest_build_started_at
]
@end_time_attrs
=
mr_metrics_table
[
:latest_build_finished_at
]
@projections
=
[
build_table
[
:id
]]
@order
=
build_table
[
:created_at
]
def
self
.
query
(
base_query
)
base_query
.
join
(
build_table
).
on
(
mr_metrics_table
[
:pipeline_id
].
eq
(
build_table
[
:commit_id
]))
end
end
end
end
spec/lib/gitlab/cycle_analytics/code_config_spec.rb
0 → 100644
View file @
cf2dcf04
require
'spec_helper'
require
'lib/gitlab/cycle_analytics/shared_config_spec'
describe
Gitlab
::
CycleAnalytics
::
CodeConfig
do
it_behaves_like
'default query config'
it
'has the default order'
do
expect
(
described_class
.
order
).
not_to
eq
(
described_class
.
start_time_attrs
)
end
end
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
cf2dcf04
...
...
@@ -9,6 +9,8 @@ describe Gitlab::CycleAnalytics::Events do
subject
{
described_class
.
new
(
project:
project
,
options:
{
from:
from_date
})
}
before
do
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
context
])
setup
(
context
)
end
...
...
@@ -317,6 +319,8 @@ describe Gitlab::CycleAnalytics::Events do
def
setup
(
context
)
milestone
=
create
(
:milestone
,
project:
project
)
context
.
update
(
milestone:
milestone
)
create_merge_request_closing_issue
(
context
)
mr
=
create_merge_request_closing_issue
(
context
)
ProcessCommitWorker
.
new
.
perform
(
project
.
id
,
user
.
id
,
mr
.
commits
.
last
.
sha
)
end
end
spec/lib/gitlab/cycle_analytics/issue_config_spec.rb
0 → 100644
View file @
cf2dcf04
require
'spec_helper'
require
'lib/gitlab/cycle_analytics/shared_config_spec'
describe
Gitlab
::
CycleAnalytics
::
IssueConfig
do
it_behaves_like
'default query config'
it
'has the default order'
do
expect
(
described_class
.
order
).
to
eq
(
described_class
.
start_time_attrs
)
end
end
spec/lib/gitlab/cycle_analytics/plan_config_spec.rb
0 → 100644
View file @
cf2dcf04
require
'spec_helper'
require
'lib/gitlab/cycle_analytics/shared_config_spec'
describe
Gitlab
::
CycleAnalytics
::
PlanConfig
do
it_behaves_like
'default query config'
it
'has the default order'
do
expect
(
described_class
.
order
).
to
eq
(
described_class
.
start_time_attrs
)
end
end
spec/lib/gitlab/cycle_analytics/production_config_spec.rb
0 → 100644
View file @
cf2dcf04
require
'spec_helper'
require
'lib/gitlab/cycle_analytics/shared_config_spec'
describe
Gitlab
::
CycleAnalytics
::
ProductionConfig
do
it_behaves_like
'default query config'
it
'has the default order'
do
expect
(
described_class
.
order
).
to
eq
(
described_class
.
start_time_attrs
)
end
end
spec/lib/gitlab/cycle_analytics/review_config_spec.rb
0 → 100644
View file @
cf2dcf04
require
'spec_helper'
require
'lib/gitlab/cycle_analytics/shared_config_spec'
describe
Gitlab
::
CycleAnalytics
::
ReviewConfig
do
it_behaves_like
'default query config'
it
'has the default order'
do
expect
(
described_class
.
order
).
to
eq
(
described_class
.
start_time_attrs
)
end
end
spec/lib/gitlab/cycle_analytics/shared_config_spec.rb
0 → 100644
View file @
cf2dcf04
require
'spec_helper'
shared_examples
'default query config'
do
it
'has the start attributes'
do
expect
(
described_class
.
start_time_attrs
).
not_to
be_nil
end
it
'has the end attributes'
do
expect
(
described_class
.
end_time_attrs
).
not_to
be_nil
end
it
'has the projection attributes'
do
expect
(
described_class
.
projections
).
not_to
be_nil
end
end
spec/lib/gitlab/cycle_analytics/staging_config_spec.rb
0 → 100644
View file @
cf2dcf04
require
'spec_helper'
require
'lib/gitlab/cycle_analytics/shared_config_spec'
describe
Gitlab
::
CycleAnalytics
::
StagingConfig
do
it_behaves_like
'default query config'
it
'has the default order'
do
expect
(
described_class
.
order
).
not_to
eq
(
described_class
.
start_time_attrs
)
end
end
spec/lib/gitlab/cycle_analytics/test_config_spec.rb
0 → 100644
View file @
cf2dcf04
require
'spec_helper'
require
'lib/gitlab/cycle_analytics/shared_config_spec'
describe
Gitlab
::
CycleAnalytics
::
TestConfig
do
it_behaves_like
'default query config'
it
'has the default order'
do
expect
(
described_class
.
order
).
not_to
eq
(
described_class
.
start_time_attrs
)
end
end
spec/requests/projects/cycle_analytics_events_spec.rb
View file @
cf2dcf04
...
...
@@ -12,6 +12,8 @@ describe 'cycle analytics events' do
deploy_master
login_as
(
user
)
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
context
])
end
it
'lists the issue events'
do
...
...
@@ -143,6 +145,6 @@ describe 'cycle analytics events' do
merge_merge_requests_closing_issue
(
issue
)
Issue
::
Metrics
.
update_all
(
first_mentioned_in_commit_at:
mr
.
commits
.
last
.
committed_date
)
ProcessCommitWorker
.
new
.
perform
(
project
.
id
,
user
.
id
,
mr
.
commits
.
last
.
sha
)
end
end
spec/serializers/analytics_generic_entity_spec.rb
View file @
cf2dcf04
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
AnalyticsGenericEntity
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:entity_hash
)
{
let
(
:entity_hash
)
do
{
total_time:
"172802.724419"
,
title:
"Eos voluptatem inventore in sed."
,
...
...
@@ -11,7 +11,7 @@ describe AnalyticsGenericEntity do
created_at:
"2016-11-12 15:04:02.948604"
,
author:
user
,
}
}
end
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:request
)
{
EntityRequest
.
new
(
project:
project
,
entity: :merge_request
)
}
...
...
spec/serializers/analytics_generic_serializer_spec.rb
View file @
cf2dcf04
...
...
@@ -10,7 +10,7 @@ describe AnalyticsGenericSerializer do
let
(
:user
)
{
create
(
:user
)
}
let
(
:json
)
{
serializer
.
as_json
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:resource
)
{
let
(
:resource
)
do
{
total_time:
"172802.724419"
,
title:
"Eos voluptatem inventore in sed."
,
...
...
@@ -19,7 +19,7 @@ describe AnalyticsGenericSerializer do
created_at:
"2016-11-12 15:04:02.948604"
,
author:
user
,
}
}
end
context
'when there is a single object provided'
do
it
'it generates payload for single object'
do
...
...
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