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
3f7e1bba
Commit
3f7e1bba
authored
Nov 24, 2021
by
Adam Hegyi
Committed by
Alper Akgun
Nov 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the aggregated tables for duration chart
parent
af4001a4
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
109 additions
and
3 deletions
+109
-3
ee/lib/ee/gitlab/analytics/cycle_analytics/aggregated/data_collector.rb
...ab/analytics/cycle_analytics/aggregated/data_collector.rb
+19
-0
ee/lib/ee/gitlab/analytics/cycle_analytics/data_collector.rb
ee/lib/ee/gitlab/analytics/cycle_analytics/data_collector.rb
+6
-2
ee/lib/gitlab/analytics/cycle_analytics/aggregated/data_for_duration_chart.rb
...ics/cycle_analytics/aggregated/data_for_duration_chart.rb
+35
-0
ee/spec/lib/gitlab/analytics/cycle_analytics/aggregated/data_for_duration_chart_spec.rb
...ycle_analytics/aggregated/data_for_duration_chart_spec.rb
+32
-0
ee/spec/lib/gitlab/analytics/cycle_analytics/data_collector_spec.rb
...b/gitlab/analytics/cycle_analytics/data_collector_spec.rb
+9
-0
ee/spec/support/shared_examples/controllers/analytics/cycle_analytics/shared_stage_shared_examples.rb
...analytics/cycle_analytics/shared_stage_shared_examples.rb
+6
-1
lib/gitlab/analytics/cycle_analytics/aggregated/data_collector.rb
...ab/analytics/cycle_analytics/aggregated/data_collector.rb
+2
-0
No files found.
ee/lib/ee/gitlab/analytics/cycle_analytics/aggregated/data_collector.rb
0 → 100644
View file @
3f7e1bba
# frozen_string_literal: true
module
EE
module
Gitlab
module
Analytics
module
CycleAnalytics
module
Aggregated
module
DataCollector
def
duration_chart_average_data
::
Gitlab
::
Analytics
::
CycleAnalytics
::
Aggregated
::
DataForDurationChart
.
new
(
stage:
stage
,
params:
params
,
query:
query
)
.
average_by_day
end
end
end
end
end
end
end
ee/lib/ee/gitlab/analytics/cycle_analytics/data_collector.rb
View file @
3f7e1bba
...
@@ -6,10 +6,14 @@ module EE
...
@@ -6,10 +6,14 @@ module EE
module
CycleAnalytics
module
CycleAnalytics
module
DataCollector
module
DataCollector
def
duration_chart_average_data
def
duration_chart_average_data
strong_memoize
(
:duration_chart_average_data
)
do
strong_memoize
(
:records_fetcher
)
do
if
use_aggregated_data_collector?
aggregated_data_collector
.
duration_chart_average_data
else
duration_chart
.
average_by_day
duration_chart
.
average_by_day
end
end
end
end
end
private
private
...
...
ee/lib/gitlab/analytics/cycle_analytics/aggregated/data_for_duration_chart.rb
0 → 100644
View file @
3f7e1bba
# frozen_string_literal: true
module
Gitlab
module
Analytics
module
CycleAnalytics
module
Aggregated
class
DataForDurationChart
include
StageQueryHelpers
def
initialize
(
stage
:,
params
:,
query
:)
@stage
=
stage
@params
=
params
@query
=
query
end
# rubocop: disable CodeReuse/ActiveRecord
def
average_by_day
@query
.
group
(
date_expression
)
.
select
(
date_expression
.
as
(
'date'
),
duration
.
average
.
as
(
'average_duration_in_seconds'
))
end
# rubocop: enable CodeReuse/ActiveRecord
private
attr_reader
:stage
,
:query
,
:params
def
date_expression
Arel
::
Nodes
::
NamedFunction
.
new
(
'DATE'
,
[
query
.
model
.
arel_table
[
:end_event_timestamp
]])
end
end
end
end
end
end
ee/spec/lib/gitlab/analytics/cycle_analytics/aggregated/data_for_duration_chart_spec.rb
0 → 100644
View file @
3f7e1bba
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Analytics
::
CycleAnalytics
::
Aggregated
::
DataForDurationChart
do
let_it_be
(
:stage
)
{
create
(
:cycle_analytics_group_stage
,
start_event_identifier: :issue_created
,
end_event_identifier: :issue_closed
)
}
let_it_be
(
:project
)
{
create
(
:project
,
group:
stage
.
group
)
}
let_it_be
(
:issue_1
)
{
create
(
:issue
,
project:
project
)
}
let_it_be
(
:issue_2
)
{
create
(
:issue
,
project:
project
)
}
let_it_be
(
:issue_3
)
{
create
(
:issue
,
project:
project
)
}
subject
(
:result
)
do
described_class
.
new
(
stage:
stage
,
params:
{},
query:
Analytics
::
CycleAnalytics
::
IssueStageEvent
.
all
)
.
average_by_day
end
it
'calculates the daily average stage duration'
do
end_timestamp_1
=
Time
.
zone
.
local
(
2020
,
5
,
6
,
12
,
0
)
end_timestamp_2
=
Time
.
zone
.
local
(
2020
,
5
,
15
,
10
,
0
)
create
(
:cycle_analytics_issue_stage_event
,
issue_id:
issue_1
.
id
,
start_event_timestamp:
end_timestamp_1
-
3
.
days
,
end_event_timestamp:
end_timestamp_1
)
# 3 days
create
(
:cycle_analytics_issue_stage_event
,
issue_id:
issue_2
.
id
,
start_event_timestamp:
end_timestamp_2
-
3
.
days
,
end_event_timestamp:
end_timestamp_2
)
# 3 days
create
(
:cycle_analytics_issue_stage_event
,
issue_id:
issue_3
.
id
,
start_event_timestamp:
end_timestamp_2
-
1
.
day
,
end_event_timestamp:
end_timestamp_2
)
# 1 day
average_two_days_ago
=
result
[
0
]
average_today
=
result
[
1
]
expect
(
average_two_days_ago
).
to
have_attributes
(
date:
end_timestamp_1
.
to_date
,
average_duration_in_seconds:
3
.
days
)
expect
(
average_today
).
to
have_attributes
(
date:
end_timestamp_2
.
to_date
,
average_duration_in_seconds:
2
.
days
)
end
end
ee/spec/lib/gitlab/analytics/cycle_analytics/data_collector_spec.rb
View file @
3f7e1bba
...
@@ -138,6 +138,15 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
...
@@ -138,6 +138,15 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::DataCollector do
resource_2_end_time
.
utc
.
to_date
=>
5
,
resource_2_end_time
.
utc
.
to_date
=>
5
,
resource_3_end_time
.
utc
.
to_date
=>
15
resource_3_end_time
.
utc
.
to_date
=>
15
})
})
if
aggregated_data_collector_enabled
data
=
aggregated_data_collector
.
duration_chart_average_data
.
map
{
|
item
|
[
item
.
date
,
round_to_days
(
item
.
average_duration_in_seconds
)]
}
expect
(
Hash
[
data
]).
to
eq
({
resource_1_end_time
.
utc
.
to_date
=>
10
,
resource_2_end_time
.
utc
.
to_date
=>
5
,
resource_3_end_time
.
utc
.
to_date
=>
15
})
end
end
end
end
end
...
...
ee/spec/support/shared_examples/controllers/analytics/cycle_analytics/shared_stage_shared_examples.rb
View file @
3f7e1bba
...
@@ -280,7 +280,12 @@ RSpec.shared_examples 'Value Stream Analytics Stages controller' do
...
@@ -280,7 +280,12 @@ RSpec.shared_examples 'Value Stream Analytics Stages controller' do
it
'matches the response schema'
do
it
'matches the response schema'
do
fake_result
=
[
double
(
MergeRequest
,
average_duration_in_seconds:
10
,
date:
Time
.
current
.
to_date
)]
fake_result
=
[
double
(
MergeRequest
,
average_duration_in_seconds:
10
,
date:
Time
.
current
.
to_date
)]
if
Feature
.
enabled?
(
:use_vsa_aggregated_tables
)
expect_any_instance_of
(
Gitlab
::
Analytics
::
CycleAnalytics
::
Aggregated
::
DataForDurationChart
).
to
receive
(
:average_by_day
).
and_return
(
fake_result
)
else
expect_any_instance_of
(
Gitlab
::
Analytics
::
CycleAnalytics
::
DataForDurationChart
).
to
receive
(
:average_by_day
).
and_return
(
fake_result
)
expect_any_instance_of
(
Gitlab
::
Analytics
::
CycleAnalytics
::
DataForDurationChart
).
to
receive
(
:average_by_day
).
and_return
(
fake_result
)
end
subject
subject
...
...
lib/gitlab/analytics/cycle_analytics/aggregated/data_collector.rb
View file @
3f7e1bba
...
@@ -52,3 +52,5 @@ module Gitlab
...
@@ -52,3 +52,5 @@ module Gitlab
end
end
end
end
end
end
Gitlab
::
Analytics
::
CycleAnalytics
::
Aggregated
::
DataCollector
.
prepend_mod_with
(
'Gitlab::Analytics::CycleAnalytics::Aggregated::DataCollector'
)
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