Commit 9064c0fb authored by Shinya Maeda's avatar Shinya Maeda

Remove redundant key/value pair from the payload of DORA metrics API

This commit removes the redaundant key/value pair from the payload,
that was wrongly added at the first place and already taken over
by the other proper attributes.

Changelog: removed
parent 1d88c7bc
......@@ -7,7 +7,8 @@ type: reference, api
# DevOps Research and Assessment (DORA) key metrics API **(ULTIMATE)**
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/279039) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.10.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/279039) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 13.10.
> - The legacy key/value pair `{ "<date>" => "<value>" }` was removed from the payload in GitLab 14.0.
All methods require [reporter permissions and above](../../user/permissions.md).
......@@ -38,14 +39,14 @@ Example response:
```json
[
{ "2021-03-01": 3, "date": "2021-03-01", "value": 3 },
{ "2021-03-02": 6, "date": "2021-03-02", "value": 6 },
{ "2021-03-03": 0, "date": "2021-03-03", "value": 0 },
{ "2021-03-04": 0, "date": "2021-03-04", "value": 0 },
{ "2021-03-05": 0, "date": "2021-03-05", "value": 0 },
{ "2021-03-06": 0, "date": "2021-03-06", "value": 0 },
{ "2021-03-07": 0, "date": "2021-03-07", "value": 0 },
{ "2021-03-08": 4, "date": "2021-03-08", "value": 4 }
{ "date": "2021-03-01", "value": 3 },
{ "date": "2021-03-02", "value": 6 },
{ "date": "2021-03-03", "value": 0 },
{ "date": "2021-03-04", "value": 0 },
{ "date": "2021-03-05", "value": 0 },
{ "date": "2021-03-06", "value": 0 },
{ "date": "2021-03-07", "value": 0 },
{ "date": "2021-03-08", "value": 4 }
]
```
......@@ -78,14 +79,14 @@ Example response:
```json
[
{ "2021-03-01": 3, "date": "2021-03-01", "value": 3 },
{ "2021-03-02": 6, "date": "2021-03-02", "value": 6 },
{ "2021-03-03": 0, "date": "2021-03-03", "value": 0 },
{ "2021-03-04": 0, "date": "2021-03-04", "value": 0 },
{ "2021-03-05": 0, "date": "2021-03-05", "value": 0 },
{ "2021-03-06": 0, "date": "2021-03-06", "value": 0 },
{ "2021-03-07": 0, "date": "2021-03-07", "value": 0 },
{ "2021-03-08": 4, "date": "2021-03-08", "value": 4 }
{ "date": "2021-03-01", "value": 3 },
{ "date": "2021-03-02", "value": 6 },
{ "date": "2021-03-03", "value": 0 },
{ "date": "2021-03-04", "value": 0 },
{ "date": "2021-03-05", "value": 0 },
{ "date": "2021-03-06", "value": 0 },
{ "date": "2021-03-07", "value": 0 },
{ "date": "2021-03-08", "value": 4 }
]
```
......
......@@ -57,8 +57,6 @@ module Dora
def aggregate_for!(metric, interval)
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
when INTERVAL_ALL
select(data_query).take.data
......@@ -66,12 +64,12 @@ module Dora
select("DATE_TRUNC('month', date)::date AS month, #{data_query}")
.group("DATE_TRUNC('month', date)")
.order('month ASC')
.map { |row| { row.month.to_s => row.data, 'date' => row.month.to_s, 'value' => row.data } }
.map { |row| { 'date' => row.month.to_s, 'value' => row.data } }
when INTERVAL_DAILY
select("date, #{data_query}")
.group('date')
.order('date ASC')
.map { |row| { row.date.to_s => row.data, 'date' => row.date.to_s, 'value' => row.data } }
.map { |row| { 'date' => row.date.to_s, 'value' => row.data } }
else
raise ArgumentError, 'Unknown interval'
end
......
......@@ -193,7 +193,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let(:interval) { described_class::INTERVAL_MONTHLY }
it 'aggregates the rows' do
is_expected.to eq([{ '2021-01-01' => 12, 'date' => '2021-01-01', 'value' => 12 }])
is_expected.to eq([{ 'date' => '2021-01-01', 'value' => 12 }])
end
end
......@@ -201,10 +201,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let(:interval) { described_class::INTERVAL_DAILY }
it 'aggregates the rows' do
is_expected.to eq([{ '2021-01-01' => 6, 'date' => '2021-01-01', 'value' => 6 },
{ '2021-01-02' => 4, 'date' => '2021-01-02', 'value' => 4 },
{ '2021-01-03' => 2, 'date' => '2021-01-03', 'value' => 2 },
{ '2021-01-04' => nil, 'date' => '2021-01-04', 'value' => nil }])
is_expected.to eq([{ 'date' => '2021-01-01', 'value' => 6 },
{ 'date' => '2021-01-02', 'value' => 4 },
{ 'date' => '2021-01-03', 'value' => 2 },
{ 'date' => '2021-01-04', 'value' => nil }])
end
end
......@@ -240,7 +240,7 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let(:interval) { described_class::INTERVAL_MONTHLY }
it 'calculates the median' do
is_expected.to eq([{ '2021-01-01' => 75, 'date' => '2021-01-01', 'value' => 75 }])
is_expected.to eq([{ 'date' => '2021-01-01', 'value' => 75 }])
end
end
......@@ -248,10 +248,10 @@ RSpec.describe Dora::DailyMetrics, type: :model do
let(:interval) { described_class::INTERVAL_DAILY }
it 'calculates the median' do
is_expected.to eq([{ '2021-01-01' => 95, 'date' => '2021-01-01', 'value' => 95 },
{ '2021-01-02' => 75, 'date' => '2021-01-02', 'value' => 75 },
{ '2021-01-03' => 55, 'date' => '2021-01-03', 'value' => 55 },
{ '2021-01-04' => nil, 'date' => '2021-01-04', 'value' => nil }])
is_expected.to eq([{ 'date' => '2021-01-01', 'value' => 95 },
{ 'date' => '2021-01-02', 'value' => 75 },
{ 'date' => '2021-01-03', 'value' => 55 },
{ 'date' => '2021-01-04', 'value' => nil }])
end
end
......
......@@ -35,8 +35,8 @@ RSpec.describe API::Dora::Metrics do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq([{ '2021-01-01' => 1, 'date' => '2021-01-01', 'value' => 1 },
{ '2021-01-02' => 2, 'date' => '2021-01-02', 'value' => 2 }])
expect(json_response).to eq([{ 'date' => '2021-01-01', 'value' => 1 },
{ 'date' => '2021-01-02', 'value' => 2 }])
end
context 'when user is guest' do
......@@ -84,8 +84,8 @@ RSpec.describe API::Dora::Metrics do
subject
expect(response).to have_gitlab_http_status(:ok)
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, 'date' => Time.current.to_date.to_s, 'value' => 2 }])
expect(json_response).to eq([{ 'date' => 1.day.ago.to_date.to_s, 'value' => 1 },
{ 'date' => Time.current.to_date.to_s, 'value' => 2 }])
end
context 'when user is guest' do
......
......@@ -115,7 +115,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success)
expect(subject[:data]).to eq([{ Time.current.to_date.to_s => 2, 'date' => Time.current.to_date.to_s, 'value' => 2 }])
expect(subject[:data]).to eq([{ 'date' => Time.current.to_date.to_s, 'value' => 2 }])
end
context 'when interval is monthly' do
......@@ -123,7 +123,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success)
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 }])
expect(subject[:data]).to eq([{ 'date' => Time.current.beginning_of_month.to_date.to_s, 'value' => 2 }])
end
end
......@@ -141,7 +141,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success)
expect(subject[:data]).to eq([{ Time.current.to_date.to_s => 1, 'date' => Time.current.to_date.to_s, 'value' => 1 }])
expect(subject[:data]).to eq([{ 'date' => Time.current.to_date.to_s, 'value' => 1 }])
end
end
......@@ -185,7 +185,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success)
expect(subject[:data]).to eq([{ Time.current.to_date.to_s => 3, 'date' => Time.current.to_date.to_s, 'value' => 3 }])
expect(subject[:data]).to eq([{ 'date' => Time.current.to_date.to_s, 'value' => 3 }])
end
context 'when interval is monthly' do
......@@ -193,7 +193,7 @@ RSpec.describe Dora::AggregateMetricsService do
it 'returns the aggregated data' do
expect(subject[:status]).to eq(:success)
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 }])
expect(subject[:data]).to eq([{ 'date' => Time.current.beginning_of_month.to_date.to_s, 'value' => 3 }])
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment