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
3268e377
Commit
3268e377
authored
Nov 18, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - started refactoring cycle analytics median stuff into stages
parent
e7fdb1aa
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
118 additions
and
59 deletions
+118
-59
app/models/cycle_analytics.rb
app/models/cycle_analytics.rb
+7
-40
lib/gitlab/cycle_analytics/base_event.rb
lib/gitlab/cycle_analytics/base_event.rb
+4
-4
lib/gitlab/cycle_analytics/base_stage.rb
lib/gitlab/cycle_analytics/base_stage.rb
+24
-0
lib/gitlab/cycle_analytics/code_event.rb
lib/gitlab/cycle_analytics/code_event.rb
+0
-1
lib/gitlab/cycle_analytics/code_stage.rb
lib/gitlab/cycle_analytics/code_stage.rb
+11
-0
lib/gitlab/cycle_analytics/events_query.rb
lib/gitlab/cycle_analytics/events_query.rb
+2
-7
lib/gitlab/cycle_analytics/issue_event.rb
lib/gitlab/cycle_analytics/issue_event.rb
+0
-1
lib/gitlab/cycle_analytics/issue_stage.rb
lib/gitlab/cycle_analytics/issue_stage.rb
+12
-0
lib/gitlab/cycle_analytics/metrics_fetcher.rb
lib/gitlab/cycle_analytics/metrics_fetcher.rb
+2
-1
lib/gitlab/cycle_analytics/plan_event.rb
lib/gitlab/cycle_analytics/plan_event.rb
+0
-1
lib/gitlab/cycle_analytics/plan_stage.rb
lib/gitlab/cycle_analytics/plan_stage.rb
+12
-0
lib/gitlab/cycle_analytics/production_event.rb
lib/gitlab/cycle_analytics/production_event.rb
+0
-1
lib/gitlab/cycle_analytics/production_stage.rb
lib/gitlab/cycle_analytics/production_stage.rb
+11
-0
lib/gitlab/cycle_analytics/review_event.rb
lib/gitlab/cycle_analytics/review_event.rb
+0
-1
lib/gitlab/cycle_analytics/review_stage.rb
lib/gitlab/cycle_analytics/review_stage.rb
+11
-0
lib/gitlab/cycle_analytics/staging_event.rb
lib/gitlab/cycle_analytics/staging_event.rb
+0
-1
lib/gitlab/cycle_analytics/staging_stage.rb
lib/gitlab/cycle_analytics/staging_stage.rb
+11
-0
lib/gitlab/cycle_analytics/test_event.rb
lib/gitlab/cycle_analytics/test_event.rb
+0
-1
lib/gitlab/cycle_analytics/test_stage.rb
lib/gitlab/cycle_analytics/test_stage.rb
+11
-0
No files found.
app/models/cycle_analytics.rb
View file @
3268e377
class
CycleAnalytics
STAGES
=
%i[issue plan code test review staging production]
.
freeze
def
initialize
(
project
,
current_user
,
from
:)
def
initialize
(
project
,
from
:)
@project
=
project
@current_user
=
current_user
@from
=
from
@fetcher
=
Gitlab
::
CycleAnalytics
::
MetricsFetcher
.
new
(
project:
project
,
from:
from
,
branch:
nil
)
@options
=
options
end
def
summary
@summary
||=
Summary
.
new
(
@project
,
@current_user
,
from:
@from
)
@summary
||=
Summary
.
new
(
@project
,
from:
@options
[
:from
]
)
end
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
method_sym
)
def
permissions
(
user
:)
Gitlab
::
CycleAnalytics
::
Permissions
.
get
(
user:
user
,
project:
@project
)
end
...
...
@@ -23,40 +23,7 @@ class CycleAnalytics
Issue
::
Metrics
.
arel_table
[
:first_added_to_board_at
]])
end
def
plan
@fetcher
.
calculate_metric
(
:plan
,
[
Issue
::
Metrics
.
arel_table
[
:first_associated_with_milestone_at
],
Issue
::
Metrics
.
arel_table
[
:first_added_to_board_at
]],
Issue
::
Metrics
.
arel_table
[
:first_mentioned_in_commit_at
])
end
def
code
@fetcher
.
calculate_metric
(
:code
,
Issue
::
Metrics
.
arel_table
[
:first_mentioned_in_commit_at
],
MergeRequest
.
arel_table
[
:created_at
])
end
def
test
@fetcher
.
calculate_metric
(
:test
,
MergeRequest
::
Metrics
.
arel_table
[
:latest_build_started_at
],
MergeRequest
::
Metrics
.
arel_table
[
:latest_build_finished_at
])
end
def
review
@fetcher
.
calculate_metric
(
:review
,
MergeRequest
.
arel_table
[
:created_at
],
MergeRequest
::
Metrics
.
arel_table
[
:merged_at
])
end
def
staging
@fetcher
.
calculate_metric
(
:staging
,
MergeRequest
::
Metrics
.
arel_table
[
:merged_at
],
MergeRequest
::
Metrics
.
arel_table
[
:first_deployed_to_production_at
])
end
def
production
@fetcher
.
calculate_metric
(
:production
,
Issue
.
arel_table
[
:created_at
],
MergeRequest
::
Metrics
.
arel_table
[
:first_deployed_to_production_at
])
def
classify_stage
(
method_sym
)
"Gitlab::CycleAnalytics::
#{
method_sym
.
to_s
.
capitalize
}
Stage"
.
constantize
end
end
lib/gitlab/cycle_analytics/base_event.rb
View file @
3268e377
...
...
@@ -5,10 +5,10 @@ module Gitlab
attr_reader
:stage
,
:start_time_attrs
,
:end_time_attrs
,
:projections
,
:query
def
initialize
(
project
:,
options
:)
@query
=
EventsQuery
.
new
(
project:
project
,
options:
options
)
@project
=
project
@
options
=
options
def
initialize
(
fetcher
:,
stage
:)
@query
=
EventsQuery
.
new
(
fetcher:
fetcher
)
@project
=
fetcher
.
project
@
stage
=
stage
end
def
fetch
...
...
lib/gitlab/cycle_analytics/base_stage.rb
0 → 100644
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
BaseStage
def
initialize
(
project
:,
options
:,
stage:
stage
)
@project
=
project
@options
=
options
@fetcher
=
Gitlab
::
CycleAnalytics
::
MetricsFetcher
.
new
(
project:
project
,
from:
options
[
:from
],
branch:
options
[
:branch
])
@stage
=
stage
end
def
events
event_class
.
new
(
fetcher:
@fetcher
,
stage:
@stage
).
fetch
end
private
def
event_class
"Gitlab::CycleAnalytics::
#{
@stage
.
to_s
.
capitalize
}
Event"
.
constantize
end
end
end
end
lib/gitlab/cycle_analytics/code_event.rb
View file @
3268e377
...
...
@@ -4,7 +4,6 @@ module Gitlab
include
MergeRequestAllowed
def
initialize
(
*
args
)
@stage
=
:code
@start_time_attrs
=
issue_metrics_table
[
:first_mentioned_in_commit_at
]
@end_time_attrs
=
mr_table
[
:created_at
]
@projections
=
[
mr_table
[
:title
],
...
...
lib/gitlab/cycle_analytics/code_stage.rb
0 → 100644
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
CodeStage
<
BaseStage
def
median
@fetcher
.
calculate_metric
(
:code
,
Issue
::
Metrics
.
arel_table
[
:first_mentioned_in_commit_at
],
MergeRequest
.
arel_table
[
:created_at
])
end
end
end
end
lib/gitlab/cycle_analytics/events_query.rb
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
EventsQuery
attr_reader
:project
def
initialize
(
project
:,
options:
{})
@project
=
project
@from
=
options
[
:from
]
@branch
=
options
[
:branch
]
@fetcher
=
Gitlab
::
CycleAnalytics
::
MetricsFetcher
.
new
(
project:
project
,
from:
@from
,
branch:
@branch
)
def
initialize
(
fetcher
:)
@fetcher
=
fetcher
end
def
execute
(
stage_class
)
...
...
lib/gitlab/cycle_analytics/issue_event.rb
View file @
3268e377
...
...
@@ -4,7 +4,6 @@ module Gitlab
include
IssueAllowed
def
initialize
(
*
args
)
@stage
=
: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
]]
...
...
lib/gitlab/cycle_analytics/issue_stage.rb
0 → 100644
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
IssueStage
<
BaseStage
def
median
@fetcher
.
calculate_metric
(
:issue
,
Issue
.
arel_table
[
:created_at
],
[
Issue
::
Metrics
.
arel_table
[
:first_associated_with_milestone_at
],
Issue
::
Metrics
.
arel_table
[
:first_added_to_board_at
]])
end
end
end
end
lib/gitlab/cycle_analytics/metrics_fetcher.rb
View file @
3268e377
...
...
@@ -5,10 +5,11 @@ module Gitlab
include
Gitlab
::
Database
::
DateTime
include
MetricsTables
attr_reader
:project
DEPLOYMENT_METRIC_STAGES
=
%i[production staging]
def
initialize
(
project
:,
from
:,
branch
:)
@project
=
project
@project
=
project
@from
=
from
@branch
=
branch
...
...
lib/gitlab/cycle_analytics/plan_event.rb
View file @
3268e377
...
...
@@ -2,7 +2,6 @@ module Gitlab
module
CycleAnalytics
class
PlanEvent
<
BaseEvent
def
initialize
(
*
args
)
@stage
=
: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
]]
...
...
lib/gitlab/cycle_analytics/plan_stage.rb
0 → 100644
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
PlanStage
<
BaseStage
def
median
@fetcher
.
calculate_metric
(
:plan
,
[
Issue
::
Metrics
.
arel_table
[
:first_associated_with_milestone_at
],
Issue
::
Metrics
.
arel_table
[
:first_added_to_board_at
]],
Issue
::
Metrics
.
arel_table
[
:first_mentioned_in_commit_at
])
end
end
end
end
lib/gitlab/cycle_analytics/production_event.rb
View file @
3268e377
...
...
@@ -4,7 +4,6 @@ module Gitlab
include
IssueAllowed
def
initialize
(
*
args
)
@stage
=
:production
@start_time_attrs
=
issue_table
[
:created_at
]
@end_time_attrs
=
mr_metrics_table
[
:first_deployed_to_production_at
]
@projections
=
[
issue_table
[
:title
],
...
...
lib/gitlab/cycle_analytics/production_stage.rb
0 → 100644
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
ProductionStage
<
BaseStage
def
median
@fetcher
.
calculate_metric
(
:production
,
Issue
.
arel_table
[
:created_at
],
MergeRequest
::
Metrics
.
arel_table
[
:first_deployed_to_production_at
])
end
end
end
end
lib/gitlab/cycle_analytics/review_event.rb
View file @
3268e377
...
...
@@ -4,7 +4,6 @@ module Gitlab
include
MergeRequestAllowed
def
initialize
(
*
args
)
@stage
=
:review
@start_time_attrs
=
mr_table
[
:created_at
]
@end_time_attrs
=
mr_metrics_table
[
:merged_at
]
@projections
=
[
mr_table
[
:title
],
...
...
lib/gitlab/cycle_analytics/review_stage.rb
0 → 100644
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
ReviewStage
<
BaseStage
def
median
@fetcher
.
calculate_metric
(
:review
,
MergeRequest
.
arel_table
[
:created_at
],
MergeRequest
::
Metrics
.
arel_table
[
:merged_at
])
end
end
end
end
lib/gitlab/cycle_analytics/staging_event.rb
View file @
3268e377
...
...
@@ -2,7 +2,6 @@ module Gitlab
module
CycleAnalytics
class
StagingEvent
<
BaseEvent
def
initialize
(
*
args
)
@stage
=
:staging
@start_time_attrs
=
mr_metrics_table
[
:merged_at
]
@end_time_attrs
=
mr_metrics_table
[
:first_deployed_to_production_at
]
@projections
=
[
build_table
[
:id
]]
...
...
lib/gitlab/cycle_analytics/staging_stage.rb
0 → 100644
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
StagingStage
<
BaseStage
def
median
@fetcher
.
calculate_metric
(
:staging
,
MergeRequest
::
Metrics
.
arel_table
[
:merged_at
],
MergeRequest
::
Metrics
.
arel_table
[
:first_deployed_to_production_at
])
end
end
end
end
lib/gitlab/cycle_analytics/test_event.rb
View file @
3268e377
...
...
@@ -4,7 +4,6 @@ module Gitlab
def
initialize
(
*
args
)
super
(
*
args
)
@stage
=
:test
@start_time_attrs
=
mr_metrics_table
[
:latest_build_started_at
]
@end_time_attrs
=
mr_metrics_table
[
:latest_build_finished_at
]
end
...
...
lib/gitlab/cycle_analytics/test_stage.rb
0 → 100644
View file @
3268e377
module
Gitlab
module
CycleAnalytics
class
TestStage
<
BaseStage
def
median
@fetcher
.
calculate_metric
(
:test
,
MergeRequest
::
Metrics
.
arel_table
[
:latest_build_started_at
],
MergeRequest
::
Metrics
.
arel_table
[
:latest_build_finished_at
])
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