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
5e9c5c87
Commit
5e9c5c87
authored
Mar 24, 2021
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change payload format for DORA metrics
This commit changes the payload format on the DORA metrics.
parent
299fc1e4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
37 deletions
+44
-37
changelogs/unreleased/change-payload-format-for-dora-metrics.yml
...ogs/unreleased/change-payload-format-for-dora-metrics.yml
+5
-0
doc/api/dora/metrics.md
doc/api/dora/metrics.md
+16
-16
ee/app/models/dora/daily_metrics.rb
ee/app/models/dora/daily_metrics.rb
+4
-2
ee/spec/models/dora/daily_metrics_spec.rb
ee/spec/models/dora/daily_metrics_spec.rb
+10
-10
ee/spec/requests/api/dora/metrics_spec.rb
ee/spec/requests/api/dora/metrics_spec.rb
+4
-4
ee/spec/services/dora/aggregate_metrics_service_spec.rb
ee/spec/services/dora/aggregate_metrics_service_spec.rb
+5
-5
No files found.
changelogs/unreleased/change-payload-format-for-dora-metrics.yml
0 → 100644
View file @
5e9c5c87
---
title
:
Improve payload format of DORA metrics API
merge_request
:
57314
author
:
type
:
added
doc/api/dora/metrics.md
View file @
5e9c5c87
...
@@ -38,14 +38,14 @@ Example response:
...
@@ -38,14 +38,14 @@ Example response:
```
json
```
json
[
[
{
"2021-03-01"
:
3
},
{
"2021-03-01"
:
3
,
"date"
:
"2021-03-01"
,
"value"
:
3
},
{
"2021-03-02"
:
6
},
{
"2021-03-02"
:
6
,
"date"
:
"2021-03-02"
,
"value"
:
6
},
{
"2021-03-03"
:
0
},
{
"2021-03-03"
:
0
,
"date"
:
"2021-03-03"
,
"value"
:
0
},
{
"2021-03-04"
:
0
},
{
"2021-03-04"
:
0
,
"date"
:
"2021-03-04"
,
"value"
:
0
},
{
"2021-03-05"
:
0
},
{
"2021-03-05"
:
0
,
"date"
:
"2021-03-05"
,
"value"
:
0
},
{
"2021-03-06"
:
0
},
{
"2021-03-06"
:
0
,
"date"
:
"2021-03-06"
,
"value"
:
0
},
{
"2021-03-07"
:
0
},
{
"2021-03-07"
:
0
,
"date"
:
"2021-03-07"
,
"value"
:
0
},
{
"2021-03-08"
:
4
}
{
"2021-03-08"
:
4
,
"date"
:
"2021-03-08"
,
"value"
:
4
}
]
]
```
```
...
@@ -78,13 +78,13 @@ Example response:
...
@@ -78,13 +78,13 @@ Example response:
```
json
```
json
[
[
{
"2021-03-01"
:
3
},
{
"2021-03-01"
:
3
,
"date"
:
"2021-03-01"
,
"value"
:
3
},
{
"2021-03-02"
:
6
},
{
"2021-03-02"
:
6
,
"date"
:
"2021-03-02"
,
"value"
:
6
},
{
"2021-03-03"
:
0
},
{
"2021-03-03"
:
0
,
"date"
:
"2021-03-03"
,
"value"
:
0
},
{
"2021-03-04"
:
0
},
{
"2021-03-04"
:
0
,
"date"
:
"2021-03-04"
,
"value"
:
0
},
{
"2021-03-05"
:
0
},
{
"2021-03-05"
:
0
,
"date"
:
"2021-03-05"
,
"value"
:
0
},
{
"2021-03-06"
:
0
},
{
"2021-03-06"
:
0
,
"date"
:
"2021-03-06"
,
"value"
:
0
},
{
"2021-03-07"
:
0
},
{
"2021-03-07"
:
0
,
"date"
:
"2021-03-07"
,
"value"
:
0
},
{
"2021-03-08"
:
4
}
{
"2021-03-08"
:
4
,
"date"
:
"2021-03-08"
,
"value"
:
4
}
]
]
```
```
ee/app/models/dora/daily_metrics.rb
View file @
5e9c5c87
...
@@ -57,6 +57,8 @@ module Dora
...
@@ -57,6 +57,8 @@ module Dora
def
aggregate_for!
(
metric
,
interval
)
def
aggregate_for!
(
metric
,
interval
)
data_query
=
data_query_for!
(
metric
)
data_query
=
data_query_for!
(
metric
)
# NOTE: We would remove the `{ date => value }` entry in 14.0 in favor of the explicit `date` and `value` keys.
# See more https://gitlab.com/gitlab-org/gitlab/-/issues/325931
case
interval
case
interval
when
INTERVAL_ALL
when
INTERVAL_ALL
select
(
data_query
).
take
.
data
select
(
data_query
).
take
.
data
...
@@ -64,12 +66,12 @@ module Dora
...
@@ -64,12 +66,12 @@ module Dora
select
(
"DATE_TRUNC('month', date)::date AS month,
#{
data_query
}
"
)
select
(
"DATE_TRUNC('month', date)::date AS month,
#{
data_query
}
"
)
.
group
(
"DATE_TRUNC('month', date)"
)
.
group
(
"DATE_TRUNC('month', date)"
)
.
order
(
'month ASC'
)
.
order
(
'month ASC'
)
.
map
{
|
row
|
{
row
.
month
.
to_s
=>
row
.
data
}
}
.
map
{
|
row
|
{
row
.
month
.
to_s
=>
row
.
data
,
'date'
=>
row
.
month
.
to_s
,
'value'
=>
row
.
data
}
}
when
INTERVAL_DAILY
when
INTERVAL_DAILY
select
(
"date,
#{
data_query
}
"
)
select
(
"date,
#{
data_query
}
"
)
.
group
(
'date'
)
.
group
(
'date'
)
.
order
(
'date ASC'
)
.
order
(
'date ASC'
)
.
map
{
|
row
|
{
row
.
date
.
to_s
=>
row
.
data
}
}
.
map
{
|
row
|
{
row
.
date
.
to_s
=>
row
.
data
,
'date'
=>
row
.
date
.
to_s
,
'value'
=>
row
.
data
}
}
else
else
raise
ArgumentError
,
'Unknown interval'
raise
ArgumentError
,
'Unknown interval'
end
end
...
...
ee/spec/models/dora/daily_metrics_spec.rb
View file @
5e9c5c87
...
@@ -192,7 +192,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do
...
@@ -192,7 +192,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let
(
:interval
)
{
described_class
::
INTERVAL_MONTHLY
}
let
(
:interval
)
{
described_class
::
INTERVAL_MONTHLY
}
it
'aggregates the rows'
do
it
'aggregates the rows'
do
is_expected
.
to
eq
([{
'2021-01-01'
=>
12
}])
is_expected
.
to
eq
([{
'2021-01-01'
=>
12
,
'date'
=>
'2021-01-01'
,
'value'
=>
12
}])
end
end
end
end
...
@@ -200,10 +200,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do
...
@@ -200,10 +200,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let
(
:interval
)
{
described_class
::
INTERVAL_DAILY
}
let
(
:interval
)
{
described_class
::
INTERVAL_DAILY
}
it
'aggregates the rows'
do
it
'aggregates the rows'
do
is_expected
.
to
eq
([{
'2021-01-01'
=>
6
},
is_expected
.
to
eq
([{
'2021-01-01'
=>
6
,
'date'
=>
'2021-01-01'
,
'value'
=>
6
},
{
'2021-01-02'
=>
4
},
{
'2021-01-02'
=>
4
,
'date'
=>
'2021-01-02'
,
'value'
=>
4
},
{
'2021-01-03'
=>
2
},
{
'2021-01-03'
=>
2
,
'date'
=>
'2021-01-03'
,
'value'
=>
2
},
{
'2021-01-04'
=>
nil
}])
{
'2021-01-04'
=>
nil
,
'date'
=>
'2021-01-04'
,
'value'
=>
nil
}])
end
end
end
end
...
@@ -239,7 +239,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do
...
@@ -239,7 +239,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let
(
:interval
)
{
described_class
::
INTERVAL_MONTHLY
}
let
(
:interval
)
{
described_class
::
INTERVAL_MONTHLY
}
it
'calculates the median'
do
it
'calculates the median'
do
is_expected
.
to
eq
([{
'2021-01-01'
=>
75
}])
is_expected
.
to
eq
([{
'2021-01-01'
=>
75
,
'date'
=>
'2021-01-01'
,
'value'
=>
75
}])
end
end
end
end
...
@@ -247,10 +247,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do
...
@@ -247,10 +247,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let
(
:interval
)
{
described_class
::
INTERVAL_DAILY
}
let
(
:interval
)
{
described_class
::
INTERVAL_DAILY
}
it
'calculates the median'
do
it
'calculates the median'
do
is_expected
.
to
eq
([{
'2021-01-01'
=>
95
},
is_expected
.
to
eq
([{
'2021-01-01'
=>
95
,
'date'
=>
'2021-01-01'
,
'value'
=>
95
},
{
'2021-01-02'
=>
75
},
{
'2021-01-02'
=>
75
,
'date'
=>
'2021-01-02'
,
'value'
=>
75
},
{
'2021-01-03'
=>
55
},
{
'2021-01-03'
=>
55
,
'date'
=>
'2021-01-03'
,
'value'
=>
55
},
{
'2021-01-04'
=>
nil
}])
{
'2021-01-04'
=>
nil
,
'date'
=>
'2021-01-04'
,
'value'
=>
nil
}])
end
end
end
end
...
...
ee/spec/requests/api/dora/metrics_spec.rb
View file @
5e9c5c87
...
@@ -35,8 +35,8 @@ RSpec.describe API::Dora::Metrics do
...
@@ -35,8 +35,8 @@ RSpec.describe API::Dora::Metrics do
subject
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
eq
([{
'2021-01-01'
=>
1
},
expect
(
json_response
).
to
eq
([{
'2021-01-01'
=>
1
,
'date'
=>
'2021-01-01'
,
'value'
=>
1
},
{
'2021-01-02'
=>
2
}])
{
'2021-01-02'
=>
2
,
'date'
=>
'2021-01-02'
,
'value'
=>
2
}])
end
end
context
'when user is guest'
do
context
'when user is guest'
do
...
@@ -84,8 +84,8 @@ RSpec.describe API::Dora::Metrics do
...
@@ -84,8 +84,8 @@ RSpec.describe API::Dora::Metrics do
subject
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
eq
([{
1
.
day
.
ago
.
to_date
.
to_s
=>
1
},
expect
(
json_response
).
to
eq
([{
1
.
day
.
ago
.
to_date
.
to_s
=>
1
,
'date'
=>
1
.
day
.
ago
.
to_date
.
to_s
,
'value'
=>
1
},
{
Time
.
current
.
to_date
.
to_s
=>
2
}])
{
Time
.
current
.
to_date
.
to_s
=>
2
,
'date'
=>
Time
.
current
.
to_date
.
to_s
,
'value'
=>
2
}])
end
end
context
'when user is guest'
do
context
'when user is guest'
do
...
...
ee/spec/services/dora/aggregate_metrics_service_spec.rb
View file @
5e9c5c87
...
@@ -114,7 +114,7 @@ RSpec.describe Dora::AggregateMetricsService do
...
@@ -114,7 +114,7 @@ RSpec.describe Dora::AggregateMetricsService do
it
'returns the aggregated data'
do
it
'returns the aggregated data'
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
to_date
.
to_s
=>
2
}])
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
to_date
.
to_s
=>
2
,
'date'
=>
Time
.
current
.
to_date
.
to_s
,
'value'
=>
2
}])
end
end
context
'when interval is monthly'
do
context
'when interval is monthly'
do
...
@@ -122,7 +122,7 @@ RSpec.describe Dora::AggregateMetricsService do
...
@@ -122,7 +122,7 @@ RSpec.describe Dora::AggregateMetricsService do
it
'returns the aggregated data'
do
it
'returns the aggregated data'
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
beginning_of_month
.
to_date
.
to_s
=>
2
}])
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
beginning_of_month
.
to_date
.
to_s
=>
2
,
'date'
=>
Time
.
current
.
beginning_of_month
.
to_date
.
to_s
,
'value'
=>
2
}])
end
end
end
end
...
@@ -140,7 +140,7 @@ RSpec.describe Dora::AggregateMetricsService do
...
@@ -140,7 +140,7 @@ RSpec.describe Dora::AggregateMetricsService do
it
'returns the aggregated data'
do
it
'returns the aggregated data'
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
to_date
.
to_s
=>
1
}])
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
to_date
.
to_s
=>
1
,
'date'
=>
Time
.
current
.
to_date
.
to_s
,
'value'
=>
1
}])
end
end
end
end
end
end
...
@@ -174,7 +174,7 @@ RSpec.describe Dora::AggregateMetricsService do
...
@@ -174,7 +174,7 @@ RSpec.describe Dora::AggregateMetricsService do
it
'returns the aggregated data'
do
it
'returns the aggregated data'
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
to_date
.
to_s
=>
3
}])
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
to_date
.
to_s
=>
3
,
'date'
=>
Time
.
current
.
to_date
.
to_s
,
'value'
=>
3
}])
end
end
context
'when interval is monthly'
do
context
'when interval is monthly'
do
...
@@ -182,7 +182,7 @@ RSpec.describe Dora::AggregateMetricsService do
...
@@ -182,7 +182,7 @@ RSpec.describe Dora::AggregateMetricsService do
it
'returns the aggregated data'
do
it
'returns the aggregated data'
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
beginning_of_month
.
to_date
.
to_s
=>
3
}])
expect
(
subject
[
:data
]).
to
eq
([{
Time
.
current
.
beginning_of_month
.
to_date
.
to_s
=>
3
,
'date'
=>
Time
.
current
.
beginning_of_month
.
to_date
.
to_s
,
'value'
=>
3
}])
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